cc-4105: Fixed up mutagen metadata related stuff. Included utf8 routines from old media monitor

This commit is contained in:
Rudi Grinberg 2012-07-19 18:16:53 -04:00
parent 1c09907fd5
commit 58fb152a8d
2 changed files with 18 additions and 6 deletions

View file

@ -125,7 +125,7 @@ def normalized_metadata(md, original_path):
new_md = copy.deepcopy(md)
# replace all slashes with dashes
for k,v in new_md.iteritems():
new_md[k] = str(v).replace('/','-')
new_md[k] = unicode(v).replace('/','-')
# Specific rules that are applied in a per attribute basis
format_rules = {
# It's very likely that the following isn't strictly necessary. But the old
@ -206,6 +206,15 @@ def file_md5(path,max_length=100):
return m.hexdigest()
else: raise ValueError("'%s' must exist to find its md5")
def encode_to(obj, encoding='utf-8'):
if isinstance(obj, unicode):
obj = obj.encode(encoding)
return obj
def convert_dict_value_to_utf8(md):
#list comprehension to convert all values of md to utf-8
return dict([(item[0], encode_to(item[1], "utf-8")) for item in md.items()])
if __name__ == '__main__':
import doctest
doctest.testmod()