CC-2633: media monitor crashes on non-ascii files and metadata
- fixed bug for the case where mutagen return None for metadata - fixed bug for non-ascii files and metadata
This commit is contained in:
parent
6c6776e2ce
commit
938c503e85
5 changed files with 49 additions and 28 deletions
|
@ -402,7 +402,7 @@ class AirTimeApiClient(ApiClientInterface):
|
||||||
req = urllib2.Request(url, data)
|
req = urllib2.Request(url, data)
|
||||||
|
|
||||||
response = urllib2.urlopen(req).read()
|
response = urllib2.urlopen(req).read()
|
||||||
logger.info("update media %s", response)
|
logger.info("update media %s, filepath: %s, mode: %s", response, md['MDATA_KEY_FILEPATH'], mode)
|
||||||
response = json.loads(response)
|
response = json.loads(response)
|
||||||
|
|
||||||
elapsed = (time.time() - start)
|
elapsed = (time.time() - start)
|
||||||
|
|
|
@ -70,7 +70,8 @@ try:
|
||||||
#create 5 worker threads
|
#create 5 worker threads
|
||||||
wp = MediaMonitorWorkerProcess()
|
wp = MediaMonitorWorkerProcess()
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
t = Thread(target=wp.process_file_events, args=(multi_queue, notifier))
|
threadName = "Thread #%d" % i
|
||||||
|
t = Thread(target=wp.process_file_events, name=threadName, args=(multi_queue, notifier))
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
wdd = notifier.watch_directory(storage_directory)
|
wdd = notifier.watch_directory(storage_directory)
|
||||||
|
|
|
@ -5,11 +5,16 @@ import logging
|
||||||
import math
|
import math
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
def to_unicode(obj, encoding='utf-8'):
|
||||||
|
if isinstance(obj, basestring):
|
||||||
|
if not isinstance(obj, unicode):
|
||||||
|
obj = unicode(obj, encoding)
|
||||||
|
return obj
|
||||||
|
|
||||||
"""
|
"""
|
||||||
list of supported easy tags in mutagen version 1.20
|
list of supported easy tags in mutagen version 1.20
|
||||||
['albumartistsort', 'musicbrainz_albumstatus', 'lyricist', 'releasecountry', 'date', 'performer', 'musicbrainz_albumartistid', 'composer', 'encodedby', 'tracknumber', 'musicbrainz_albumid', 'album', 'asin', 'musicbrainz_artistid', 'mood', 'copyright', 'author', 'media', 'length', 'version', 'artistsort', 'titlesort', 'discsubtitle', 'website', 'musicip_fingerprint', 'conductor', 'compilation', 'barcode', 'performer:*', 'composersort', 'musicbrainz_discid', 'musicbrainz_albumtype', 'genre', 'isrc', 'discnumber', 'musicbrainz_trmid', 'replaygain_*_gain', 'musicip_puid', 'artist', 'title', 'bpm', 'musicbrainz_trackid', 'arranger', 'albumsort', 'replaygain_*_peak', 'organization']
|
['albumartistsort', 'musicbrainz_albumstatus', 'lyricist', 'releasecountry', 'date', 'performer', 'musicbrainz_albumartistid', 'composer', 'encodedby', 'tracknumber', 'musicbrainz_albumid', 'album', 'asin', 'musicbrainz_artistid', 'mood', 'copyright', 'author', 'media', 'length', 'version', 'artistsort', 'titlesort', 'discsubtitle', 'website', 'musicip_fingerprint', 'conductor', 'compilation', 'barcode', 'performer:*', 'composersort', 'musicbrainz_discid', 'musicbrainz_albumtype', 'genre', 'isrc', 'discnumber', 'musicbrainz_trmid', 'replaygain_*_gain', 'musicip_puid', 'artist', 'title', 'bpm', 'musicbrainz_trackid', 'arranger', 'albumsort', 'replaygain_*_peak', 'organization']
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class AirtimeMetadata:
|
class AirtimeMetadata:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -108,7 +113,6 @@ class AirtimeMetadata:
|
||||||
|
|
||||||
def get_md_from_file(self, filepath):
|
def get_md_from_file(self, filepath):
|
||||||
|
|
||||||
self.logger.debug("testing upgrade")
|
|
||||||
self.logger.info("getting info from filepath %s", filepath)
|
self.logger.info("getting info from filepath %s", filepath)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -125,7 +129,8 @@ class AirtimeMetadata:
|
||||||
|
|
||||||
|
|
||||||
self.logger.info(file_info)
|
self.logger.info(file_info)
|
||||||
|
if file_info is None:
|
||||||
|
return None
|
||||||
#check if file has any metadata
|
#check if file has any metadata
|
||||||
if file_info is not None:
|
if file_info is not None:
|
||||||
for key in file_info.keys() :
|
for key in file_info.keys() :
|
||||||
|
@ -134,11 +139,13 @@ class AirtimeMetadata:
|
||||||
|
|
||||||
if 'MDATA_KEY_TITLE' not in md:
|
if 'MDATA_KEY_TITLE' not in md:
|
||||||
#get rid of file extention from original name, name might have more than 1 '.' in it.
|
#get rid of file extention from original name, name might have more than 1 '.' in it.
|
||||||
|
filepath = to_unicode(filepath)
|
||||||
|
filepath = filepath.encode('utf-8')
|
||||||
original_name = os.path.basename(filepath)
|
original_name = os.path.basename(filepath)
|
||||||
original_name = original_name.split(".")[0:-1]
|
original_name = original_name.split(".")[0:-1]
|
||||||
original_name = ''.join(original_name)
|
original_name = ''.join(original_name)
|
||||||
md['MDATA_KEY_TITLE'] = original_name
|
md['MDATA_KEY_TITLE'] = original_name
|
||||||
|
|
||||||
#incase track number is in format u'4/11'
|
#incase track number is in format u'4/11'
|
||||||
#need to also check that the tracknumber is even a tracknumber (cc-2582)
|
#need to also check that the tracknumber is even a tracknumber (cc-2582)
|
||||||
if 'MDATA_KEY_TRACKNUMBER' in md:
|
if 'MDATA_KEY_TRACKNUMBER' in md:
|
||||||
|
@ -175,10 +182,11 @@ class AirtimeMetadata:
|
||||||
|
|
||||||
#do this so object can be urlencoded properly.
|
#do this so object can be urlencoded properly.
|
||||||
for key in md.keys():
|
for key in md.keys():
|
||||||
if(isinstance(md[key], basestring)):
|
|
||||||
|
if (isinstance(md[key], basestring)):
|
||||||
|
#self.logger.info("Converting md[%s] = '%s' ", key, md[key])
|
||||||
|
md[key] = to_unicode(md[key])
|
||||||
md[key] = md[key].encode('utf-8')
|
md[key] = md[key].encode('utf-8')
|
||||||
|
#self.logger.info("Converting complete: md[%s] = '%s' ", key, md[key])
|
||||||
self.logger.info("MD after parsing.")
|
|
||||||
self.logger.debug(md)
|
|
||||||
|
|
||||||
return md
|
return md
|
||||||
|
|
|
@ -119,25 +119,27 @@ class AirtimeNotifier(Notifier):
|
||||||
os.unlink(filepath)
|
os.unlink(filepath)
|
||||||
|
|
||||||
|
|
||||||
#update airtime with information about files discovered in our
|
"""
|
||||||
#watched directories. Pass in a dict() object with the following
|
Update airtime with information about files discovered in our
|
||||||
#attributes:
|
watched directories.
|
||||||
# -filepath
|
event: a dict() object with the following attributes:
|
||||||
# -mode
|
-filepath
|
||||||
# -data
|
-mode
|
||||||
# -is_recorded_show
|
-data
|
||||||
def update_airtime(self, d):
|
-is_recorded_show
|
||||||
|
"""
|
||||||
|
def update_airtime(self, event):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.logger.info("updating filepath: %s ", d['filepath'])
|
self.logger.info("updating filepath: %s ", event['filepath'])
|
||||||
filepath = d['filepath']
|
filepath = event['filepath']
|
||||||
mode = d['mode']
|
mode = event['mode']
|
||||||
|
|
||||||
md = {}
|
md = {}
|
||||||
md['MDATA_KEY_FILEPATH'] = filepath
|
md['MDATA_KEY_FILEPATH'] = filepath
|
||||||
|
|
||||||
if 'data' in d:
|
if 'data' in event:
|
||||||
file_md = d['data']
|
file_md = event['data']
|
||||||
md.update(file_md)
|
md.update(file_md)
|
||||||
else:
|
else:
|
||||||
file_md = None
|
file_md = None
|
||||||
|
@ -151,7 +153,7 @@ class AirtimeNotifier(Notifier):
|
||||||
return
|
return
|
||||||
md.update(mutagen)
|
md.update(mutagen)
|
||||||
|
|
||||||
if d['is_recorded_show']:
|
if event['is_recorded_show']:
|
||||||
self.api_client.update_media_metadata(md, mode, True)
|
self.api_client.update_media_metadata(md, mode, True)
|
||||||
else:
|
else:
|
||||||
self.api_client.update_media_metadata(md, mode)
|
self.api_client.update_media_metadata(md, mode)
|
||||||
|
@ -171,7 +173,7 @@ class AirtimeNotifier(Notifier):
|
||||||
self.api_client.update_media_metadata(md, mode)
|
self.api_client.update_media_metadata(md, mode)
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.logger.error("failed updating filepath: %s ", d['filepath'])
|
self.logger.error("failed updating filepath: %s ", event['filepath'])
|
||||||
self.logger.error('Exception: %s', e)
|
self.logger.error('Exception: %s', e)
|
||||||
|
|
||||||
#define which directories the pyinotify WatchManager should watch.
|
#define which directories the pyinotify WatchManager should watch.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[loggers]
|
[loggers]
|
||||||
keys=root
|
keys= root,notifier,metadata
|
||||||
|
|
||||||
[handlers]
|
[handlers]
|
||||||
keys=fileOutHandler
|
keys=fileOutHandler
|
||||||
|
@ -11,12 +11,22 @@ keys=simpleFormatter
|
||||||
level=DEBUG
|
level=DEBUG
|
||||||
handlers=fileOutHandler
|
handlers=fileOutHandler
|
||||||
|
|
||||||
|
[logger_notifier]
|
||||||
|
level=DEBUG
|
||||||
|
handlers=fileOutHandler
|
||||||
|
qualname=notifier
|
||||||
|
|
||||||
|
[logger_metadata]
|
||||||
|
level=DEBUG
|
||||||
|
handlers=fileOutHandler
|
||||||
|
qualname=metadata
|
||||||
|
|
||||||
[handler_fileOutHandler]
|
[handler_fileOutHandler]
|
||||||
class=logging.handlers.RotatingFileHandler
|
class=logging.handlers.RotatingFileHandler
|
||||||
level=DEBUG
|
level=DEBUG
|
||||||
formatter=simpleFormatter
|
formatter=simpleFormatter
|
||||||
args=("/var/log/airtime/media-monitor/media-monitor.log", 'a', 1000000, 5,)
|
args=("/var/log/airtime/media-monitor/media-monitor.log", 'a', 10000000, 5,)
|
||||||
|
|
||||||
[formatter_simpleFormatter]
|
[formatter_simpleFormatter]
|
||||||
format=%(asctime)s %(levelname)s - [%(filename)s : %(funcName)s() : line %(lineno)d] - %(message)s
|
format=%(asctime)s %(levelname)s - [%(threadName)s] [%(filename)s : %(funcName)s()] : LINE %(lineno)d - %(message)s
|
||||||
datefmt=
|
datefmt=
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue