Exemplo n.º 1
0
 def setUp(self):
     super(TMid3v2, self).setUp()
     original = os.path.join(DATA_DIR, fsn(u'silence-44-s.mp3'))
     fd, self.filename = mkstemp(suffix=fsn(u'öäü.mp3'))
     assert isfsn(self.filename)
     os.close(fd)
     shutil.copy(original, self.filename)
Exemplo n.º 2
0
 def test_artist_escape(self):
     res, out = self.call(
         fsn(u"-e"), fsn(u"-a"), fsn(u"foo\\nbar"), self.filename)
     self.failUnlessEqual(res, 0)
     self.failIf(out)
     f = ID3(self.filename)
     self.failUnlessEqual(f["TPE1"][0], "foo\nbar")
Exemplo n.º 3
0
 def test_list(self):
     f = ID3(self.filename)
     album = f["TALB"].text[0]
     for arg in [fsn(u"-l"), fsn(u"--list")]:
         res, out = self.call(arg, self.filename)
         self.assertFalse("b'" in out)
         self.failUnlessEqual(res, 0)
         self.failUnless("TALB=" + fsn(album) in out)
Exemplo n.º 4
0
    def test_value_from_fsnative(self):
        vffs = self.get_var("value_from_fsnative")
        self.assertEqual(vffs(fsn(u"öäü\\n"), True), u"öäü\n")
        self.assertEqual(vffs(fsn(u"öäü\\n"), False), u"öäü\\n")

        if os.name != "nt" and PY3:
            se = b"\xff".decode("utf-8", "surrogateescape")
            self.assertRaises(ValueError, vffs, se, False)
Exemplo n.º 5
0
    def test_comm2(self):
        res, out = self.call(fsn(u"--COMM"), fsn(u"Y:B"), self.filename)
        self.failUnlessEqual((res, out), (0, ""))

        f = ID3(self.filename)
        frame = f.getall("COMM:Y")[0]
        self.failUnlessEqual(frame.desc, "Y")
        self.failUnlessEqual(frame.text, ["B"])
Exemplo n.º 6
0
    def test_exclude_single_tag(self):
        self.call(fsn(u"-x"), fsn(u"TLEN"), self.filename, self.blank_file)

        original_id3 = ID3(self.filename)
        copied_id3 = ID3(self.blank_file)

        self.failUnless("TLEN" in original_id3)
        self.failIf("TLEN" in copied_id3)
Exemplo n.º 7
0
    def test_txxx(self):
        res, out = self.call(fsn(u"--TXXX"), fsn(u"A\\:B:C"), self.filename)
        self.failUnlessEqual((res, out), (0, ""))

        f = ID3(self.filename)
        frame = f.getall("TXXX")[0]
        self.failUnlessEqual(frame.desc, "A\\")
        self.failUnlessEqual(frame.text, ["B:C"])
Exemplo n.º 8
0
    def setUp(self):
        super(TMid3cp, self).setUp()
        original = os.path.join(DATA_DIR, fsn(u"silence-44-s.mp3"))
        fd, self.filename = mkstemp(suffix=fsn(u"öäü.mp3"))
        os.close(fd)
        shutil.copy(original, self.filename)

        fd, self.blank_file = mkstemp(suffix=fsn(u".mp3"))
        os.close(fd)
Exemplo n.º 9
0
    def test_comm2_escape(self):
        res, out = self.call(
            fsn(u"-e"), fsn(u"--COMM"), fsn(u"Y\\:B\\nG"), self.filename)
        self.failUnlessEqual((res, out), (0, ""))

        f = ID3(self.filename)
        frame = f.getall("COMM:")[0]
        self.failUnlessEqual(frame.desc, "")
        self.failUnlessEqual(frame.text, ["Y:B\nG"])
Exemplo n.º 10
0
    def test_ufid(self):
        res, out, err = self.call2(
            fsn(u"--UFID"), fsn(u"foo:bar"), self.filename)
        self.assertEqual((res, out, err), (0, "", ""))

        f = ID3(self.filename)
        frame = f.getall("UFID:foo")[0]
        self.assertEqual(frame.owner, u"foo")
        self.assertEqual(frame.data, b"bar")
Exemplo n.º 11
0
    def test_comm3(self):
        res, out = self.call(
            fsn(u"--COMM"), fsn(u"Z:B:C:D:ger"), self.filename)
        self.failUnlessEqual((res, out), (0, ""))

        f = ID3(self.filename)
        frame = f.getall("COMM:Z")[0]
        self.failUnlessEqual(frame.desc, "Z")
        self.failUnlessEqual(frame.text, ["B:C:D"])
        self.failUnlessEqual(frame.lang, "ger")
Exemplo n.º 12
0
    def test_basic(self):
        base = os.path.join(fsn(u'tests'), fsn(u'data'))
        self.paths = glob.glob(os.path.join(base, "empty*"))
        self.paths += glob.glob(os.path.join(base, "silence-*"))

        for path in self.paths:
            res, out = self.call(path)
            self.failIf(res)
            self.failUnless(out.strip())
            self.failIf("Unknown file type" in out)
            self.failIf("Errno" in out)
Exemplo n.º 13
0
    def test_basic(self):
        d = os.path.dirname(self.filename)
        p = os.path.join(d, fsn(u"%(stream)d.%(ext)s"))
        res, out = self.call(fsn(u"--pattern"), p, self.filename)
        self.failIf(res)
        self.failIf(out)

        for stream in [1002429366, 1806412655]:
            stream_path = os.path.join(
                d, fsn(text_type(stream)) + fsn(u".ogg"))
            self.failUnless(os.path.exists(stream_path))
            os.unlink(stream_path)
Exemplo n.º 14
0
    def test_txxx_escape(self):
        res, out = self.call(
            fsn(u"-e"), fsn(u"--TXXX"),
            fsn(u"EscapeTest\\:\\:albumartist:Ex\\:ample"),
            self.filename)
        self.failUnlessEqual(res, 0)
        self.failIf(out)

        f = ID3(self.filename)
        frame = f.getall("TXXX")[0]
        self.failUnlessEqual(frame.desc, u"EscapeTest::albumartist")
        self.failUnlessEqual(frame.text, [u"Ex:ample"])
Exemplo n.º 15
0
    def test_conv_basic(self):
        from mutagen.id3 import TALB

        for codec in CODECS:
            f = ID3(self.filename)
            f.add(TALB(text=[AMBIGUOUS.decode("latin-1")], encoding=0))
            f.save()
            res, out = self.call(
                fsn(u"-d"), fsn(u"-e"), fsn(text_type(codec)), self.filename)
            f = ID3(self.filename)
            self.failUnlessEqual(f["TALB"].encoding, 1)
            self.failUnlessEqual(f["TALB"].text[0], AMBIGUOUS.decode(codec))
Exemplo n.º 16
0
    def setUp(self):
        super(TMOggSPlit, self).setUp()
        self.filename = get_temp_copy(
            os.path.join(DATA_DIR, fsn(u'multipagecomment.ogg')))

        # append the second file
        first = open(self.filename, "ab")
        to_append = os.path.join(
            DATA_DIR, fsn(u'multipage-setup.ogg'))
        second = open(to_append, "rb")
        first.write(second.read())
        second.close()
        first.close()
Exemplo n.º 17
0
    def test_encoding_with_escape(self):
        is_bytes = PY2 and os.name != "nt"

        text = u'\xe4\xf6\xfc'
        if is_bytes:
            enc = locale.getpreferredencoding()
            # don't fail in case getpreferredencoding doesn't give us a unicode
            # encoding.
            text = text.encode(enc, "replace")
        res, out = self.call(fsn(u"-e"), fsn(u"-a"), text, self.filename)
        self.failUnlessEqual((res, out), (0, ""))
        f = ID3(self.filename)
        if is_bytes:
            text = text.decode(enc)
        self.assertEqual(f.getall("TPE1")[0], text)
Exemplo n.º 18
0
    def test_comm(self):
        from mutagen.id3 import COMM

        for codec in CODECS:
            f = ID3(self.filename)
            frame = COMM(desc="", lang="eng", encoding=0,
                         text=[AMBIGUOUS.decode("latin-1")])
            f.add(frame)
            f.save()
            res, out = self.call(
                fsn(u"-d"), fsn(u"-e"), fsn(text_type(codec)), self.filename)
            f = ID3(self.filename)
            new_frame = f[frame.HashKey]
            self.failUnlessEqual(new_frame.encoding, 1)
            self.failUnlessEqual(new_frame.text[0], AMBIGUOUS.decode(codec))
Exemplo n.º 19
0
    def setUp(self):
        super(TMOggSPlit, self).setUp()
        original = os.path.join(
            DATA_DIR, fsn(u'multipagecomment.ogg'))
        fd, self.filename = mkstemp(suffix=fsn(u'.ogg'))
        os.close(fd)
        shutil.copy(original, self.filename)

        # append the second file
        first = open(self.filename, "ab")
        to_append = os.path.join(
            DATA_DIR, fsn(u'multipage-setup.ogg'))
        second = open(to_append, "rb")
        first.write(second.read())
        second.close()
        first.close()
Exemplo n.º 20
0
 def test_no_src_header(self):
     fd, blank_file2 = mkstemp(suffix=fsn(u".mp3"))
     os.close(fd)
     try:
         err = self.call2(self.blank_file, blank_file2)[2]
         self.failUnless("No ID3 header found" in err)
     finally:
         os.unlink(blank_file2)
Exemplo n.º 21
0
    def test_remove_v1(self):
        from mutagen.id3 import ParseID3v1
        res, out = self.call(fsn(u"--remove-v1"), self.filename)

        with open(self.filename, "rb") as h:
            h.seek(-128, 2)
            data = h.read()
            self.failUnlessEqual(len(data), 128)
            self.failIf(ParseID3v1(data))
Exemplo n.º 22
0
    def test_include_id3v1(self):
        self.call(fsn(u"--write-v1"), self.filename, self.blank_file)

        with open(self.blank_file, "rb") as fileobj:
            fileobj.seek(-128, 2)
            frames = ParseID3v1(fileobj.read(128))

        # If ID3v1 frames are present, assume they've been written correctly by
        # mutagen, so no need to check them
        self.failUnless(frames)
Exemplo n.º 23
0
    def test_apic(self):
        image_path = os.path.join(DATA_DIR, "image.jpg")
        image_path = os.path.relpath(image_path)
        res, out, err = self.call2(
            fsn(u"--APIC"), image_path + fsn(u":fooAPIC:3:image/jpeg"),
            self.filename)
        self.failUnlessEqual((res, out, err), (0, "", ""))

        with open(image_path, "rb") as h:
            data = h.read()

        f = ID3(self.filename)
        frame = f.getall("APIC:fooAPIC")[0]
        self.assertEqual(frame.desc, u"fooAPIC")
        self.assertEqual(frame.mime, "image/jpeg")
        self.assertEqual(frame.data, data)

        res, out = self.call(fsn(u"--list"), self.filename)
        self.assertEqual(res, 0)
        self.assertTrue("fooAPIC" in out)
Exemplo n.º 24
0
    def _test_text_frame(self, short, longer, frame):
        new_value = fsn(u"TEST")
        for arg in [short, longer]:
            orig = ID3(self.filename)
            frame_class = mutagen.id3.Frames[frame]
            orig[frame] = frame_class(text=[u"BLAH"], encoding=3)
            orig.save()

            res, out = self.call(arg, new_value, self.filename)
            self.failUnlessEqual(res, 0)
            self.failIf(out)
            self.failUnlessEqual(ID3(self.filename)[frame].text, [new_value])
Exemplo n.º 25
0
    def test_exit_status(self):
        status, out, err = self.call2(self.filename)
        self.assertTrue(status)

        status, out, err = self.call2(self.filename, self.filename)
        self.assertFalse(status)

        status, out, err = self.call2(self.blank_file, self.filename)
        self.assertTrue(status)

        status, out, err = self.call2(fsn(u""), self.filename)
        self.assertTrue(status)

        status, out, err = self.call2(self.filename, self.blank_file)
        self.assertFalse(status)
Exemplo n.º 26
0
    def test_invalid_escape(self):
        res, out, err = self.call2(
            fsn(u"--TALB"), fsn(u'\\xaz'), fsn(u'-e'), self.filename)
        self.failIfEqual(res, 0)
        self.failUnless("TALB" in err)

        res, out, err = self.call2(
            fsn(u"--TALB"), fsn(u'\\'), fsn(u'-e'), self.filename)
        self.failIfEqual(res, 0)
        self.failUnless("TALB" in err)
Exemplo n.º 27
0
 def test_quiet(self):
     res, out = self.call(fsn(u"-q"), self.filename)
     self.failIf(res)
     self.failIf(out)
Exemplo n.º 28
0
 def test_debug(self):
     res, out = self.call(fsn(u"-d"), fsn(u"-p"), self.filename)
     self.failIf(res)
     self.assertFalse("b'" in out)
     self.failUnless("TCON=Silence" in out)
Exemplo n.º 29
0
 def test_basic(self):
     base = os.path.join(fsn(u'tests'), fsn(u'data'))
     res, out = self.call(base)
     self.failIf(res)
     self.failUnless("Report for %s" % base in out)
Exemplo n.º 30
0
 def setUp(self):
     super(TMid3Iconv, self).setUp()
     self.filename = get_temp_copy(
         os.path.join(DATA_DIR, fsn(u'silence-44-s.mp3')))