From ee52d2e36ec99cc7a21113e8faef57ec789c04bc Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Wed, 9 May 2012 23:24:15 -0400 Subject: [PATCH] CC-3792: Record show's file cannot be saved -fixed --- .../airtimefilemonitor/airtimemetadata.py | 10 ++++++++-- .../airtimefilemonitor/airtimeprocessevent.py | 5 +---- .../airtimefilemonitor/mediamonitorcommon.py | 13 ++++++------- python_apps/pypo/recorder.py | 3 ++- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py b/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py index 92ffa4eca..f33db9e2d 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py @@ -3,6 +3,7 @@ import hashlib import mutagen import logging import math +import datetime import re from api_clients import api_client @@ -26,7 +27,8 @@ class AirtimeMetadata: "MDATA_KEY_COMPOSER": "composer",\ "MDATA_KEY_ENCODER": "encodedby",\ "MDATA_KEY_CONDUCTOR": "conductor",\ - "MDATA_KEY_YEAR": "date",\ + "MDATA_KEY_YEAR": "year",\ + "MDATA_KEY_DATE": "date",\ "MDATA_KEY_URL": "website",\ "MDATA_KEY_ISRC": "isrc",\ "MDATA_KEY_COPYRIGHT": "copyright",\ @@ -44,7 +46,8 @@ class AirtimeMetadata: "composer": "MDATA_KEY_COMPOSER",\ "encodedby": "MDATA_KEY_ENCODER",\ "conductor": "MDATA_KEY_CONDUCTOR",\ - "date": "MDATA_KEY_YEAR",\ + "year": "MDATA_KEY_YEAR",\ + "date": "MDATA_KEY_DATE",\ "website": "MDATA_KEY_URL",\ "isrc": "MDATA_KEY_ISRC",\ "copyright": "MDATA_KEY_COPYRIGHT",\ @@ -199,6 +202,9 @@ class AirtimeMetadata: if 'MDATA_KEY_YEAR' in md: md['MDATA_KEY_YEAR'] = self.truncate_to_length(md['MDATA_KEY_YEAR'], 4) + + if 'MDATA_KEY_DATE' in md: + md['MDATA_KEY_DATE'] = self.truncate_to_length(md['MDATA_KEY_DATE'], 16) if 'MDATA_KEY_URL' in md: md['MDATA_KEY_URL'] = self.truncate_to_length(md['MDATA_KEY_URL'], 512) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py index bfa686aa0..aed82a326 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py @@ -296,10 +296,7 @@ class AirtimeProcessEvent(ProcessEvent): else: #show moved from unwatched folder into a watched folder. Do not "organize". - if self.mmc.is_parent_directory(event.pathname, self.config.recorded_directory): - is_recorded = True - else: - is_recorded = False + is_recorded = self.mmc.is_parent_directory(event.pathname, self.config.recorded_directory) self.file_events.append({'mode': self.config.MODE_CREATE, 'filepath': event.pathname, 'is_recorded_show': is_recorded}) else: #When we move a directory into a watched_dir, we only get a notification that the dir was created, diff --git a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py index 12988c656..9be5cb15a 100644 --- a/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py +++ b/python_apps/media-monitor/airtimefilemonitor/mediamonitorcommon.py @@ -208,8 +208,6 @@ class MediaMonitorCommon: storage_directory = self.config.storage_directory - is_recorded_show = False - try: #will be in the format .ext file_ext = os.path.splitext(original_path)[1] @@ -238,8 +236,8 @@ class MediaMonitorCommon: #/srv/airtime/stor/recorded/year/month/year-month-day-time-showname-bitrate.ext if(md['MDATA_KEY_CREATOR'] == u"Airtime Show Recorder"): #yyyy-mm-dd-hh-MM-ss - y = orig_md['MDATA_KEY_YEAR'].split("-") - filepath = u'%s/%s/%s/%s/%s-%s-%s%s' % (storage_directory, api_client.encode_to("recorded", 'utf-8'), y[0], y[1], orig_md['MDATA_KEY_YEAR'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext) + y = orig_md['MDATA_KEY_DATE'].split("-") + filepath = u'%s/%s/%s/%s/%s-%s-%s%s' % (storage_directory, "recorded", y[0], y[1], orig_md['MDATA_KEY_DATE'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext) #"Show-Title-2011-03-28-17:15:00" title = md['MDATA_KEY_TITLE'].split("-") @@ -250,13 +248,13 @@ class MediaMonitorCommon: new_md = {} new_md["MDATA_KEY_FILEPATH"] = original_path - new_md['MDATA_KEY_TITLE'] = '%s-%s-%s:%s:%s' % (show_name, orig_md['MDATA_KEY_YEAR'], show_hour, show_min, show_sec) + new_md['MDATA_KEY_TITLE'] = '%s-%s-%s:%s:%s' % (show_name, orig_md['MDATA_KEY_DATE'], show_hour, show_min, show_sec) self.md_manager.save_md_to_file(new_md) elif(md['MDATA_KEY_TRACKNUMBER'] == u'unknown'): - filepath = u'%s/%s/%s/%s/%s-%s%s' % (storage_directory, api_client.encode_to("imported", 'utf-8'), md['MDATA_KEY_CREATOR'], md['MDATA_KEY_SOURCE'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext) + filepath = u'%s/%s/%s/%s/%s-%s%s' % (storage_directory, "imported", md['MDATA_KEY_CREATOR'], md['MDATA_KEY_SOURCE'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext) else: - filepath = u'%s/%s/%s/%s/%s-%s-%s%s' % (storage_directory, api_client.encode_to("imported", 'utf-8'), md['MDATA_KEY_CREATOR'], md['MDATA_KEY_SOURCE'], md['MDATA_KEY_TRACKNUMBER'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext) + filepath = u'%s/%s/%s/%s/%s-%s-%s%s' % (storage_directory, "imported", md['MDATA_KEY_CREATOR'], md['MDATA_KEY_SOURCE'], md['MDATA_KEY_TRACKNUMBER'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext) filepath = self.create_unique_filename(filepath, original_path) self.logger.info('Unique filepath: %s', filepath) @@ -264,6 +262,7 @@ class MediaMonitorCommon: except Exception, e: self.logger.error('Exception: %s', e) + self.logger.error("traceback: %s", traceback.format_exc()) return filepath diff --git a/python_apps/pypo/recorder.py b/python_apps/pypo/recorder.py index ab8f2ca8f..2146e4d2e 100644 --- a/python_apps/pypo/recorder.py +++ b/python_apps/pypo/recorder.py @@ -127,13 +127,14 @@ class ShowRecorder(Thread): self.logger.info("time: %s" % time) name = time+"-"+self.show_name - artist = api_client.encode_to("Airtime Show Recorder",'utf-8') + artist = "Airtime Show Recorder" #set some metadata for our file daemon recorded_file = mutagen.File(filepath, easy=True) recorded_file['title'] = name recorded_file['artist'] = artist recorded_file['date'] = md[0] + recorded_file['year'] = md[0].split("-")[0] #You cannot pass ints into the metadata of a file. Even tracknumber needs to be a string recorded_file['tracknumber'] = unicode(self.show_instance) recorded_file.save()