當前位置: 首頁>>代碼示例>>Python>>正文


Python formats.MusicFile類代碼示例

本文整理匯總了Python中quodlibet.formats.MusicFile的典型用法代碼示例。如果您正苦於以下問題:Python MusicFile類的具體用法?Python MusicFile怎麽用?Python MusicFile使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了MusicFile類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TOperonImageClear

class TOperonImageClear(TOperonBase):
    # <image-file> <file> [<files>]

    def setUp(self):
        super(TOperonImageClear, self).setUp()
        self.fcover = get_temp_copy(get_data_path('test-2.wma'))
        self.cover = MusicFile(self.fcover)

    def tearDown(self):
        os.unlink(self.fcover)
        super(TOperonImageClear, self).tearDown()

    def test_misc(self):
        self.check_true(["image-clear", "-h"], True, False)
        self.check_true(["image-clear", self.fcover], False, False)
        self.check_false(["image-clear"], False, True)

    def test_not_supported(self):
        path = get_data_path('test.mid')
        out, err = self.check_false(["image-clear", path], False, True)
        self.assertTrue("supported" in err)

    def test_clear(self):
        images = self.cover.get_images()
        self.assertEqual(len(images), 1)

        self.check_true(["image-clear", self.fcover], False, False)

        self.cover.reload()
        images = self.cover.get_images()
        self.assertEqual(len(images), 0)
開發者ID:LudoBike,項目名稱:quodlibet,代碼行數:31,代碼來源:test_operon.py

示例2: TOperonImageSet

class TOperonImageSet(TOperonBase):
    # <image-file> <file> [<files>]

    def setUp(self):
        super(TOperonImageSet, self).setUp()
        from gi.repository import GdkPixbuf

        h, self.filename = mkstemp(".png")
        os.close(h)
        wide = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 150, 10)
        wide.savev(self.filename, "png", [], [])

        self.fcover = get_temp_copy(get_data_path('test-2.wma'))
        self.cover = MusicFile(self.fcover)

        self.fcover2 = get_temp_copy(get_data_path('test-2.wma'))
        self.cover2 = MusicFile(self.fcover2)

    def tearDown(self):
        os.unlink(self.fcover)
        os.unlink(self.filename)
        super(TOperonImageSet, self).tearDown()

    def test_misc(self):
        self.check_true(["image-set", "-h"], True, False)
        self.check_false(["image-set", self.fcover], False, True)
        self.check_false(["image-set"], False, True)
        self.check_false(["image-set", self.filename], False, True)

    def test_not_supported(self):
        path = get_data_path('test.mid')
        out, err = self.check_false(
            ["image-set", self.filename, path], False, True)
        self.assertTrue("supported" in err)

    def test_set(self):
        self.check_true(["image-set", self.filename, self.fcover],
                        False, False)
        self.check_true(["-v", "image-set", self.filename, self.fcover],
                        False, True)

        self.cover.reload()
        images = self.cover.get_images()
        self.assertEqual(len(images), 1)

        with open(self.filename, "rb") as h:
            self.assertEqual(h.read(), images[0].read())

    def test_set_two(self):
        self.check_true(
            ["image-set", self.filename, self.fcover, self.fcover2],
            False, False)

        with open(self.filename, "rb") as h:
            image_data = h.read()

        for audio in [self.cover, self.cover2]:
            audio.reload()
            image = audio.get_images()[0]
            self.assertEqual(image.read(), image_data)
開發者ID:LudoBike,項目名稱:quodlibet,代碼行數:60,代碼來源:test_operon.py

示例3: TOperonImageClear

class TOperonImageClear(TOperonBase):
    # <image-file> <file> [<files>]

    def setUp(self):
        super(TOperonImageClear, self).setUp()
        fd, self.fcover = mkstemp(".wma")
        os.close(fd)
        shutil.copy(os.path.join(DATA_DIR, 'test-2.wma'), self.fcover)
        self.cover = MusicFile(self.fcover)

    def tearDown(self):
        os.unlink(self.fcover)
        super(TOperonImageClear, self).tearDown()

    def test_misc(self):
        self.check_true(["image-clear", "-h"], True, False)
        self.check_true(["image-clear", self.fcover], False, False)
        self.check_false(["image-clear"], False, True)

    def test_not_supported(self):
        path = os.path.join(DATA_DIR, 'test.mid')
        out, err = self.check_false(["image-clear", path], False, True)
        self.assertTrue("supported" in err)

    def test_clear(self):
        images = self.cover.get_images()
        self.assertEqual(len(images), 1)

        self.check_true(["image-clear", self.fcover], False, False)

        self.cover.reload()
        images = self.cover.get_images()
        self.assertEqual(len(images), 0)
開發者ID:Konzertheld,項目名稱:quodlibet,代碼行數:33,代碼來源:test_operon.py

示例4: TOperonImageExtract

class TOperonImageExtract(TOperonBase):
    # [--dry-run] [--primary] [-d <destination>] <file> [<files>]

    def setUp(self):
        super(TOperonImageExtract, self).setUp()

        h, self.fcover = mkstemp(".wma")
        os.close(h)
        shutil.copy(os.path.join(DATA_DIR, 'test-2.wma'), self.fcover)
        self.cover = MusicFile(self.fcover)

    def tearDown(self):
        os.unlink(self.fcover)

        super(TOperonImageExtract, self).tearDown()

    def test_misc(self):
        self.check_true(["image-extract", "-h"], True, False)
        self.check_true(["image-extract", self.f], False, False)
        self.check_true(["image-extract", self.f, self.f2], False, False)
        self.check_false(["image-extract"], False, True)

    def test_extract_all(self):
        target_dir = os.path.dirname(self.fcover)
        self.check_true(["image-extract", "-d", target_dir, self.fcover],
                        False, False)

        self.assertEqual(len(self.cover.get_images()), 1)
        image = self.cover.get_primary_image()

        name = os.path.splitext(os.path.basename(self.fcover))[0]

        expected = "%s-00.%s" % (name, image.extensions[0])
        expected_path = os.path.join(target_dir, expected)

        self.assertTrue(os.path.exists(expected_path))

        with open(expected_path, "rb") as h:
            self.assertEqual(h.read(), image.file.read())

    def test_extract_primary(self):
        target_dir = os.path.dirname(self.fcover)
        self.check_true(
            ["image-extract", "-d", target_dir, "--primary", self.fcover],
            False, False)

        self.assertEqual(len(self.cover.get_images()), 1)
        image = self.cover.get_primary_image()

        name = os.path.splitext(os.path.basename(self.fcover))[0]

        expected = "%s.%s" % (name, image.extensions[0])
        expected_path = os.path.join(target_dir, expected)

        self.assertTrue(os.path.exists(expected_path))

        with open(expected_path, "rb") as h:
            self.assertEqual(h.read(), image.file.read())
開發者ID:Konzertheld,項目名稱:quodlibet,代碼行數:58,代碼來源:test_operon.py

示例5: TAudioFileAllBase

class TAudioFileAllBase(object):

    FILE = None

    def setUp(self):
        fd, filename = mkstemp(os.path.splitext(self.FILE)[-1])
        os.close(fd)
        shutil.copy(self.FILE, filename)
        self.song = MusicFile(filename)
        self.filename = filename

    def tearDown(self):
        try:
            os.remove(self.filename)
        except OSError:
            pass

    def test_clear_images_noent(self):
        os.remove(self.filename)
        self.assertRaises(AudioFileError, self.song.clear_images)

    def test_set_image_noent(self):
        os.remove(self.filename)
        image = EmbeddedImage(None, "image/png")
        self.assertRaises(AudioFileError, self.song.set_image, image)

    def test_get_primary_image_noent(self):
        os.remove(self.filename)
        self.assertTrue(self.song.get_primary_image() is None)

    def test_get_images_noent(self):
        os.remove(self.filename)
        self.assertEqual(self.song.get_images(), [])

    def test_write_noent(self):
        os.remove(self.filename)
        try:
            self.song.write()
        except AudioFileError:
            pass

    def test_load_noent(self):
        os.remove(self.filename)
        self.assertRaises(AudioFileError, type(self.song), self.filename)

    @classmethod
    def create_tests(cls):
        for i, file_ in enumerate(FILES):
            new_type = type(cls.__name__ + str(i),
                            (cls, TestCase), {"FILE": file_})
            assert new_type.__name__ not in globals()
            globals()[new_type.__name__] = new_type
開發者ID:pensadorramm,項目名稱:quodlibet,代碼行數:52,代碼來源:test_formats_all.py

示例6: setUp

    def setUp(self):
        super(TOperonImageExtract, self).setUp()

        h, self.fcover = mkstemp(".wma")
        os.close(h)
        shutil.copy(os.path.join(DATA_DIR, 'test-2.wma'), self.fcover)
        self.cover = MusicFile(self.fcover)
開發者ID:Konzertheld,項目名稱:quodlibet,代碼行數:7,代碼來源:test_operon.py

示例7: TOperonImageSet

class TOperonImageSet(TOperonBase):
    # <image-file> <file> [<files>]

    def setUp(self):
        super(TOperonImageSet, self).setUp()
        from gi.repository import GdkPixbuf

        h, self.filename = mkstemp(".png")
        os.close(h)
        wide = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 150, 10)
        wide.savev(self.filename, "png", [], [])

        h, self.fcover = mkstemp(".wma")
        os.close(h)
        shutil.copy(os.path.join(DATA_DIR, 'test-2.wma'), self.fcover)
        self.cover = MusicFile(self.fcover)

    def tearDown(self):
        os.unlink(self.fcover)
        os.unlink(self.filename)
        super(TOperonImageSet, self).tearDown()

    def test_misc(self):
        self.check_true(["image-set", "-h"], True, False)
        self.check_false(["image-set", self.fcover], False, True)
        self.check_false(["image-set"], False, True)
        self.check_false(["image-set", self.filename], False, True)

    def test_not_supported(self):
        path = os.path.join(DATA_DIR, 'test.mid')
        out, err = self.check_false(
            ["image-set", self.filename, path], False, True)
        self.assertTrue("supported" in err)

    def test_set(self):
        self.check_true(["image-set", self.filename, self.fcover],
                        False, False)
        self.check_true(["-v", "image-set", self.filename, self.fcover],
                        False, True)

        self.cover.reload()
        images = self.cover.get_images()
        self.assertEqual(len(images), 1)

        with open(self.filename, "rb") as h:
            self.assertEqual(h.read(), images[0].file.read())
開發者ID:Konzertheld,項目名稱:quodlibet,代碼行數:46,代碼來源:test_operon.py

示例8: __init__

 def __init__(self, track, pltag=None):
     if isinstance(track, str):
         self.track = MusicFile(track)
     elif isinstance(track, quodlibet.formats._audio.AudioFile):
         self.track = track
     else:
         raise TypeError("track must be either a quodlibet audiofile or a path to a music file.")
     self.pltag = pltag or 'playlist'
開發者ID:DarwinAwardWinner,項目名稱:mkplaylist,代碼行數:8,代碼來源:mkplaylist.py

示例9: setUp

    def setUp(self):
        super(TOperonImageSet, self).setUp()
        from gi.repository import GdkPixbuf

        h, self.filename = mkstemp(".png")
        os.close(h)
        wide = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 150, 10)
        wide.savev(self.filename, "png", [], [])

        self.fcover = get_temp_copy(get_data_path('test-2.wma'))
        self.cover = MusicFile(self.fcover)

        self.fcover2 = get_temp_copy(get_data_path('test-2.wma'))
        self.cover2 = MusicFile(self.fcover2)
開發者ID:LudoBike,項目名稱:quodlibet,代碼行數:14,代碼來源:test_operon.py

示例10: PLTrack

class PLTrack(object):
    '''Extends MusicFile with convenience methods for accessing playlists.'''
    def __init__(self, track, pltag=None):
        if isinstance(track, str):
            self.track = MusicFile(track)
        elif isinstance(track, quodlibet.formats._audio.AudioFile):
            self.track = track
        else:
            raise TypeError("track must be either a quodlibet audiofile or a path to a music file.")
        self.pltag = pltag or 'playlist'

    def get_playlists(self):
        """Get the set of playlists of which this track is a member."""
        playlists = self.track.get(self.pltag)
        if playlists:
            return tuple(playlists.split("\n"))
        else:
            return tuple()
開發者ID:DarwinAwardWinner,項目名稱:mkplaylist,代碼行數:18,代碼來源:mkplaylist.py

示例11: test_reload

 def test_reload(self):
     audio = MusicFile(get_data_path('silence-44-s.mp3'))
     audio["title"] = u"foo"
     audio.reload()
     self.assertNotEqual(audio.get("title"), u"foo")
開發者ID:Muges,項目名稱:quodlibet,代碼行數:5,代碼來源:test_formats__audio.py

示例12: setUp

 def setUp(self):
     super(TOperonImageClear, self).setUp()
     self.fcover = get_temp_copy(os.path.join(DATA_DIR, 'test-2.wma'))
     self.cover = MusicFile(self.fcover)
開發者ID:bernd-wechner,項目名稱:quodlibet,代碼行數:4,代碼來源:test_operon.py

示例13: test_reload_fail

 def test_reload_fail(self):
     audio = MusicFile(os.path.join(DATA_DIR, 'silence-44-s.mp3'))
     audio["title"] = u"foo"
     audio.sanitize(fsnative(u"/dev/null"))
     self.assertRaises(AudioFileError, audio.reload)
     self.assertEqual(audio["title"], u"foo")
開發者ID:pensadorramm,項目名稱:quodlibet,代碼行數:6,代碼來源:test_formats__audio.py

示例14: test_reload

 def test_reload(self):
     audio = MusicFile(os.path.join(DATA_DIR, 'silence-44-s.mp3'))
     audio["title"] = u"foo"
     audio.reload()
     self.assertNotEqual(audio.get("title"), u"foo")
開發者ID:pensadorramm,項目名稱:quodlibet,代碼行數:5,代碼來源:test_formats__audio.py

示例15: setUp

 def setUp(self):
     self.filename = get_temp_copy(self.FILE)
     self.song = MusicFile(self.filename)
開發者ID:LudoBike,項目名稱:quodlibet,代碼行數:3,代碼來源:test_formats_all.py


注:本文中的quodlibet.formats.MusicFile類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。