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.
This commit is contained in:
Tai Lee 2013-05-25 01:36:12 +10:00
parent 4c06c96630
commit 835a3c2a73

View file

@ -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: