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


Python CoverManager.get_cover_many方法代碼示例

本文整理匯總了Python中quodlibet.util.cover.manager.CoverManager.get_cover_many方法的典型用法代碼示例。如果您正苦於以下問題:Python CoverManager.get_cover_many方法的具體用法?Python CoverManager.get_cover_many怎麽用?Python CoverManager.get_cover_many使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在quodlibet.util.cover.manager.CoverManager的用法示例。


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

示例1: TCoverManagerBuiltin

# 需要導入模塊: from quodlibet.util.cover.manager import CoverManager [as 別名]
# 或者: from quodlibet.util.cover.manager.CoverManager import get_cover_many [as 別名]
class TCoverManagerBuiltin(TestCase):

    def setUp(self):
        config.init()

        self.main = mkdtemp()

        self.dir1 = mkdtemp(dir=self.main)
        self.dir2 = mkdtemp(dir=self.main)

        h, self.cover1 = mkstemp(".png", dir=self.main)
        os.close(h)
        pb = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 10, 10)
        pb.savev(self.cover1, "png", [], [])

        h, self.cover2 = mkstemp(".png", dir=self.main)
        os.close(h)
        pb = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 20, 20)
        pb.savev(self.cover2, "png", [], [])

        fd, self.file1 = mkstemp(".mp3", dir=self.main)
        os.close(fd)
        shutil.copy(os.path.join(DATA_DIR, 'silence-44-s.mp3'), self.file1)

        fd, self.file2 = mkstemp(".mp3", dir=self.main)
        os.close(fd)
        shutil.copy(os.path.join(DATA_DIR, 'silence-44-s.mp3'), self.file2)

        self.manager = CoverManager()

    def tearDown(self):
        shutil.rmtree(self.main)
        config.quit()

    def test_connect_cover_changed(self):

        called_with = []

        def sig_handler(*args):
            called_with.extend(args)

        obj = object()
        self.manager.connect("cover-changed", sig_handler)
        self.manager.cover_changed([obj])

        self.assertEqual(called_with, [self.manager, [obj]])

    def test_get_primary_image(self):
        self.assertFalse(MP3File(self.file1).has_images)
        self.assertFalse(MP3File(self.file1).has_images)

    def test_manager(self):
        self.assertEqual(len(list(self.manager.sources)), 2)

    def test_main(self):
        # embedd one cover, move one to the other dir
        MP3File(self.file1).set_image(EmbeddedImage.from_path(self.cover1))
        os.unlink(self.cover1)
        dest = os.path.join(self.dir2, "cover.png")
        shutil.move(self.cover2, dest)
        self.cover2 = dest

        # move one audio file in each dir
        shutil.move(self.file1, self.dir1)
        self.file1 = os.path.join(self.dir1, os.path.basename(self.file1))
        shutil.move(self.file2, self.dir2)
        self.file2 = os.path.join(self.dir2, os.path.basename(self.file2))

        song1 = MP3File(self.file1)
        song2 = MP3File(self.file2)

        def is_embedded(fileobj):
            return not path_equal(fileobj.name, self.cover2, True)

        # each should find a cover
        self.assertTrue(is_embedded(self.manager.get_cover(song1)))
        self.assertTrue(not is_embedded(self.manager.get_cover(song2)))

        # both settings should search both songs before giving up
        config.set("albumart", "prefer_embedded", True)
        self.assertTrue(
            is_embedded(self.manager.get_cover_many([song1, song2])))
        self.assertTrue(
            is_embedded(self.manager.get_cover_many([song2, song1])))

        config.set("albumart", "prefer_embedded", False)
        self.assertTrue(
            not is_embedded(self.manager.get_cover_many([song1, song2])))
        self.assertTrue(
            not is_embedded(self.manager.get_cover_many([song2, song1])))
開發者ID:bp0,項目名稱:quodlibet,代碼行數:92,代碼來源:test_plugins_cover.py

示例2: TCoverManager

# 需要導入模塊: from quodlibet.util.cover.manager import CoverManager [as 別名]
# 或者: from quodlibet.util.cover.manager.CoverManager import get_cover_many [as 別名]

#.........這裏部分代碼省略.........
        # The glob in the dirname should be ignored, while the
        # glob in the filename/basename is honored
        assert path_equal(
            os.path.abspath(self._find_cover(self.song).name), f)

        self.song['~filename'] = old_song_path

    def test_intelligent(self):
        song = self.song
        song["artist"] = "Q-Man"
        song["title"] = "First Q falls hardest"
        fns = ["Quuxly - back.jpg", "Quuxly.jpg", "q-man - quxxly.jpg",
                  "folder.jpeg", "Q-man - Quuxly (FRONT).jpg"]
        for fn in fns:
            f = self.add_file(fn)
            cover = self._find_cover(song)
            if cover:
                actual = os.path.abspath(cover.name)
                assert path_equal(actual, f)
            else:
                # Here, no cover is better than the back...
                assert path_equal(f, self.full_path("Quuxly - back.jpg"))

    def test_embedded_special_cover_words(self):
        """Tests that words incidentally containing embedded "special" words
        album keywords (e.g. cover, disc, back) don't trigger
        See Issue 818"""

        song = AudioFile({
            "~filename": fsnative(os.path.join(self.dir, u"asong.ogg")),
            "album": "foobar",
            "title": "Ode to Baz",
            "artist": "Q-Man",
        })
        data = [('back.jpg', False),
                ('discovery.jpg', False),
                ("Pharell - frontin'.jpg", False),
                ('nickelback - Curb.jpg', False),
                ('foobar.jpg', True),
                ('folder.jpg', True),  # Though this order is debatable
                ('Q-Man - foobar.jpg', True),
                ('Q-man - foobar (cover).jpg', True)]
        for fn, should_find in data:
            f = self.add_file(fn)
            cover = self._find_cover(song)
            if cover:
                actual = os.path.abspath(cover.name)
                assert path_equal(
                    actual, f, "\"%s\" should trump \"%s\"" % (f, actual))
            else:
                self.failIf(should_find, msg="Couldn't find %s for %s" %
                                             (f, song("~filename")))

    def add_file(self, fn):
        f = self.full_path(fn)
        open(f, "wb").close()
        return f

    def test_multiple_people(self):
        song = AudioFile({
            "~filename": os.path.join(self.dir, "asong.ogg"),
            "album": "foobar",
            "title": "Ode to Baz",
            "performer": "The Performer",
            "artist": "The Composer\nThe Conductor",
            "composer": "The Composer",
        })
        for fn in ["foobar.jpg",
                   "The Performer - foobar.jpg",
                   "The Composer - The Performer - foobar.jpg",
                   "The Composer - The Conductor, The Performer - foobar.jpg"]:
            f = self.add_file(fn)
            cover = self._find_cover(song)
            self.failUnless(cover)
            actual = os.path.abspath(cover.name)
            cover.close()
            assert path_equal(
                actual, f, "\"%s\" should trump \"%s\"" % (f, actual))

    def test_get_thumbnail(self):
        self.assertTrue(self.manager.get_pixbuf(self.song, 10, 10) is None)
        self.assertTrue(
            self.manager.get_pixbuf_many([self.song], 10, 10) is None)

    def test_get_many(self):
        songs = [AudioFile({"~filename": os.path.join(self.dir, "song.ogg"),
                            "title": "Ode to Baz"}),
                 self.an_album_song()]
        plugin = Plugin(ArtworkUrlCover)
        self.manager.plugin_handler.plugin_enable(plugin)
        self.add_file('cover.jpg')
        cover = self.manager.get_cover_many(songs)
        assert cover

    def test_search_missing_artist(self):
        titled_album_song = self.an_album_song('z.ogg')
        titled_album_song["artist"] = "foo"
        album_songs = [self.an_album_song('x.ogg'), titled_album_song,
                       self.an_album_song()]
        self.manager.search_cover(Gio.Cancellable(), album_songs)
開發者ID:LudoBike,項目名稱:quodlibet,代碼行數:104,代碼來源:test_util_cover.py


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