Exemplo n.º 1
0
    def setUp(self):
        super(ApplyTest, self).setUp()

        self.items = []
        self.items.append(Item({}))
        self.items.append(Item({}))
        trackinfo = []
        trackinfo.append(
            TrackInfo(
                u'oneNew',
                'dfa939ec-118c-4d0f-84a0-60f3d1e6522c',
                medium=1,
                medium_index=1,
                artist_credit='trackArtistCredit',
                artist_sort='trackArtistSort',
                index=1,
            ))
        trackinfo.append(
            TrackInfo(u'twoNew',
                      '40130ed1-a27c-42fd-a328-1ebefb6caef4',
                      medium=2,
                      medium_index=1,
                      index=2))
        self.info = AlbumInfo(
            tracks=trackinfo,
            artist=u'artistNew',
            album=u'albumNew',
            album_id='7edb51cb-77d6-4416-a23c-3a8c2994a2c7',
            artist_id='a6623d39-2d8e-4f70-8242-0a9553b91e50',
            artist_credit=u'albumArtistCredit',
            artist_sort=u'albumArtistSort',
            albumtype=u'album',
            va=False,
            mediums=2,
        )
Exemplo n.º 2
0
    def setUp(self):
        super(ApplyCompilationTest, self).setUp()

        self.items = []
        self.items.append(Item({}))
        self.items.append(Item({}))
        trackinfo = []
        trackinfo.append(TrackInfo(
            u'oneNew',
            u'dfa939ec-118c-4d0f-84a0-60f3d1e6522c',
            u'artistOneNew',
            u'a05686fc-9db2-4c23-b99e-77f5db3e5282',
            index=1,
        ))
        trackinfo.append(TrackInfo(
            u'twoNew',
            u'40130ed1-a27c-42fd-a328-1ebefb6caef4',
            u'artistTwoNew',
            u'80b3cf5e-18fe-4c59-98c7-e5bb87210710',
            index=2,
        ))
        self.info = AlbumInfo(
            tracks=trackinfo,
            artist=u'variousNew',
            album=u'albumNew',
            album_id='3b69ea40-39b8-487f-8818-04b6eff8c21a',
            artist_id='89ad4ac3-39f7-470e-963a-56509c546377',
            albumtype=u'compilation',
        )
Exemplo n.º 3
0
 def test_order_returns_none_for_extra_tracks(self):
     items = []
     items.append(self.item('one', 1))
     items.append(self.item('two', 2))
     items.append(self.item('three', 3))
     trackinfo = []
     trackinfo.append(TrackInfo('one', None))
     trackinfo.append(TrackInfo('three', None))
     ordered = match.order_items(items, trackinfo)
     self.assertEqual(ordered, None)
Exemplo n.º 4
0
 def test_order_works_with_missing_tracks(self):
     items = []
     items.append(self.item('one', 1))
     items.append(self.item('three', 3))
     trackinfo = []
     trackinfo.append(TrackInfo('one', None))
     trackinfo.append(TrackInfo('two', None))
     trackinfo.append(TrackInfo('three', None))
     ordered = match.order_items(items, trackinfo)
     self.assertEqual(ordered[0].title, 'one')
     self.assertEqual(ordered[1], None)
     self.assertEqual(ordered[2].title, 'three')
Exemplo n.º 5
0
 def test_order_works_with_incomplete_metadata(self):
     items = []
     items.append(self.item('one', 1))
     items.append(self.item('three', 1))
     items.append(self.item('two', 1))
     trackinfo = []
     trackinfo.append(TrackInfo('one', None))
     trackinfo.append(TrackInfo('two', None))
     trackinfo.append(TrackInfo('three', None))
     ordered = match.order_items(items, trackinfo)
     self.assertEqual(ordered[0].title, 'one')
     self.assertEqual(ordered[1].title, 'two')
     self.assertEqual(ordered[2].title, 'three')
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
 def _make_track_match(self, artist, album, number):
     return TrackInfo(
         title=u'Applied Title %d' % number,
         track_id=u'match %d' % number,
         artist=artist,
         length=1
     )
Exemplo n.º 8
0
    def setUp(self):
        super(ImportApplyTest, self).setUp()

        self.libdir = os.path.join(self.temp_dir, 'testlibdir')
        os.mkdir(self.libdir)
        self.libpath = os.path.join(self.temp_dir, 'testlib.blb')
        self.lib = library.Library(self.libpath, self.libdir)
        self.lib.path_formats = [
            ('default', 'one'),
            ('singleton:true', 'three'),
            ('comp:true', 'two'),
        ]
        self.session = _common.import_session(self.lib)

        self.srcdir = os.path.join(self.temp_dir, 'testsrcdir')
        os.mkdir(self.srcdir)
        os.mkdir(os.path.join(self.srcdir, 'testalbum'))
        self.srcpath = os.path.join(self.srcdir, 'testalbum', 'srcfile.mp3')
        shutil.copy(os.path.join(_common.RSRC, 'full.mp3'), self.srcpath)
        self.i = library.Item.from_path(self.srcpath)
        self.i.comp = False

        trackinfo = TrackInfo('one', 'trackid', 'some artist', 'artistid', 1)
        self.info = AlbumInfo(
            artist='some artist',
            album='some album',
            tracks=[trackinfo],
            va=False,
            album_id='albumid',
            artist_id='artistid',
            albumtype='soundtrack',
        )
Exemplo n.º 9
0
    def setUp(self):
        self.libdir = os.path.join(_common.RSRC, 'testlibdir')
        os.mkdir(self.libdir)
        self.lib = library.Library(':memory:', self.libdir)
        self.lib.path_formats = {
            'default': 'one',
            'comp': 'two',
            'singleton': 'three',
        }

        self.srcpath = os.path.join(self.libdir, 'srcfile.mp3')
        shutil.copy(os.path.join(_common.RSRC, 'full.mp3'), self.srcpath)
        self.i = library.Item.from_path(self.srcpath)
        self.i.comp = False

        trackinfo = TrackInfo('one', 'trackid', 'some artist', 'artistid', 1)
        self.info = AlbumInfo(
            artist='some artist',
            album='some album',
            tracks=[trackinfo],
            va=False,
            album_id='albumid',
            artist_id='artistid',
            albumtype='soundtrack',
        )
Exemplo n.º 10
0
    def item_candidates(self, item, artist, album):
        dir = path.dirname(item.path)
        cues = glob.glob(path.join(dir, "*.cue"))
        if not cues:
            return
        if len(cues) > 1:
            self._log.info(u"Found multiple cue files doing nothing: {0}",
                           map(displayable_path, cues))

        cue_file = cues[0]
        self._log.info("Found {} for {}", displayable_path(cue_file), item)

        try:
            # careful: will ask for input in case of conflicts
            command_output(['shnsplit', '-f', cue_file, item.path])
        except (subprocess.CalledProcessError, OSError):
            self._log.exception(u'shnsplit execution failed')
            return

        tracks = glob(path.join(dir, "*.wav"))
        self._log.info("Generated {0} tracks", len(tracks))
        for t in tracks:
            title = "dunno lol"
            track_id = "wtf"
            index = int(path.basename(t)[len("split-track"):-len(".wav")])
            yield TrackInfo(title, track_id, index=index, artist=artist)
Exemplo n.º 11
0
 def test_order_works_with_extra_tracks(self):
     items = []
     items.append(self.item(u'one', 1))
     items.append(self.item(u'two', 2))
     items.append(self.item(u'three', 3))
     trackinfo = []
     trackinfo.append(TrackInfo(u'one', None))
     trackinfo.append(TrackInfo(u'three', None))
     mapping, extra_items, extra_tracks = \
         match.assign_items(items, trackinfo)
     self.assertEqual(extra_items, [items[1]])
     self.assertEqual(extra_tracks, [])
     self.assertEqual(mapping, {
         items[0]: trackinfo[0],
         items[2]: trackinfo[1],
     })
Exemplo n.º 12
0
    def setUp(self):
        self.setup_beets()

        # Original album
        self.add_album_fixture(albumartist=u'artist', album=u'album')

        # Create duplicate through autotagger
        self.match_album_patcher = patch('beets.autotag.mb.match_album')
        self.match_album = self.match_album_patcher.start()
        track_info = TrackInfo(
            title=u'new title',
            track_id=u'trackid',
        )
        album_info = AlbumInfo(
            artist=u'artist',
            album=u'album',
            tracks=[track_info],
            album_id=u'albumid',
            artist_id=u'artistid',
        )
        self.match_album.return_value = iter([album_info])

        # Create import session
        self.importer = self.create_importer()
        config['import']['autotag'] = True
Exemplo n.º 13
0
 def test_order_works_with_missing_tracks(self):
     items = []
     items.append(self.item('one', 1))
     items.append(self.item('three', 3))
     trackinfo = []
     trackinfo.append(TrackInfo(title='one'))
     trackinfo.append(TrackInfo(title='two'))
     trackinfo.append(TrackInfo(title='three'))
     mapping, extra_items, extra_tracks = \
         match.assign_items(items, trackinfo)
     self.assertEqual(extra_items, [])
     self.assertEqual(extra_tracks, [trackinfo[1]])
     self.assertEqual(mapping, {
         items[0]: trackinfo[0],
         items[1]: trackinfo[2],
     })
Exemplo n.º 14
0
 def match_track(self, artist, title):
     yield TrackInfo(
         title     = title.replace('Tag', 'Applied'),
         track_id  = u'trackid',
         artist    = artist.replace('Tag', 'Applied'),
         artist_id = u'artistid',
         length    = 1)
Exemplo n.º 15
0
 def test_reorder_when_track_numbers_incorrect(self):
     items = []
     items.append(self.item(u'one', 1))
     items.append(self.item(u'three', 2))
     items.append(self.item(u'two', 3))
     trackinfo = []
     trackinfo.append(TrackInfo(u'one', None))
     trackinfo.append(TrackInfo(u'two', None))
     trackinfo.append(TrackInfo(u'three', None))
     mapping, extra_items, extra_tracks = \
         match.assign_items(items, trackinfo)
     self.assertEqual(extra_items, [])
     self.assertEqual(extra_tracks, [])
     self.assertEqual(mapping, {
         items[0]: trackinfo[0],
         items[1]: trackinfo[2],
         items[2]: trackinfo[1],
     })
Exemplo n.º 16
0
def _make_trackinfo():
    return [
        TrackInfo(title=u'one',
                  track_id=None,
                  artist=u'some artist',
                  length=1,
                  index=1),
        TrackInfo(title=u'two',
                  track_id=None,
                  artist=u'some artist',
                  length=1,
                  index=2),
        TrackInfo(title=u'three',
                  track_id=None,
                  artist=u'some artist',
                  length=1,
                  index=3),
    ]
Exemplo n.º 17
0
 def setUp(self):
     self.items = []
     self.items.append(Item({}))
     self.items.append(Item({}))
     trackinfo = []
     trackinfo.append(
         TrackInfo('oneNew', 'dfa939ec-118c-4d0f-84a0-60f3d1e6522c'))
     trackinfo.append(
         TrackInfo('twoNew', '40130ed1-a27c-42fd-a328-1ebefb6caef4'))
     self.info = AlbumInfo(
         tracks=trackinfo,
         artist='artistNew',
         album='albumNew',
         album_id='7edb51cb-77d6-4416-a23c-3a8c2994a2c7',
         artist_id='a6623d39-2d8e-4f70-8242-0a9553b91e50',
         albumtype='album',
         va=False,
     )
Exemplo n.º 18
0
 def test_order_works_with_invalid_track_numbers(self):
     items = []
     items.append(self.item(u'one', 1))
     items.append(self.item(u'three', 1))
     items.append(self.item(u'two', 1))
     trackinfo = []
     trackinfo.append(TrackInfo(title=u'one'))
     trackinfo.append(TrackInfo(title=u'two'))
     trackinfo.append(TrackInfo(title=u'three'))
     mapping, extra_items, extra_tracks = \
         match.assign_items(items, trackinfo)
     self.assertEqual(extra_items, [])
     self.assertEqual(extra_tracks, [])
     self.assertEqual(
         mapping, {
             items[0]: trackinfo[0],
             items[1]: trackinfo[2],
             items[2]: trackinfo[1],
         })
Exemplo n.º 19
0
    def _item_task(self, asis, artist=None, title=None, existing=False):
        if existing:
            item = self.i
        else:
            item = _common.item()
        artist = artist or item.artist
        title = title or item.title

        task = importer.ImportTask.item_task(item)
        if asis:
            item.artist = artist
            item.title = title
            task.set_choice(importer.action.ASIS)
        else:
            task.set_choice(TrackMatch(0, TrackInfo(title, None, artist)))
        return task
Exemplo n.º 20
0
    def setUp(self):
        self.setup_beets()

        # Original file in library
        self.add_item_fixture(artist=u'artist', title=u'title',
                              mb_trackid='old trackid')

        # Create duplicate through autotagger
        self.match_track_patcher = patch('beets.autotag.mb.match_track')
        self.match_track = self.match_track_patcher.start()
        track_info = TrackInfo(
            artist=u'artist',
            title=u'title',
            track_id=u'new trackid',
        )
        self.match_track.return_value = iter([track_info])

        # Import session
        self.importer = self.create_importer()
        config['import']['autotag'] = True
        config['import']['singletons'] = True
Exemplo n.º 21
0
    def _get_track(self, track_data):
        """Convert a Deezer track object dict to a TrackInfo object.

        :param track_data: Deezer Track object dict
        :type track_data: dict
        :return: TrackInfo object for track
        :rtype: beets.autotag.hooks.TrackInfo
        """
        artist, artist_id = self.get_artist(
            track_data.get('contributors', [track_data['artist']]))
        return TrackInfo(
            title=track_data['title'],
            track_id=track_data['id'],
            artist=artist,
            artist_id=artist_id,
            length=track_data['duration'],
            index=track_data['track_position'],
            medium=track_data['disk_number'],
            medium_index=track_data['track_position'],
            data_source=self.data_source,
            data_url=track_data['link'],
        )
Exemplo n.º 22
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]))
Exemplo n.º 23
0
def _make_trackinfo():
    ti = []
    ti.append(TrackInfo('one', None, 'some artist', length=1))
    ti.append(TrackInfo('two', None, 'some artist', length=1))
    ti.append(TrackInfo('three', None, 'some artist', length=1))
    return ti
Exemplo n.º 24
0
 def info(index, title, length):
     return TrackInfo(title, None, length=length, index=index)
Exemplo n.º 25
0
 def info(title, length):
     return TrackInfo(title, None, length=length)
Exemplo n.º 26
0
 def tag_item(self, item, **kwargs):
     title = (item.title or '') + ' tag'
     track_info = TrackInfo(title=title, track_id=self.nextid())
     match = TrackMatch(distance=Distance(), info=track_info)
     return [match], Recommendation.strong
Exemplo n.º 27
0
def _make_trackinfo():
    return [
        TrackInfo(u'one', None, u'some artist', length=1, index=1),
        TrackInfo(u'two', None, u'some artist', length=1, index=2),
        TrackInfo(u'three', None, u'some artist', length=1, index=3),
    ]