Skip to content

Commit

Permalink
fix: ID3 v2.3 to v2.4 date conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
nicfit committed Sep 18, 2019
1 parent 4fe25b3 commit 3758cc5
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/eyed3/id3/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,14 @@ def _convertFrames(self, std_frames, convert_list, version):
date_frames[f.id] = f

if date_frames:
def fidHandled(fid):
# A duplicate text frame (illegal ID3 but oft seen) may exist. The date_frames dict
# will have one, but the flist has multiple, hence the loop.
for frame in list(flist):
if frame.id == fid:
flist.remove(frame)
del date_frames[fid]

if version == ID3_V2_4:
if b"TORY" in date_frames or b"XDOR" in date_frames:
# XDOR -> TDOR (full date)
Expand All @@ -1103,8 +1111,7 @@ def _convertFrames(self, std_frames, convert_list, version):
converted_frames.append(DateFrame(b"TDOR", date))
for fid in (b"TORY", b"XDOR"):
if fid in flist:
flist.remove(date_frames[fid])
del date_frames[fid]
fidHandled(fid)

# TYER, TDAT, TIME -> TDRC
if (b"TYER" in date_frames or b"TDAT" in date_frames or
Expand All @@ -1114,17 +1121,15 @@ def _convertFrames(self, std_frames, convert_list, version):
converted_frames.append(DateFrame(b"TDRC", date))
for fid in [b"TYER", b"TDAT", b"TIME"]:
if fid in date_frames:
flist.remove(date_frames[fid])
del date_frames[fid]
fidHandled(fid)

elif version == ID3_V2_3:
if b"TDOR" in date_frames:
date = date_frames[b"TDOR"].date
if date:
converted_frames.append(DateFrame(b"TORY",
unicode(date.year)))
flist.remove(date_frames[b"TDOR"])
del date_frames[b"TDOR"]
fidHandled(b"TDOR")

if b"TDRC" in date_frames:
date = date_frames[b"TDRC"].date
Expand All @@ -1145,16 +1150,14 @@ def _convertFrames(self, std_frames, convert_list, version):
converted_frames.append(TextFrame(b"TIME",
date_str))

flist.remove(date_frames[b"TDRC"])
del date_frames[b"TDRC"]
fidHandled(b"TDRC")

if b"TDRL" in date_frames:
# TDRL -> XDOR
date = date_frames[b"TDRL"].date
if date:
converted_frames.append(DateFrame(b"XDOR", str(date)))
flist.remove(date_frames[b"TDRL"])
del date_frames[b"TDRL"]
fidHandled(b"TDRL")

# All other date frames have no conversion
for fid in date_frames:
Expand Down Expand Up @@ -1189,7 +1192,7 @@ def _convertFrames(self, std_frames, convert_list, version):
if len(flist) != 0:
unconverted = u", ".join([f.id.decode("ascii") for f in flist])
if version[0] != 1:
raise TagException("Unable to covert the following frames to "
raise TagException("Unable to convert the following frames to "
"version %s: %s" % (versionToString(version),
unconverted))

Expand Down

0 comments on commit 3758cc5

Please sign in to comment.