From 6889b9ffdc588aae5f1e793aa0844c53257d2d31 Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Tue, 17 Dec 2019 13:43:53 -0500 Subject: [PATCH 01/12] Add `index_tracks' configuration option --- beetsplug/discogs.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 1437c970e..905cc12da 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 From e31695b606b570218dac7b2bf55fd28a2af97544 Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Tue, 17 Dec 2019 15:27:26 -0500 Subject: [PATCH 02/12] Trace hierarchy of index tracks --- beetsplug/discogs.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 905cc12da..eedfde739 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -398,14 +398,23 @@ class DiscogsPlugin(BeetsPlugin): tracks = [] index_tracks = {} index = 0 + divisions, next_divisions = [], [] for track in clean_tracklist: # Only real tracks have `position`. Otherwise, it's an index track. if track['position']: index += 1 + if next_divisions: + divisions += next_divisions + next_divisions.clear() track_info = self.get_track_info(track, index) track_info.track_alt = track['position'] tracks.append(track_info) else: + next_divisions.append(track['title']) + try: + divisions.pop() + except IndexError: + pass index_tracks[index + 1] = track['title'] # Fix up medium and medium_index for each track. Discogs position is From 02e03be93d23a5b3c24a683043daa10d8024fe5d Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Tue, 17 Dec 2019 15:38:54 -0500 Subject: [PATCH 03/12] Incorporate divisions into track titles --- beetsplug/discogs.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index eedfde739..ea3239c21 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -406,7 +406,7 @@ class DiscogsPlugin(BeetsPlugin): if next_divisions: divisions += next_divisions next_divisions.clear() - track_info = self.get_track_info(track, index) + track_info = self.get_track_info(track, index, divisions) track_info.track_alt = track['position'] tracks.append(track_info) else: @@ -549,10 +549,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( From 8805ba28fdc25ad90f29bab4da1f7a72305faa35 Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Tue, 17 Dec 2019 16:33:41 -0500 Subject: [PATCH 04/12] Add comments --- beetsplug/discogs.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index ea3239c21..7e398072b 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -398,12 +398,14 @@ 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 if next_divisions: + # End of a block of index tracks: update the current divisions. divisions += next_divisions next_divisions.clear() track_info = self.get_track_info(track, index, divisions) @@ -411,6 +413,8 @@ class DiscogsPlugin(BeetsPlugin): 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: From 90fb79f40834d219323dcf07284c3177bfae38e6 Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Tue, 17 Dec 2019 16:54:56 -0500 Subject: [PATCH 05/12] Document `index_tracks' option --- docs/plugins/discogs.rst | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/plugins/discogs.rst b/docs/plugins/discogs.rst index 6c16083ee..80be4c8bb 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_track`` 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 --------------- From 67e402bbae1586d035623e818efc895771e27687 Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Tue, 17 Dec 2019 16:57:24 -0500 Subject: [PATCH 06/12] Fix typo in new documentation --- docs/plugins/discogs.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/plugins/discogs.rst b/docs/plugins/discogs.rst index 80be4c8bb..2a7e90439 100644 --- a/docs/plugins/discogs.rst +++ b/docs/plugins/discogs.rst @@ -67,7 +67,7 @@ would result in track names like:: Messiah, Part II: No.22: Chorus- Behold The Lamb Of God Athalia, Act I, Scene I: Sinfonia -whereas with ``index_track`` disabled you'd get:: +whereas with ``index_tracks`` disabled you'd get:: No.1: Sinfony No.22: Chorus- Behold The Lamb Of God From 5f74edf2d9e482ea413a43202e219829e7e6acd7 Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Tue, 17 Dec 2019 17:01:34 -0500 Subject: [PATCH 07/12] One more documentation typo --- docs/plugins/discogs.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/plugins/discogs.rst b/docs/plugins/discogs.rst index 2a7e90439..c199ccf49 100644 --- a/docs/plugins/discogs.rst +++ b/docs/plugins/discogs.rst @@ -52,7 +52,7 @@ 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,:: +or within works. When ``index_tracks`` is enabled:: discogs: index_tracks: yes From 3ccafa24953cde2ec37603ff4fc1a8fff48eb6ee Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Tue, 17 Dec 2019 17:40:16 -0500 Subject: [PATCH 08/12] Fix `str.join' usage --- beetsplug/discogs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 7e398072b..cc2bd67ff 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -559,7 +559,7 @@ class DiscogsPlugin(BeetsPlugin): title = track['title'] if self.config['index_tracks']: prefix = ', '.join(divisions) - title = ': '.join(prefix, title) + title = ': '.join([prefix, title]) track_id = None medium, medium_index, _ = self.get_track_index(track['position']) artist, artist_id = MetadataSourcePlugin.get_artist( From 614289af5f519dfdc8bfb87aaa8d4637b6320762 Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Tue, 17 Dec 2019 17:46:43 -0500 Subject: [PATCH 09/12] Remove use of `list.clear()' for compatibility --- beetsplug/discogs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index cc2bd67ff..6171f8f56 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -407,7 +407,7 @@ class DiscogsPlugin(BeetsPlugin): if next_divisions: # End of a block of index tracks: update the current divisions. divisions += next_divisions - next_divisions.clear() + del next_divisions[:] track_info = self.get_track_info(track, index, divisions) track_info.track_alt = track['position'] tracks.append(track_info) From 6c948764fe684848aca5365781bc7771644d6fcf Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Tue, 17 Dec 2019 17:56:56 -0500 Subject: [PATCH 10/12] Wrap comment lines --- beetsplug/discogs.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 6171f8f56..7abffdf07 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -405,7 +405,8 @@ class DiscogsPlugin(BeetsPlugin): if track['position']: index += 1 if next_divisions: - # End of a block of index tracks: update the current 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) @@ -413,8 +414,8 @@ class DiscogsPlugin(BeetsPlugin): 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). + # We expect new levels of division at the beginning of the + # tracklist (and possibly elsewhere). try: divisions.pop() except IndexError: From e945ed894dada7ecef24f4158cf2672aa5c773f3 Mon Sep 17 00:00:00 2001 From: Cole Miller <53574922+cole-miller@users.noreply.github.com> Date: Wed, 18 Dec 2019 14:31:59 -0500 Subject: [PATCH 11/12] Add trailing comma Co-Authored-By: Adrian Sampson --- beetsplug/discogs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 7abffdf07..0ba27d7dd 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -58,7 +58,7 @@ class DiscogsPlugin(BeetsPlugin): 'source_weight': 0.5, 'user_token': '', 'separator': u', ', - 'index_tracks': False + 'index_tracks': False, }) self.config['apikey'].redact = True self.config['apisecret'].redact = True From 49d9f474a53dc2afceb071dc03e2e4821b887f34 Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Wed, 18 Dec 2019 14:44:57 -0500 Subject: [PATCH 12/12] Update changelog --- docs/changelog.rst | 5 +++++ 1 file changed, 5 insertions(+) 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: