Ejemplo n.º 1
0
def _call_apply_choice(coro, items, choice, album=True):
    task = importer.ImportTask(None, None, items)
    task.is_album = album
    if not album:
        task.item = items[0]
    task.set_choice(choice)
    coro.send(task)
Ejemplo n.º 2
0
def _call_stages(session,
                 items,
                 choice_or_info,
                 stages=[
                     importer.apply_choices, importer.manipulate_files,
                     importer.finalize
                 ],
                 album=True,
                 toppath=None):
    # Set up the import task.
    task = importer.ImportTask(None, None, items)
    task.is_album = True
    task.toppath = toppath
    if not album:
        task.item = items[0]
    if isinstance(choice_or_info, importer.action):
        task.set_choice(choice_or_info)
    else:
        mapping = dict(zip(items, choice_or_info.tracks))
        task.set_choice(AlbumMatch(0, choice_or_info, mapping, set(), set()))

    # Call the coroutines.
    for stage in stages:
        coro = stage(session)
        coro.next()
        coro.send(task)

    return task
Ejemplo n.º 3
0
def _call_apply(coros, items, info):
    task = importer.ImportTask(None, None, None)
    task.is_album = True
    task.set_choice((info, items))
    if not isinstance(coros, list):
        coros = [coros]
    for coro in coros:
        task = coro.send(task)
Ejemplo n.º 4
0
 def _no_candidates_test(self, result):
     task = importer.ImportTask(
         'toppath',
         'path',
         [_common.item()],
     )
     task.set_match('artist', 'album', [], autotag.RECOMMEND_NONE)
     res = commands.choose_match(task, _common.iconfig(None, quiet=False))
     self.assertEqual(res, result)
     self.assertTrue('No match' in self.io.getoutput())
Ejemplo n.º 5
0
 def _no_candidates_test(self, result):
     task = importer.ImportTask(
         'toppath',
         'path',
         [_common.item()],
     )
     task.set_candidates('artist', 'album', [], autotag.recommendation.none)
     session = _common.import_session(cli=True)
     res = session.choose_match(task)
     self.assertEqual(res, result)
     self.assertTrue('No match' in self.io.getoutput())
Ejemplo n.º 6
0
    def setUp(self):
        i1 = _common.item()
        i2 = _common.item()
        i3 = _common.item()
        i1.title = 'first item'
        i2.title = 'second item'
        i3.title = 'third item'
        i1.comp = i2.comp = i3.comp = False
        i1.albumartist = i2.albumartist = i3.albumartist = ''
        i1.mb_albumartistid = i2.mb_albumartistid = i3.mb_albumartistid = ''
        self.items = [i1, i2, i3]

        self.task = importer.ImportTask(path='a path', toppath='top path',
                                        items=self.items)
        self.task.set_null_candidates()
Ejemplo n.º 7
0
    def setUp(self):
        super(InferAlbumDataTest, self).setUp()

        i1 = _common.item()
        i2 = _common.item()
        i3 = _common.item()
        i1.title = 'first item'
        i2.title = 'second item'
        i3.title = 'third item'
        i1.comp = i2.comp = i3.comp = False
        i1.albumartist = i2.albumartist = i3.albumartist = ''
        i1.mb_albumartistid = i2.mb_albumartistid = i3.mb_albumartistid = ''
        self.items = [i1, i2, i3]

        self.task = importer.ImportTask(paths=['a path'], toppath='top path',
                                        items=self.items)
Ejemplo n.º 8
0
    def _album_task(self, asis, artist=None, album=None, existing=False):
        if existing:
            item = self.i
        else:
            item = _common.item()
        artist = artist or item.albumartist
        album = album or item.album

        task = importer.ImportTask(paths=['a path'], toppath='top path',
                                   items=[item])
        task.set_candidates(artist, album, None, None)
        if asis:
            task.set_choice(importer.action.ASIS)
        else:
            info = AlbumInfo(album, None, artist, None, None)
            task.set_choice(AlbumMatch(0, info, {}, set(), set()))
        return task
Ejemplo n.º 9
0
    def _album_task(self, asis, artist=None, album=None, existing=False):
        if existing:
            item = self.i
        else:
            item = _common.item()
        artist = artist or item.albumartist
        album = album or item.album

        task = importer.ImportTask(path='a path',
                                   toppath='top path',
                                   items=[item])
        task.set_match(artist, album, None, None)
        if asis:
            task.set_choice(importer.action.ASIS)
        else:
            task.set_choice((AlbumInfo(album, None, artist, None,
                                       None), [item]))
        return task
Ejemplo n.º 10
0
    def setUp(self):
        super(ArtImporterTest, self).setUp()

        # Mock the album art fetcher to always return our test file.
        self.art_file = os.path.join(self.temp_dir, 'tmpcover.jpg')
        _common.touch(self.art_file)
        self.old_afa = fetchart.art_for_album
        self.afa_response = self.art_file

        def art_for_album(i, p, maxwidth=None, local_only=False):
            return self.afa_response

        fetchart.art_for_album = art_for_album

        # Test library.
        self.libpath = os.path.join(self.temp_dir, 'tmplib.blb')
        self.libdir = os.path.join(self.temp_dir, 'tmplib')
        os.mkdir(self.libdir)
        os.mkdir(os.path.join(self.libdir, 'album'))
        itempath = os.path.join(self.libdir, 'album', 'test.mp3')
        shutil.copyfile(os.path.join(_common.RSRC, 'full.mp3'), itempath)
        self.lib = library.Library(self.libpath)
        self.i = _common.item()
        self.i.path = itempath
        self.album = self.lib.add_album([self.i])
        self.lib._connection().commit()

        # The plugin and import configuration.
        self.plugin = fetchart.FetchArtPlugin()
        self.session = _common.import_session(self.lib)

        # Import task for the coroutine.
        self.task = importer.ImportTask(None, None, [self.i])
        self.task.is_album = True
        self.task.album = self.album
        info = AlbumInfo(
            album='some album',
            album_id='albumid',
            artist='some artist',
            artist_id='artistid',
            tracks=[],
        )
        self.task.set_choice(AlbumMatch(0, info, {}, set(), set()))
Ejemplo n.º 11
0
    def setUp(self):
        # Mock the album art fetcher to always return our test file.
        self.art_file = os.path.join(_common.RSRC, 'tmpcover.jpg')
        _common.touch(self.art_file)
        self.old_afa = art.art_for_album
        art.art_for_album = lambda a, b: self.art_file

        # Test library.
        self.libpath = os.path.join(_common.RSRC, 'tmplib.blb')
        self.libdir = os.path.join(_common.RSRC, 'tmplib')
        os.mkdir(self.libdir)
        os.mkdir(os.path.join(self.libdir, 'album'))
        itempath = os.path.join(self.libdir, 'album', 'test.mp3')
        shutil.copyfile(os.path.join(_common.RSRC, 'full.mp3'), itempath)
        self.lib = library.Library(self.libpath)
        self.i = _common.item()
        self.i.path = itempath
        self.album = self.lib.add_album([self.i])
        self.lib.save()

        # Set up an art-fetching coroutine.
        self.config = _common.iconfig(self.lib)
        self.config.art = True
        self.coro = importer.fetch_art(self.config)
        self.coro.next()

        # Import task for the coroutine.
        self.task = importer.ImportTask(None, None, [self.i])
        self.task.is_album = True
        self.task.album_id = self.album.id
        info = AlbumInfo(
            album='some album',
            album_id='albumid',
            artist='some artist',
            artist_id='artistid',
            tracks=[TrackInfo('one', 'trackid', 'some artist', 'artistid', 1)],
        )
        self.task.set_choice((info, [self.i]))
Ejemplo n.º 12
0
def match_benchmark(lib, prof, query=None, album_id=None):
    # If no album ID is provided, we'll match against a suitably huge
    # album.
    if not album_id:
        album_id = '9c5c043e-bc69-4edb-81a4-1aaf9c81e6dc'

    # Get an album from the library to use as the source for the match.
    items = lib.albums(query).get().items()

    # Ensure fingerprinting is invoked (if enabled).
    plugins.send('import_task_start',
                 task=importer.ImportTask(None, None, items),
                 session=importer.ImportSession(lib, None, None, None))

    # Run the match.
    def _run_match():
        match.tag_album(items, search_id=album_id)
    if prof:
        cProfile.runctx('_run_match()', {}, {'_run_match': _run_match},
                        'match.prof')
    else:
        interval = timeit.timeit(_run_match, number=1)
        print('match duration:', interval)
Ejemplo n.º 13
0
    def test_hate(self):

        match_pattern = {}
        test_item = Item(
            genre='TestGenre',
            album=u'TestAlbum',
            artist=u'TestArtist')
        task = importer.ImportTask()
        task.items = [test_item]
        task.item = test_item
        task.is_album = False

        # Empty query should let it pass.
        self.assertFalse(IHatePlugin.do_i_hate_this(task, match_pattern))

        # 1 query match.
        match_pattern = ["artist:bad_artist","artist:TestArtist"]
        self.assertTrue(IHatePlugin.do_i_hate_this(task, match_pattern))

        # 2 query matches, either should trigger.
        match_pattern = ["album:test","artist:testartist"]
        self.assertTrue(IHatePlugin.do_i_hate_this(task, match_pattern))

        # Query is blocked by AND clause.
        match_pattern = ["album:notthis genre:testgenre"]
        self.assertFalse(IHatePlugin.do_i_hate_this(task, match_pattern))

        # Both queries are blocked by AND clause with unmatched condition.
        match_pattern = ["album:notthis genre:testgenre",
                         "artist:testartist album:notthis"]
        self.assertFalse(IHatePlugin.do_i_hate_this(task, match_pattern))

        # Only one query should fire.
        match_pattern = ["album:testalbum genre:testgenre",
                         "artist:testartist album:notthis"]
        self.assertTrue(IHatePlugin.do_i_hate_this(task, match_pattern))
Ejemplo n.º 14
0
 def _call_apply_choice(self, coro, items, choice):
     task = importer.ImportTask(None, None, items)
     task.is_album = True
     task.set_choice(choice)
     coro.send(task)
Ejemplo n.º 15
0
 def _call_apply(self, coro, items, info):
     task = importer.ImportTask(None, None, None)
     task.is_album = True
     task.set_choice((info, items))
     coro.send(task)