From 30c95f3e9dabf4aea3c8074e9acbca6ee89467a0 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 2 Oct 2012 13:30:02 -0400 Subject: [PATCH 1/3] Removed duplication of truncate_to_length routine --- python_apps/media-monitor2/media/monitor/metadata.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/python_apps/media-monitor2/media/monitor/metadata.py b/python_apps/media-monitor2/media/monitor/metadata.py index 063c1211c..c42c54587 100644 --- a/python_apps/media-monitor2/media/monitor/metadata.py +++ b/python_apps/media-monitor2/media/monitor/metadata.py @@ -8,7 +8,7 @@ from mutagen.easyid3 import EasyID3KeyError from media.monitor.exceptions import BadSongFile, InvalidMetadataElement from media.monitor.log import Loggable -from media.monitor.pure import format_length +from media.monitor.pure import format_length, truncate_to_length import media.monitor.pure as mmp """ @@ -95,12 +95,6 @@ truncate_table = { 'MDATA_KEY_COPYRIGHT' : 512, } -def truncate_to_length(item, length): - if isinstance(item, int): item = str(item) - if isinstance(item, basestring): - if len(item) > length: return item[0:length] - else: return item - class Metadata(Loggable): # TODO : refactor the way metadata is being handled. Right now things are a # little bit messy. Some of the handling is in m.m.pure while the rest is From 4d9fbaf21685756258e0b7e3f946d8cd7dfbd77e Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 2 Oct 2012 13:30:37 -0400 Subject: [PATCH 2/3] Formatted code better and added TODO --- python_apps/media-monitor2/media/monitor/eventdrainer.py | 1 + python_apps/media-monitor2/media/monitor/metadata.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/python_apps/media-monitor2/media/monitor/eventdrainer.py b/python_apps/media-monitor2/media/monitor/eventdrainer.py index 69f997bf0..1d3bc96f6 100644 --- a/python_apps/media-monitor2/media/monitor/eventdrainer.py +++ b/python_apps/media-monitor2/media/monitor/eventdrainer.py @@ -9,6 +9,7 @@ class EventDrainer(Loggable): """ def __init__(self, connection, interval=1): def cb(): + # TODO : make 0.3 parameter configurable try : connection.drain_events(timeout=0.3) except socket.timeout : pass except Exception as e : diff --git a/python_apps/media-monitor2/media/monitor/metadata.py b/python_apps/media-monitor2/media/monitor/metadata.py index c42c54587..195d7fcdd 100644 --- a/python_apps/media-monitor2/media/monitor/metadata.py +++ b/python_apps/media-monitor2/media/monitor/metadata.py @@ -163,9 +163,12 @@ class Metadata(Loggable): # Forcing the unicode through try : fpath = fpath.decode("utf-8") except : pass + if not mmp.file_playable(fpath): raise BadSongFile(fpath) + try : full_mutagen = mutagen.File(fpath, easy=True) except Exception : raise BadSongFile(fpath) + self.path = fpath if not os.path.exists(self.path): self.logger.info("Attempting to read metadata of file \ From b41c03902ed909d855842b195573a7292219caba Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 2 Oct 2012 14:43:17 -0400 Subject: [PATCH 3/3] cc-4518: fixed --- python_apps/media-monitor2/media/monitor/metadata.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/python_apps/media-monitor2/media/monitor/metadata.py b/python_apps/media-monitor2/media/monitor/metadata.py index 195d7fcdd..8ceaf2aa9 100644 --- a/python_apps/media-monitor2/media/monitor/metadata.py +++ b/python_apps/media-monitor2/media/monitor/metadata.py @@ -120,7 +120,14 @@ class Metadata(Loggable): # TODO : some files have multiple fields for the same metadata. # genre is one example. In that case mutagen will return a list # of values - assign_val = m_val[0] if isinstance(m_val, list) else m_val + + if isinstance(m_val, list): + # TODO : does it make more sense to just skip the element in + # this case? + if len(m_val) == 0: assign_val = '' + else: assign_val = m_val[0] + else: assign_val = m_val + temp_dict[ m_key ] = assign_val airtime_dictionary = {} for muta_k, muta_v in temp_dict.iteritems():