CC-2505 : Media monitor doesn't delete some tracks from the Airtime server due to weird characters in file names

seems to fix unicode problems I was having.
This commit is contained in:
Naomi Aro 2011-07-18 12:05:16 +02:00
parent c74af05f18
commit e369ab8dee
2 changed files with 59 additions and 52 deletions

View File

@ -120,45 +120,52 @@ class AirtimeNotifier(Notifier):
# -data # -data
# -is_recorded_show # -is_recorded_show
def update_airtime(self, d): def update_airtime(self, d):
filepath = d['filepath']
mode = d['mode']
md = {} try:
md['MDATA_KEY_FILEPATH'] = filepath.encode("utf_8") self.logger.info("updating filepath: %s ", d['filepath'])
filepath = d['filepath']
mode = d['mode']
if 'data' in d: md = {}
file_md = d['data'] md['MDATA_KEY_FILEPATH'] = filepath
md.update(file_md)
else: if 'data' in d:
file_md = None file_md = d['data']
data = None md.update(file_md)
else:
file_md = None
data = None
if (os.path.exists(filepath) and (mode == self.config.MODE_CREATE)): if (os.path.exists(filepath) and (mode == self.config.MODE_CREATE)):
if file_md is None: if file_md is None:
mutagen = self.md_manager.get_md_from_file(filepath)
if mutagen is None:
return
md.update(mutagen)
if d['is_recorded_show']:
self.api_client.update_media_metadata(md, mode, True)
else:
self.api_client.update_media_metadata(md, mode)
elif (os.path.exists(filepath) and (mode == self.config.MODE_MODIFY)):
mutagen = self.md_manager.get_md_from_file(filepath) mutagen = self.md_manager.get_md_from_file(filepath)
if mutagen is None: if mutagen is None:
return return
md.update(mutagen) md.update(mutagen)
if d['is_recorded_show']:
self.api_client.update_media_metadata(md, mode, True)
else:
self.api_client.update_media_metadata(md, mode) self.api_client.update_media_metadata(md, mode)
elif (os.path.exists(filepath) and (mode == self.config.MODE_MODIFY)): elif (mode == self.config.MODE_MOVED):
mutagen = self.md_manager.get_md_from_file(filepath) md['MDATA_KEY_MD5'] = self.md_manager.get_md5(filepath)
if mutagen is None: self.api_client.update_media_metadata(md, mode)
return
md.update(mutagen)
self.api_client.update_media_metadata(md, mode)
elif (mode == self.config.MODE_MOVED): elif (mode == self.config.MODE_DELETE):
md['MDATA_KEY_MD5'] = self.md_manager.get_md5(filepath) self.api_client.update_media_metadata(md, mode)
self.api_client.update_media_metadata(md, mode)
elif (mode == self.config.MODE_DELETE): except Exception, e:
self.api_client.update_media_metadata(md, mode) self.logger.error("failed updating filepath: %s ", d['filepath'])
self.logger.error('Exception: %s', e)
#define which directories the pyinotify WatchManager should watch. #define which directories the pyinotify WatchManager should watch.
def watch_directory(self, directory): def watch_directory(self, directory):

View File

@ -228,7 +228,7 @@ class MediaMonitorCommon:
open(self.timestamp_file, "w") open(self.timestamp_file, "w")
def organize_new_file(self, pathname): def organize_new_file(self, pathname):
self.logger.info(u"Organizing new file: %s", pathname) self.logger.info("Organizing new file: %s", pathname)
file_md = self.md_manager.get_md_from_file(pathname) file_md = self.md_manager.get_md_from_file(pathname)
if file_md is not None: if file_md is not None:
@ -236,7 +236,7 @@ class MediaMonitorCommon:
# file_md['MDATA_KEY_CREATOR'] == "AIRTIMERECORDERSOURCEFABRIC".encode('utf-8') # file_md['MDATA_KEY_CREATOR'] == "AIRTIMERECORDERSOURCEFABRIC".encode('utf-8')
filepath = self.create_file_path(pathname, file_md) filepath = self.create_file_path(pathname, file_md)
self.logger.debug(u"Moving from %s to %s", pathname, filepath) self.logger.debug("Moving from %s to %s", pathname, filepath)
self.move_file(pathname, filepath) self.move_file(pathname, filepath)
else: else:
filepath = None filepath = None