From 0ca45e343b85193ee7ab0d1a28eaa98df1123db1 Mon Sep 17 00:00:00 2001
From: James <james@sourcefabric-DX4840.(none)>
Date: Wed, 6 Jun 2012 14:18:54 -0400
Subject: [PATCH] CC-3878: Recorded media file's track number is changed after
 restarting media-monitor

- fixed
---
 .../application/controllers/ApiController.php      |  2 +-
 .../airtimefilemonitor/airtimenotifier.py          | 14 +++++++++-----
 .../airtimefilemonitor/airtimeprocessevent.py      |  3 ++-
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php
index ffb46b97f..15f9dbc61 100644
--- a/airtime_mvc/application/controllers/ApiController.php
+++ b/airtime_mvc/application/controllers/ApiController.php
@@ -493,7 +493,7 @@ class ApiController extends Zend_Controller_Action
 
 		//$file->setMetadataValue('MDATA_KEY_TITLE', $tmpTitle);
         $file->setMetadataValue('MDATA_KEY_CREATOR', "Airtime Show Recorder");
-        $file->setMetadataValue('MDATA_KEY_TRACKNUMBER', null);
+        $file->setMetadataValue('MDATA_KEY_TRACKNUMBER', $show_instance_id);
 
         if (!$showCanceled && Application_Model_Preference::GetAutoUploadRecordedShowToSoundcloud())
         {
diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py b/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py
index 6f6040db3..be301c958 100644
--- a/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py
+++ b/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py
@@ -159,7 +159,7 @@ class AirtimeNotifier(Notifier):
                         return
                     md.update(mutagen)
 
-                if event['is_recorded_show']:
+                if 'is_recorded_show' in event and event['is_recorded_show']:
                     self.api_client.update_media_metadata(md, mode, True)
                 else:
                     self.api_client.update_media_metadata(md, mode)
@@ -169,12 +169,16 @@ class AirtimeNotifier(Notifier):
                 if mutagen is None:
                     return
                 md.update(mutagen)
-                self.api_client.update_media_metadata(md, mode)
-
+                if 'is_recorded_show' in event and event['is_recorded_show']:
+                    self.api_client.update_media_metadata(md, mode, True)
+                else:
+                    self.api_client.update_media_metadata(md, mode)
             elif (mode == self.config.MODE_MOVED):
                 md['MDATA_KEY_MD5'] = self.md_manager.get_md5(filepath)
-                self.api_client.update_media_metadata(md, mode)
-
+                if 'is_recorded_show' in event and event['is_recorded_show']:
+                    self.api_client.update_media_metadata(md, mode, True)
+                else:
+                    self.api_client.update_media_metadata(md, mode)
             elif (mode == self.config.MODE_DELETE):
                 self.api_client.update_media_metadata(md, mode)
             
diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py
index dc10b8a85..2195e9d91 100644
--- a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py
+++ b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py
@@ -180,7 +180,8 @@ class AirtimeProcessEvent(ProcessEvent):
         if not dir and not self.mmc.is_parent_directory(pathname, self.config.organize_directory):
             self.logger.info("Modified: %s", pathname)
             if self.mmc.is_audio_file(name):
-                self.file_events.append({'filepath': pathname, 'mode': self.config.MODE_MODIFY})
+                is_recorded = self.mmc.is_parent_directory(pathname, self.config.recorded_directory)
+                self.file_events.append({'filepath': pathname, 'mode': self.config.MODE_MODIFY, 'is_recorded_show': is_recorded})
     
     # if change is detected on /etc/mtab, we check what mount(file system) was added/removed
     # and act accordingly