mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 04:55:10 +01:00
Merge pull request #3459 from cole-miller/index-tracks
discogs: Add `index_tracks` option (closes #3458)
This commit is contained in:
commit
a9b19e1678
3 changed files with 53 additions and 3 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
---------------
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue