Exemple #1
0
 def _get_artist(self, artists):
     """Returns an artist string (all artists) and an artist_id (the main
     artist) for a list of Beatport release or track artists.
     """
     return MetadataSourcePlugin.get_artist(artists=artists,
                                            id_key=0,
                                            name_key=1)
Exemple #2
0
 def get_track_info(self, track, index):
     """Returns a TrackInfo object for a discogs track.
     """
     title = track['title']
     track_id = None
     medium, medium_index, _ = self.get_track_index(track['position'])
     artist, artist_id = MetadataSourcePlugin.get_artist(
         track.get('artists', [])
     )
     length = self.get_track_length(track['duration'])
     return TrackInfo(title, track_id, artist=artist, artist_id=artist_id,
                      length=length, index=index,
                      medium=medium, medium_index=medium_index,
                      artist_sort=None, disctitle=None, artist_credit=None)
Exemple #3
0
 def get_track_info(self, track, index, divisions):
     """Returns a TrackInfo object for a discogs track.
     """
     title = track['title']
     if self.config['index_tracks']:
         prefix = ', '.join(divisions)
         title = ': '.join([prefix, title])
     track_id = None
     medium, medium_index, _ = self.get_track_index(track['position'])
     artist, artist_id = MetadataSourcePlugin.get_artist(
         track.get('artists', [])
     )
     length = self.get_track_length(track['duration'])
     return TrackInfo(title=title, track_id=track_id, artist=artist,
                      artist_id=artist_id, length=length, index=index,
                      medium=medium, medium_index=medium_index)
Exemple #4
0
 def get_track_info(self, track, index):
     """Returns a TrackInfo object for a discogs track.
     """
     title = track['title']
     track_id = None
     medium, medium_index, _ = self.get_track_index(track['position'])
     artist, artist_id = MetadataSourcePlugin.get_artist(
         track.get('artists', [])
     )
     feats = self.get_feats(track.get('extraartists', []))
     if artist and feats:
         artist = artist + ' feat. ' + feats
     length = self.get_track_length(track['duration'])
     trackinfo = TrackInfo(title, track_id, artist=artist, artist_id=artist_id,
                           length=length, index=index,
                           medium=medium, medium_index=medium_index,
                           artist_sort=None, disctitle=None, artist_credit=None)
     trackinfo.feats = feats
     return trackinfo
Exemple #5
0
    def get_album_info(self, result):
        """Returns an AlbumInfo object for a discogs Release object.
        """
        # Explicitly reload the `Release` fields, as they might not be yet
        # present if the result is from a `discogs_client.search()`.
        if not result.data.get('artists'):
            result.refresh()

        # Sanity check for required fields. The list of required fields is
        # defined at Guideline 1.3.1.a, but in practice some releases might be
        # lacking some of these fields. This function expects at least:
        # `artists` (>0), `title`, `id`, `tracklist` (>0)
        # https://www.discogs.com/help/doc/submission-guidelines-general-rules
        if not all([
                result.data.get(k)
                for k in ['artists', 'title', 'id', 'tracklist']
        ]):
            self._log.warning(u"Release does not contain the required fields")
            return None

        artist, artist_id = MetadataSourcePlugin.get_artist(
            [a.data for a in result.artists])
        album = re.sub(r' +', ' ', result.title)
        album_id = result.data['id']
        # Use `.data` to access the tracklist directly instead of the
        # convenient `.tracklist` property, which will strip out useful artist
        # information and leave us with skeleton `Artist` objects that will
        # each make an API call just to get the same data back.
        tracks = self.get_tracks(result.data['tracklist'])

        # Extract information for the optional AlbumInfo fields, if possible.
        va = result.data['artists'][0].get('name', '').lower() == 'various'
        year = result.data.get('year')
        mediums = [t.medium for t in tracks]
        country = result.data.get('country')
        data_url = result.data.get('uri')
        style = self.format(result.data.get('styles'))
        genre = self.format(result.data.get('genres'))
        discogs_albumid = self.extract_release_id(result.data.get('uri'))

        # Extract information for the optional AlbumInfo fields that are
        # contained on nested discogs fields.
        albumtype = media = label = catalogno = labelid = None
        if result.data.get('formats'):
            albumtype = ', '.join(result.data['formats'][0].get(
                'descriptions', [])) or None
            media = result.data['formats'][0]['name']
        if result.data.get('labels'):
            label = result.data['labels'][0].get('name')
            catalogno = result.data['labels'][0].get('catno')
            labelid = result.data['labels'][0].get('id')

        # Additional cleanups (various artists name, catalog number, media).
        if va:
            artist = config['va_name'].as_str()
        if catalogno == 'none':
            catalogno = None
        # Explicitly set the `media` for the tracks, since it is expected by
        # `autotag.apply_metadata`, and set `medium_total`.
        for track in tracks:
            track.media = media
            track.medium_total = mediums.count(track.medium)
            # Discogs does not have track IDs. Invent our own IDs as proposed
            # in #2336.
            track.track_id = str(album_id) + "-" + track.track_alt

        # Retrieve master release id (returns None if there isn't one).
        master_id = result.data.get('master_id')
        # Assume `original_year` is equal to `year` for releases without
        # a master release, otherwise fetch the master release.
        original_year = self.get_master_year(master_id) if master_id else year

        return AlbumInfo(album=album,
                         album_id=album_id,
                         artist=artist,
                         artist_id=artist_id,
                         tracks=tracks,
                         albumtype=albumtype,
                         va=va,
                         year=year,
                         label=label,
                         mediums=len(set(mediums)),
                         releasegroup_id=master_id,
                         catalognum=catalogno,
                         country=country,
                         style=style,
                         genre=genre,
                         media=media,
                         original_year=original_year,
                         data_source='Discogs',
                         data_url=data_url,
                         discogs_albumid=discogs_albumid,
                         discogs_labelid=labelid,
                         discogs_artistid=artist_id)
Exemple #6
0
 def get_feats(self, extraartists):
     if extraartists:
         feats = [f for f in extraartists if f['role'] == 'Featuring']
         if feats:
             feats, _ = MetadataSourcePlugin.get_artist(feats, id_key='name')
             return feats