From 685794930af9d44890c3ca375a9ef6abb99b586c Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 21 Aug 2012 20:37:36 -0400 Subject: [PATCH] Fix Unicode tag encoding in mkogg's mp3 output. --- posts/mkogg/mkogg.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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: -- 2.26.2