Skip to content

Commit

Permalink
Merge pull request #3459 from cole-miller/index-tracks
Browse files Browse the repository at this point in the history
discogs: Add `index_tracks` option (closes #3458)
  • Loading branch information
sampsyo committed Dec 18, 2019
2 parents 20630d1 + ea02890 commit a9b19e1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
24 changes: 21 additions & 3 deletions beetsplug/discogs.py
Expand Up @@ -57,7 +57,8 @@ def __init__(self):
'tokenfile': 'discogs_token.json',
'source_weight': 0.5,
'user_token': '',
'separator': u', '
'separator': u', ',
'index_tracks': False,
})
self.config['apikey'].redact = True
self.config['apisecret'].redact = True
Expand Down Expand Up @@ -397,14 +398,28 @@ def get_tracks(self, tracklist):
tracks = []
index_tracks = {}
index = 0
# Distinct works and intra-work divisions, as defined by index tracks.
divisions, next_divisions = [], []
for track in clean_tracklist:
# Only real tracks have `position`. Otherwise, it's an index track.
if track['position']:
index += 1
track_info = self.get_track_info(track, index)
if next_divisions:
# End of a block of index tracks: update the current
# divisions.
divisions += next_divisions
del next_divisions[:]
track_info = self.get_track_info(track, index, divisions)
track_info.track_alt = track['position']
tracks.append(track_info)
else:
next_divisions.append(track['title'])
# We expect new levels of division at the beginning of the
# tracklist (and possibly elsewhere).
try:
divisions.pop()
except IndexError:
pass
index_tracks[index + 1] = track['title']

# Fix up medium and medium_index for each track. Discogs position is
Expand Down Expand Up @@ -539,10 +554,13 @@ def add_merged_subtracks(tracklist, subtracks):

return tracklist

def get_track_info(self, track, index):
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(
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.rst
Expand Up @@ -96,6 +96,11 @@ New features:
HTTPS.
Thanks to :user:`jef`.
:bug:`3449`
* :doc:`/plugins/discogs`: The new ``index_tracks`` option enables
incorporation of work names and intra-work divisions into imported track
titles.
Thanks to :user:`cole-miller`.
:bug:`3459`

Fixes:

Expand Down
27 changes: 27 additions & 0 deletions docs/plugins/discogs.rst
Expand Up @@ -48,6 +48,33 @@ Configuration

This plugin can be configured like other metadata source plugins as described in :ref:`metadata-source-plugin-configuration`.

There is one additional option in the ``discogs:`` section, ``index_tracks``.
Index tracks (see the `Discogs guidelines
<https://support.discogs.com/hc/en-us/articles/360005055373-Database-Guidelines-12-Tracklisting#12.13>`_),
along with headers, mark divisions between distinct works on the same release
or within works. When ``index_tracks`` is enabled::

discogs:
index_tracks: yes

beets will incorporate the names of the divisions containing each track into
the imported track's title. For example, importing
`this album
<https://www.discogs.com/Handel-Sutherland-Kirkby-Kwella-Nelson-Watkinson-Bowman-Rolfe-Johnson-Elliott-Partridge-Thomas-The-A/release/2026070>`_
would result in track names like::

Messiah, Part I: No.1: Sinfony
Messiah, Part II: No.22: Chorus- Behold The Lamb Of God
Athalia, Act I, Scene I: Sinfonia

whereas with ``index_tracks`` disabled you'd get::

No.1: Sinfony
No.22: Chorus- Behold The Lamb Of God
Sinfonia

This option is useful when importing classical music.

Troubleshooting
---------------

Expand Down

0 comments on commit a9b19e1

Please sign in to comment.