From: W. Trevor King Date: Wed, 22 Aug 2012 00:37:36 +0000 (-0400) Subject: Fix Unicode tag encoding in mkogg's mp3 output. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=685794930af9d44890c3ca375a9ef6abb99b586c;p=blog.git Fix Unicode tag encoding in mkogg's mp3 output. --- diff --git a/posts/mkogg/mkogg.py b/posts/mkogg/mkogg.py index cab3e05..a9bfdc6 100755 --- a/posts/mkogg/mkogg.py +++ b/posts/mkogg/mkogg.py @@ -310,7 +310,7 @@ class Converter (object): try: text.encode(encoding) except UnicodeEncodeError: - encoding_success == False + encoding_success = False break if encoding_success: return id3_encoding @@ -413,6 +413,7 @@ class Converter (object): if mp3.tags is not None: mp3.tags.delete() handled_trck = False + max_encoding = 0 for key,value in metadata.items(): if key == 'date': for i,v in enumerate(value): @@ -431,10 +432,15 @@ class Converter (object): continue frame = getattr(mutagen.id3, frame_name) id3_encoding = self._guess_id3_encoding(value) + max_encoding = max(max_encoding, id3_encoding) mp3[frame_name] = frame(encoding=id3_encoding, text=value) if mp3.tags is None: return - mp3.save(v1=2) + if max_encoding: # at least one tag doesn't use ISO-8859-1 + v1 = 0 # remove ID3v1 tags + else: + v1 = 2 # create and/or update ID3v1 tags + mp3.save(v1=v1) def set_ogg_metadata(self, target, metadata): if mutagen is None: