Skip to content

Commit

Permalink
chg: More forgiving of invalid text encoding identifiers (fixes #101)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicfit committed Nov 18, 2017
1 parent ed215f3 commit 3094a8a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/eyed3/id3/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def encoding(self, enc):
if not isinstance(enc, bytes):
raise TypeError("encoding argument must be a byte string.")
elif not (LATIN1_ENCODING <= enc <= UTF_8_ENCODING):
raise ValueError("encoding argument must be a valid constant.")
raise ValueError("Unknown encoding value {}".format(enc))
self._encoding = enc


Expand All @@ -270,9 +270,16 @@ def text(self, txt):
def parse(self, data, frame_header):
super(TextFrame, self).parse(data, frame_header)

self.encoding = self.data[0:1]
try:
self.text = decodeUnicode(self.data[1:], self.encoding)
self.encoding = self.data[0:1]
text_data = self.data[1:]
except ValueError as err:
log.warning("{err}; using latin1".format(err=err))
self.encoding = LATIN1_ENCODING
text_data = self.data[:]

try:
self.text = decodeUnicode(text_data, self.encoding)
except UnicodeDecodeError as err:
log.warning("Error decoding text frame {fid}: {err}"
.format(fid=self.id, err=err))
Expand Down

0 comments on commit 3094a8a

Please sign in to comment.