diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 1437c970e..0ba27d7dd 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -57,7 +57,8 @@ class DiscogsPlugin(BeetsPlugin): '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 @@ -397,14 +398,28 @@ class DiscogsPlugin(BeetsPlugin): 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 @@ -539,10 +554,13 @@ class DiscogsPlugin(BeetsPlugin): 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( diff --git a/docs/changelog.rst b/docs/changelog.rst index b5b6c3901..0608fb06c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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: diff --git a/docs/plugins/discogs.rst b/docs/plugins/discogs.rst index 6c16083ee..c199ccf49 100644 --- a/docs/plugins/discogs.rst +++ b/docs/plugins/discogs.rst @@ -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 +`_), +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 +`_ +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 ---------------