Don't write string terminators to ID3 frames.

This commit is contained in:
Lukáš Lalinský
2007-04-15 22:20:15 +02:00
parent d1b0017f6f
commit 911d91ab0f
2 changed files with 22 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
Version 0.9.0beta1 - 2007-XX-YY
* Bug Fixes:
* Save XSOP frame to ID3v2.3 tags. (#2484)
* Don't write string terminators to ID3 frames.
Version 0.9.0alpha8 - 2007-04-15
* New Features:

View File

@@ -31,14 +31,32 @@ from picard.util import encode_filename, sanitize_date
# unsupported characters and this better than encoding, decoding and
# again encoding.
def patched_EncodedTextSpec_write(self, frame, value):
if hasattr(self, 'encodings'):
enc, term = self.encodings[frame.encoding]
else:
try:
enc, term = self._encodings[frame.encoding]
except AttributeError:
enc, term = self.encodings[frame.encoding]
return value.encode(enc, 'ignore') + term
id3.EncodedTextSpec.write = patched_EncodedTextSpec_write
# One more "monkey patch". The ID3 spec says that multiple text
# values should be _separated_ by the string terminator, which
# means that e.g. 'a\x00' are two values, 'a' and ''.
def patched_MultiSpec_write(self, frame, value):
data = self._write_orig(frame, value)
spec = self.specs[-1]
if isinstance(spec, id3.EncodedTextSpec):
try:
term = spec._encodings[frame.encoding][1]
except AttributeError:
term = spec.encodings[frame.encoding][1]
if data.endswith(term):
data = data[:-len(term)]
return data
id3.MultiSpec._write_orig = id3.MultiSpec.write
id3.MultiSpec.write = patched_MultiSpec_write
class ID3File(File):
"""Generic ID3-based file."""
_File = None