From 835a3c2a73c41b73081b98d2a1a78d95aea44e96 Mon Sep 17 00:00:00 2001 From: Tai Lee Date: Sat, 25 May 2013 01:36:12 +1000 Subject: [PATCH] Improved parsing of Discogs' `position` field. Some albums have a single disc with positions like I, II, III, IV, etc. Previously beets thought each track on these albums was a new medium. Now we assume that if there is no explicit medium index and the ordinal of an alpha medium does not appear to be sequential (e.g. A, B, C) that the medium is actually the medium index. --- beetsplug/discogs.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 19bc5a5c0..49dc013dd 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -137,7 +137,15 @@ class DiscogsPlugin(BeetsPlugin): medium = None medium_count, index_count = 0, 0 for track in tracks: - if medium != track.medium: + # Handle special case where a different medium does not indicate a + # new disc, when there is no medium_index and the ordinal of medium + # is not sequential. For example, I, II, III, IV, V. Assume these + # are the track index, not the medium. + medium_is_index = track.medium and not track.medium_index and ( + len(track.medium) != 1 or + ord(track.medium) - 64 != medium_count + 1) + + if not medium_is_index and medium != track.medium: # Increment medium_count and reset index_count when medium # changes. medium = track.medium @@ -173,7 +181,9 @@ class DiscogsPlugin(BeetsPlugin): def get_track_index(self, position): """Returns the medium and medium index for a discogs track position. """ - match = re.match(r'^(.*?)(\d*)$', position, re.I) + # medium_index is a number at the end of position. medium is everything + # else. E.g. (A)(1), (Side A, Track )(1), (A)(), ()(1), etc. + match = re.match(r'^(.*?)(\d*)$', position.upper()) if match: medium, index = match.groups() else: