How to use the mutagen._senf.fsnative function in mutagen

To help you get started, we’ve selected a few mutagen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github quodlibet / mutagen / tests / test_tools_mid3v2.py View on Github external
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)
github quodlibet / mutagen / tests / test_tools_mid3v2.py View on Github external
def test_wcom_multiple(self):
        res, out = self.call(
            fsn(u"--WCOM"), fsn(u"foo"),
            fsn(u"--WCOM"), fsn(u"bar"),
            self.filename)
        self.failUnlessEqual((res, out), (0, ""))
        f = ID3(self.filename)
        frames = f.getall("WCOM")
        assert len(frames) == 1
        assert frames[0].url == "bar"
github quodlibet / mutagen / tests / test_tools_mid3v2.py View on Github external
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 isinstance(self.filename, fsn)
        os.close(fd)
        shutil.copy(original, self.filename)
github quodlibet / mutagen / tests / test_tools_mid3v2.py View on Github external
def test_frame_from_fsnative(self):
        fffs = self.get_var("frame_from_fsnative")
        self.assertTrue(isinstance(fffs(fsn(u"abc")), str))
        self.assertEqual(fffs(fsn(u"abc")), "abc")
        self.assertRaises(ValueError, fffs, fsn(u"öäü"))
github quodlibet / mutagen / tests / test_tools_mid3iconv.py View on Github external
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))
github quodlibet / mutagen / tests / test_tools_mid3v2.py View on Github external
def test_comm1(self):
        res, out = self.call(fsn(u"--COMM"), fsn(u"A"), self.filename)
        self.failUnlessEqual((res, out), (0, ""))

        f = ID3(self.filename)
        frame = f.getall("COMM:")[0]
        self.failUnlessEqual(frame.desc, "")
        self.failUnlessEqual(frame.text, ["A"])
github quodlibet / mutagen / tests / test_tools_mid3v2.py View on Github external
def test_txxx_multiple(self):
        res, out = self.call(
            fsn(u"--TXXX"), fsn(u"A:B"),
            fsn(u"--TXXX"), fsn(u"C:D"),
            self.filename)
        self.failUnlessEqual((res, out), (0, ""))
        f = ID3(self.filename)
        assert len(f.getall("TXXX")) == 2
github quodlibet / mutagen / tests / test_tools_mid3cp.py View on Github external
def test_merge(self):
        id3 = ID3(self.filename)
        id3.delete()
        id3.add(mutagen.id3.TALB(text=[u"foo"]))
        id3.save(v2_version=3)

        target = ID3()
        target.add(mutagen.id3.TPE1(text=[u"bar", u"quux"]))
        target.save(self.blank_file, v2_version=4)

        res, out, err = self.call2(
            self.filename, self.blank_file, fsn(u"--merge"))
        assert not any([res, out, err])

        result = ID3(self.blank_file)
        assert result.version == (2, 4, 0)
        assert result.getall("TALB")[0].text == [u"foo"]
        assert result.getall("TPE1")[0].text == [u"bar", u"quux"]
github quodlibet / mutagen / tests / test_tools_mid3v2.py View on Github external
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)
github quodlibet / mutagen / mutagen / _tools / mid3iconv.py View on Github external
help="Use an ID3v1 tag even if an ID3v2 tag is present")
    parser.add_option(
        "--remove-v1", action="store_true", dest="remove_v1",
        help="Remove v1 tag after processing the files")
    parser.add_option(
        "-q", "--quiet", action="store_const", dest="verbose",
        const="quiet", help="Only output errors")
    parser.add_option(
        "-d", "--debug", action="store_const", dest="verbose",
        const="debug", help="Output updated tags")

    for i, arg in enumerate(argv):
        if arg == "-v1":
            argv[i] = fsnative(u"--force-v1")
        elif arg == "-removev1":
            argv[i] = fsnative(u"--remove-v1")

    (options, args) = parser.parse_args(argv[1:])

    if args:
        update(options, args)
    else:
        parser.print_help()