Beispiel #1
0
 def test_tyer_tdat(self):
     id3 = ID3()
     id3.version = (2, 3)
     id3.add(TYER(encoding=0, text="2006"))
     id3.add(TDAT(encoding=0, text="0603"))
     id3.update_to_v24()
     self.failUnlessEqual(id3["TDRC"], "2006-03-06")
Beispiel #2
0
 def test_tyer_tdat(self):
     id3 = ID3()
     id3.version = (2, 3)
     id3.add(TYER(encoding=0, text="2006"))
     id3.add(TDAT(encoding=0, text="0603"))
     id3.update_to_v24()
     self.failUnlessEqual(id3["TDRC"], "2006-03-06")
Beispiel #3
0
def copy(src, dst, merge, write_v1=True, excluded_tags=None, verbose=False):
    """Returns 0 on success"""

    if excluded_tags is None:
        excluded_tags = []

    try:
        id3 = mutagen.id3.ID3(src, translate=False)
    except mutagen.id3.ID3NoHeaderError:
        print_(u"No ID3 header found in ", src, file=sys.stderr)
        return 1
    except Exception as err:
        print_(str(err), file=sys.stderr)
        return 1

    if verbose:
        print_(u"File", src, u"contains:", file=sys.stderr)
        print_(id3.pprint(), file=sys.stderr)

    for tag in excluded_tags:
        id3.delall(tag)

    if merge:
        try:
            target = mutagen.id3.ID3(dst, translate=False)
        except mutagen.id3.ID3NoHeaderError:
            # no need to merge
            pass
        except Exception as err:
            print_(str(err), file=sys.stderr)
            return 1
        else:
            for frame in id3.values():
                target.add(frame)

            id3 = target

    # if the source is 2.3 save it as 2.3
    if id3.version < (2, 4, 0):
        id3.update_to_v23()
        v2_version = 3
    else:
        id3.update_to_v24()
        v2_version = 4

    try:
        id3.save(dst, v1=(2 if write_v1 else 0), v2_version=v2_version)
    except Exception as err:
        print_(u"Error saving",
               dst,
               u":\n%s" % text_type(err),
               file=sys.stderr)
        return 1
    else:
        if verbose:
            print_(u"Successfully saved", dst, file=sys.stderr)
        return 0
Beispiel #4
0
 def test_multiple_tyer_tdat_time(self):
     id3 = ID3()
     id3.version = (2, 3)
     id3.add(TYER(text=['2000', '2001', '2002', '19xx', 'foo']))
     id3.add(TDAT(text=['0102', '0304', '1111bar']))
     id3.add(TIME(text=['1220', '1111quux', '1111']))
     id3.update_to_v24()
     assert [str(t) for t in id3['TDRC']] == \
         ['2000-02-01 12:20:00', '2001-04-03', '2002']
Beispiel #5
0
 def test_chap_subframes(self):
     id3 = ID3()
     id3.version = (2, 3)
     id3.add(CHAP(element_id="foo", start_time=0, end_time=0,
                  start_offset=0, end_offset=0,
                  sub_frames=[TYER(encoding=0, text="2006")]))
     id3.update_to_v24()
     chap = id3.getall("CHAP:foo")[0]
     self.assertEqual(chap.sub_frames.getall("TDRC")[0], u"2006")
Beispiel #6
0
 def test_ctoc_subframes(self):
     id3 = ID3()
     id3.version = (2, 3)
     id3.add(CTOC(sub_frames=[TYER(encoding=0, text="2006")]))
     id3.update_to_v24()
     ctoc = id3.getall("CTOC")[0]
     self.assertEqual(ctoc.sub_frames.getall("TDRC")[0], u"2006")
     self.assertFalse(ctoc.sub_frames.getall("TYER"))
     id3.update_to_v23()
     self.assertEqual(ctoc.sub_frames.getall("TYER")[0], u"2006")
Beispiel #7
0
 def test_ctoc_subframes(self):
     id3 = ID3()
     id3.version = (2, 3)
     id3.add(CTOC(sub_frames=[TYER(encoding=0, text="2006")]))
     id3.update_to_v24()
     ctoc = id3.getall("CTOC")[0]
     self.assertEqual(ctoc.sub_frames.getall("TDRC")[0], u"2006")
     self.assertFalse(ctoc.sub_frames.getall("TYER"))
     id3.update_to_v23()
     self.assertEqual(ctoc.sub_frames.getall("TYER")[0], u"2006")
Beispiel #8
0
def copy(src, dst, merge, write_v1=True, excluded_tags=None, verbose=False):
    """Returns 0 on success"""

    if excluded_tags is None:
        excluded_tags = []

    try:
        id3 = mutagen.id3.ID3(src, translate=False)
    except mutagen.id3.ID3NoHeaderError:
        print_(u"No ID3 header found in ", src, file=sys.stderr)
        return 1
    except Exception as err:
        print_(str(err), file=sys.stderr)
        return 1

    if verbose:
        print_(u"File", src, u"contains:", file=sys.stderr)
        print_(id3.pprint(), file=sys.stderr)

    for tag in excluded_tags:
        id3.delall(tag)

    if merge:
        try:
            target = mutagen.id3.ID3(dst, translate=False)
        except mutagen.id3.ID3NoHeaderError:
            # no need to merge
            pass
        except Exception as err:
            print_(str(err), file=sys.stderr)
            return 1
        else:
            for frame in id3.values():
                target.add(frame)

            id3 = target

    # if the source is 2.3 save it as 2.3
    if id3.version < (2, 4, 0):
        id3.update_to_v23()
        v2_version = 3
    else:
        id3.update_to_v24()
        v2_version = 4

    try:
        id3.save(dst, v1=(2 if write_v1 else 0), v2_version=v2_version)
    except Exception as err:
        print_(u"Error saving", dst, u":\n%s" % text_type(err),
               file=sys.stderr)
        return 1
    else:
        if verbose:
            print_(u"Successfully saved", dst, file=sys.stderr)
        return 0
Beispiel #9
0
 def test_chap_subframes(self):
     id3 = ID3()
     id3.version = (2, 3)
     id3.add(CHAP(element_id="foo", start_time=0, end_time=0,
                  start_offset=0, end_offset=0,
                  sub_frames=[TYER(encoding=0, text="2006")]))
     id3.update_to_v24()
     chap = id3.getall("CHAP:foo")[0]
     self.assertEqual(chap.sub_frames.getall("TDRC")[0], u"2006")
     self.assertFalse(chap.sub_frames.getall("TYER"))
     id3.update_to_v23()
     self.assertEqual(chap.sub_frames.getall("TYER")[0], u"2006")
Beispiel #10
0
 def test_ipls(self):
     id3 = ID3()
     id3.version = (2, 3)
     id3.add(IPLS(encoding=0, people=[["a", "b"], ["c", "d"]]))
     id3.update_to_v24()
     self.failUnlessEqual(id3["TIPL"], [["a", "b"], ["c", "d"]])
Beispiel #11
0
 def test_pic(self):
     id3 = ID3()
     id3.version = (2, 2)
     id3.add(PIC(encoding=0, mime="PNG", desc="cover", type=3, data=b""))
     id3.update_to_v24()
     self.failUnlessEqual(id3["APIC:cover"].mime, "image/png")
Beispiel #12
0
 def test_lnk(self):
     id3 = ID3()
     id3.version = (2, 2)
     id3.add(LNK(frameid="PIC", url="http://foo.bar"))
     id3.update_to_v24()
     self.assertTrue(id3.getall("LINK"))
Beispiel #13
0
 def test_pic(self):
     id3 = ID3()
     id3.version = (2, 2)
     id3.add(PIC(encoding=0, mime="PNG", desc="cover", type=3, data=b""))
     id3.update_to_v24()
     self.failUnlessEqual(id3["APIC:cover"].mime, "image/png")
Beispiel #14
0
 def test_lnk(self):
     id3 = ID3()
     id3.version = (2, 2)
     id3.add(LNK(frameid="PIC", url="http://foo.bar"))
     id3.update_to_v24()
     self.assertTrue(id3.getall("LINK"))
Beispiel #15
0
 def test_tory(self):
     id3 = ID3()
     id3.version = (2, 3)
     id3.add(TORY(encoding=0, text="2006"))
     id3.update_to_v24()
     self.failUnlessEqual(id3["TDOR"], "2006")
Beispiel #16
0
 def test_tory(self):
     id3 = ID3()
     id3.version = (2, 3)
     id3.add(TORY(encoding=0, text="2006"))
     id3.update_to_v24()
     self.failUnlessEqual(id3["TDOR"], "2006")
Beispiel #17
0
 def test_time_dropped(self):
     id3 = ID3()
     id3.version = (2, 3)
     id3.add(TIME(encoding=0, text=["1155"]))
     id3.update_to_v24()
     self.assertFalse(id3.getall("TIME"))
Beispiel #18
0
 def test_ipls(self):
     id3 = ID3()
     id3.version = (2, 3)
     id3.add(IPLS(encoding=0, people=[["a", "b"], ["c", "d"]]))
     id3.update_to_v24()
     self.failUnlessEqual(id3["TIPL"], [["a", "b"], ["c", "d"]])
Beispiel #19
0
 def test_time_dropped(self):
     id3 = ID3()
     id3.version = (2, 3)
     id3.add(TIME(encoding=0, text=["1155"]))
     id3.update_to_v24()
     self.assertFalse(id3.getall("TIME"))
Beispiel #20
0
 def test_rvad_dropped(self):
     id3 = ID3()
     id3.version = (2, 3)
     id3.add(RVAD())
     id3.update_to_v24()
     self.assertFalse(id3.getall("RVAD"))
Beispiel #21
0
 def test_rvad_dropped(self):
     id3 = ID3()
     id3.version = (2, 3)
     id3.add(RVAD())
     id3.update_to_v24()
     self.assertFalse(id3.getall("RVAD"))