Commits

Travis Shirk committed 5215b1c

XDOR <--> TDRC, and fixes.

Comments (0)

Files changed (4)

src/eyed3/id3/tag.py

                     # TORY -> TDOR (year only)
                     date = self._v23OrignalReleaseDate()
                     if date:
-                        converted_frames.append(DateFrame("TDOR",
-                                                          unicode(date)))
+                        converted_frames.append(DateFrame("TDOR", date))
                     flist.remove(date_frames["TORY"])
                     del date_frames["TORY"]
 
-                if date_frames["TYER"]:
+                if "TYER" in date_frames:
                     # TYER, TDAT, TIME -> TDRC
                     date = self._v23RecordingDate()
                     if date:
-                        converted_frames.append(DateFrame("TDRC",
-                                                          unicode(date)))
+                        converted_frames.append(DateFrame("TDRC", date))
                     for fid in ["TYER", "TDAT", "TIME"]:
                         if fid in date_frames:
                             flist.remove(date_frames[fid])
                             del date_frames[fid]
 
+                if "XDOR" in date_frames:
+                    # XDOR -> TDRC
+                    xdor = date_frames["XDOR"]
+                    converted_frames.append(DateFrame("TDRC", xdor.text))
+
+                    flist.remove(xdor)
+                    del date_frames["XDOR"]
+
             elif version == ID3_V2_3:
                 if "TDOR" in date_frames:
                     date = date_frames["TDOR"].date
                     flist.remove(date_frames["TDRL"])
                     del date_frames["TDRL"]
 
+                if "TDRC" in date_frames:
+                    # TDRC -> XDOR
+                    date = date_frames["TDRC"].date
+                    if date:
+                        converted_frames.append(DateFrame("XDOR", str(date)))
+                    flist.remove(date_frames["TDRC"])
+                    del date_frames["TDRC"]
+
             # All other date frames have no conversion
             for fid in date_frames:
                 log.warning("%s frame being dropped due to conversion to %s" %
             flist.remove(frame)
             converted_frames.append(frame)
 
-        # TODO: writing, XDOR only v2.3, convert to TDRC for v2.4
-
         if len(flist) != 0:
             unconverted = ", ".join([f.id for f in flist])
             raise TagException("Unable to covert the following frames to "

src/test/id3/test_tag.py

     finally:
         os.remove(test_file)
 
+def test_XDOR_TDRC_Conversions():
+    test_file = "/tmp/xdortdrc.id3"
 
-# TODO
-class ParseTests(unittest.TestCase):
-    def setUp(self):
-        pass
+    tag = Tag()
+    # 2.3 frames to 2.4
+    frame = frames.DateFrame("XDOR", "1990-06-24")
+    tag.frame_set["XDOR"] = frame
+    try:
+        tag.save(test_file)  # v2.4 is the default
+        tag = eyed3.load(test_file).tag
+        assert_equal(tag.version, ID3_V2_4)
+        assert_equal(len(tag.frame_set), 1)
+        del tag.frame_set["TDRC"]
+        assert_equal(len(tag.frame_set), 0)
+    finally:
+        os.remove(test_file)
 
+    tag = Tag()
+    # 2.4 frames to 2.3
+    frame = frames.DateFrame("TDRC", "2012-10-21")
+    tag.frame_set[frame.id] = frame
+    try:
+        tag.save(test_file, version=eyed3.id3.ID3_V2_3)
+        tag = eyed3.load(test_file).tag
+        assert_equal(tag.version, ID3_V2_3)
+        assert_equal(len(tag.frame_set), 1)
+        del tag.frame_set["XDOR"]
+        assert_equal(len(tag.frame_set), 0)
+    finally:
+        os.remove(test_file)
+

src/test/test_main.py

     def testLoadPlugin(self):
         from eyed3 import plugins
         from eyed3.plugins.classic import ClassicPlugin
-        from eyed3.plugins.examples import (MimeTypesPlugin, Mp3InfoPlugin,
+        from eyed3.plugins.examples import (MimeTypesPlugin,
                                             GenreListPlugin)
 
         args, _, _ = main.parseCommandLine([""])
             plugin = main.parseCommandLine(args)[0].plugin
             assert_true(isinstance(plugin, MimeTypesPlugin))
 
-        args, _, _ = main.parseCommandLine(["--plugin=mp3"])
-        assert_true(isinstance(args.plugin, Mp3InfoPlugin))
         args, _, _ = main.parseCommandLine(["--plugin=genres"])
         assert_true(isinstance(args.plugin, GenreListPlugin))
 

src/test/test_plugins.py

     plugins = load()
     assert_in("classic", plugins.keys())
     assert_in("mimetypes", plugins.keys()),
-    assert_in("mp3", plugins.keys())
     assert_in("genres", plugins.keys())
 
     assert_equal(load("classic"), plugins["classic"])
     assert_equal(load("mimetypes"), plugins["mimetypes"])
-    assert_equal(load("mp3"), plugins["mp3"])
     assert_equal(load("genres"), plugins["genres"])
 
     assert_equal(load("classic", reload=True).__class__.__name__,
                  plugins["classic"].__class__.__name__)
     assert_equal(load("mimetypes", reload=True).__class__.__name__,
                  plugins["mimetypes"].__class__.__name__)
-    assert_equal(load("mp3", reload=True).__class__.__name__,
-                 plugins["mp3"].__class__.__name__)
     assert_equal(load("genres", reload=True).__class__.__name__,
                  plugins["genres"].__class__.__name__)