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
def tag_album(self, items, **kwargs): artist = (items[0].artist or '') + ' tag' album = (items[0].album or '') + ' tag' mapping = {} dist = Distance() dist.tracks = {} for item in items: title = (item.title or '') + ' tag' track_info = TrackInfo(title=title, track_id=self.nextid(), index=1) mapping[item] = track_info dist.tracks[track_info] = Distance() album_info = AlbumInfo(album='album', album_id=self.nextid(), artist='artist', artist_id=self.nextid(), tracks=mapping.values()) match = AlbumMatch(distance=dist, info=album_info, mapping=mapping, extra_items=[], extra_tracks=[]) return artist, album, Proposal([match], Recommendation.strong)
def test_apply_gets_artist_and_id(self): self.task.set_choice(AlbumMatch(0, None, {}, set(), set())) # APPLY self._infer() self.assertEqual(self.items[0].albumartist, self.items[0].artist) self.assertEqual(self.items[0].mb_albumartistid, self.items[0].mb_artistid)
def test_apply_lets_album_values_override(self): for item in self.items: item.albumartist = 'some album artist' item.mb_albumartistid = 'some album artist id' self.task.set_choice(AlbumMatch(0, None, {}, set(), set())) # APPLY self._infer() self.assertEqual(self.items[0].albumartist, 'some album artist') self.assertEqual(self.items[0].mb_albumartistid, 'some album artist id')
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
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()))
def test_first_item_null_apply(self): self.items[0] = None self.task.set_choice(AlbumMatch(0, None, {}, set(), set())) # APPLY self._infer() self.assertFalse(self.items[1].comp) self.assertEqual(self.items[1].albumartist, self.items[2].artist)