Skip to content

Commit

Permalink
Revert Spotify, Discogs changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rhlahuja committed Sep 11, 2019
1 parent 6cfe7ad commit 0b2837d
Show file tree
Hide file tree
Showing 2 changed files with 196 additions and 130 deletions.
50 changes: 28 additions & 22 deletions beetsplug/discogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import beets.ui
from beets import config
from beets.autotag.hooks import AlbumInfo, TrackInfo
from beets.plugins import MetadataSourcePlugin, BeetsPlugin, get_distance
from beets.autotag.hooks import AlbumInfo, TrackInfo, Distance
from beets.plugins import BeetsPlugin
import confuse
from discogs_client import Release, Master, Client
from discogs_client.exceptions import DiscogsAPIError
Expand Down Expand Up @@ -159,20 +159,10 @@ def authenticate(self, c_key, c_secret):
def album_distance(self, items, album_info, mapping):
"""Returns the album distance.
"""
return get_distance(
data_source='Discogs',
info=album_info,
config=self.config
)

def track_distance(self, item, track_info):
"""Returns the track distance.
"""
return get_distance(
data_source='Discogs',
info=track_info,
config=self.config
)
dist = Distance()
if album_info.data_source == 'Discogs':
dist.add('source', self.config['source_weight'].as_number())
return dist

def candidates(self, items, artist, album, va_likely):
"""Returns a list of AlbumInfo objects for discogs search results
Expand Down Expand Up @@ -302,9 +292,7 @@ def get_album_info(self, result):
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]
)
artist, artist_id = self.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
Expand Down Expand Up @@ -380,6 +368,26 @@ def extract_release_id(self, uri):
else:
return None

def get_artist(self, artists):
"""Returns an artist string (all artists) and an artist_id (the main
artist) for a list of discogs album or track artists.
"""
artist_id = None
bits = []
for i, artist in enumerate(artists):
if not artist_id:
artist_id = artist['id']
name = artist['name']
# Strip disambiguation number.
name = re.sub(r' \(\d+\)$', '', name)
# Move articles to the front.
name = re.sub(r'(?i)^(.*?), (a|an|the)$', r'\2 \1', name)
bits.append(name)
if artist['join'] and i < len(artists) - 1:
bits.append(artist['join'])
artist = ' '.join(bits).replace(' ,', ',') or None
return artist, artist_id

def get_tracks(self, tracklist):
"""Returns a list of TrackInfo objects for a discogs tracklist.
"""
Expand Down Expand Up @@ -543,9 +551,7 @@ def get_track_info(self, track, index):
title = track['title']
track_id = None
medium, medium_index, _ = self.get_track_index(track['position'])
artist, artist_id = MetadataSourcePlugin.get_artist(
track.get('artists', [])
)
artist, artist_id = self.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,
Expand Down
Loading

0 comments on commit 0b2837d

Please sign in to comment.