Example #1
0
    def test_search(self):
        manager = CoverManager(use_built_in=False)
        handler = manager.plugin_handler
        for source in dummy_sources:
            handler.plugin_handle(source)
            handler.plugin_enable(source)
            source.cls.cover_call = False
            source.cls.fetch_call = False

        song = AudioFile({
            "~filename": os.path.join("/tmp/asong.ogg"),
            "album": "Abbey Road",
            "artist": "The Beatles"
        })
        songs = [song]
        results = []

        def done(manager, provider, result):
            self.failUnless(result, msg="Shouldn't succeed with no results")
            results.append(result)

        def finished(manager, songs):
            print("Finished!")

        manager.connect('covers-found', done)
        manager.search_cover(Cancellable(), songs)
        manager.connect('searches-complete', finished)
        run_loop()

        self.failUnlessEqual(len(results), 1)
Example #2
0
    def test_search(self):
        manager = CoverManager(use_built_in=False)
        handler = manager.plugin_handler
        for source in dummy_sources:
            handler.plugin_handle(source)
            handler.plugin_enable(source)
            source.cls.cover_call = False
            source.cls.fetch_call = False

        song = AudioFile({
            "~filename": os.path.join("/tmp/asong.ogg"),
            "album": "Abbey Road",
            "artist": "The Beatles"
        })
        songs = [song]
        results = []

        def done(manager, provider, result):
            self.failUnless(result, msg="Shouldn't succeed with no results")
            results.append(result)

        def finished(manager, songs):
            print("Finished!")

        manager.connect('covers-found', done)
        manager.search_cover(Cancellable(), songs)
        manager.connect('searches-complete', finished)
        run_loop()

        self.failUnlessEqual(len(results), 1)
Example #3
0
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])))
Example #4
0
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])))
Example #5
0
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", [], [])

        self.file1 = get_temp_copy(get_data_path('silence-44-s.mp3'))
        self.file2 = get_temp_copy(get_data_path('silence-44-s.mp3'))

        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_get_cover_many_prefer_embedded(self):
        # embed one cover, move one to the other dir
        MP3File(self.file1).set_image(EmbeddedImage.from_path(self.cover1))
        os.unlink(self.cover1)
        self.external_cover = os.path.join(self.dir2, "cover.png")
        shutil.move(self.cover2, self.external_cover)

        # 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)

        # each should find a cover
        self.failUnless(self.is_embedded(self.manager.get_cover(song1)))
        self.failIf(self.is_embedded(self.manager.get_cover(song2)))

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

        config.set("albumart", "prefer_embedded", False)
        self.failIf(self.is_embedded(cover_for([song1, song2])))
        self.failIf(self.is_embedded(cover_for([song2, song1])))

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

    def test_acquire_prefer_embedded(self):
        # embed one cover...
        MP3File(self.file1).set_image(EmbeddedImage.from_path(self.cover1))
        os.unlink(self.cover1)
        self.external_cover = os.path.join(self.dir1, "cover.png")
        # ...and save a different cover externally
        shutil.copy(self.cover2, self.external_cover)

        shutil.move(self.file1, self.dir1)
        self.file1 = os.path.join(self.dir1, os.path.basename(self.file1))
        both_song = MP3File(self.file1)

        results = []

        def acquire(song):
            def cb(source, result):
                results.append(result)

            self.manager.acquire_cover(cb, None, song)

        def result_was_embedded():
            return self.is_embedded(results.pop())

        config.set("albumart", "prefer_embedded", True)
        acquire(both_song)
        self.failUnless(result_was_embedded(),
                        "Embedded image expected due to prefs")

        config.set("albumart", "prefer_embedded", False)
        acquire(both_song)
        self.failIf(result_was_embedded(),
                    "Got an embedded image despite prefs")
Example #6
0
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", [], [])

        self.file1 = get_temp_copy(get_data_path('silence-44-s.mp3'))
        self.file2 = get_temp_copy(get_data_path('silence-44-s.mp3'))

        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_get_cover_many_prefer_embedded(self):
        # embed one cover, move one to the other dir
        MP3File(self.file1).set_image(EmbeddedImage.from_path(self.cover1))
        os.unlink(self.cover1)
        self.external_cover = os.path.join(self.dir2, "cover.png")
        shutil.move(self.cover2, self.external_cover)

        # 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)

        # each should find a cover
        self.failUnless(self.is_embedded(self.manager.get_cover(song1)))
        self.failIf(self.is_embedded(self.manager.get_cover(song2)))

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

        config.set("albumart", "prefer_embedded", False)
        self.failIf(self.is_embedded(cover_for([song1, song2])))
        self.failIf(self.is_embedded(cover_for([song2, song1])))

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

    def test_acquire_prefer_embedded(self):
        # embed one cover...
        MP3File(self.file1).set_image(EmbeddedImage.from_path(self.cover1))
        os.unlink(self.cover1)
        self.external_cover = os.path.join(self.dir1, "cover.png")
        # ...and save a different cover externally
        shutil.copy(self.cover2, self.external_cover)

        shutil.move(self.file1, self.dir1)
        self.file1 = os.path.join(self.dir1, os.path.basename(self.file1))
        both_song = MP3File(self.file1)

        results = []

        def acquire(song):
            def cb(source, result):
                results.append(result)

            self.manager.acquire_cover(cb, None, song)

        def result_was_embedded():
            return self.is_embedded(results.pop())

        config.set("albumart", "prefer_embedded", True)
        acquire(both_song)
        self.failUnless(result_was_embedded(),
                        "Embedded image expected due to prefs")

        config.set("albumart", "prefer_embedded", False)
        acquire(both_song)
        self.failIf(result_was_embedded(),
                    "Got an embedded image despite prefs")