Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch non-numeric track indices from MusicBrainz and Discogs #2363

Merged
merged 12 commits into from
Jan 11, 2017
2 changes: 2 additions & 0 deletions beets/autotag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,5 @@ def apply_metadata(album_info, mapping):
item.composer = track_info.composer
if track_info.arranger is not None:
item.arranger = track_info.arranger

item.track_alt = track_info.track_alt
5 changes: 4 additions & 1 deletion beets/autotag/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class TrackInfo(object):
- ``lyricist``: individual track lyricist name
- ``composer``: individual track composer name
- ``arranger`: individual track arranger name
- ``track_alt``: alternative track number (tape, vinyl, etc.)

Only ``title`` and ``track_id`` are required. The rest of the fields
may be None. The indices ``index``, ``medium``, and ``medium_index``
Expand All @@ -154,7 +155,8 @@ def __init__(self, title, track_id, artist=None, artist_id=None,
length=None, index=None, medium=None, medium_index=None,
medium_total=None, artist_sort=None, disctitle=None,
artist_credit=None, data_source=None, data_url=None,
media=None, lyricist=None, composer=None, arranger=None):
media=None, lyricist=None, composer=None, arranger=None,
track_alt=None):
self.title = title
self.track_id = track_id
self.artist = artist
Expand All @@ -173,6 +175,7 @@ def __init__(self, title, track_id, artist=None, artist_id=None,
self.lyricist = lyricist
self.composer = composer
self.arranger = arranger
self.track_alt = track_alt

# As above, work around a bug in python-musicbrainz-ngs.
def decode(self, codec='utf-8'):
Expand Down
1 change: 1 addition & 0 deletions beets/autotag/mb.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def album_info(release):
)
ti.disctitle = disctitle
ti.media = format
ti.track_alt = track['number']

# Prefer track data, where present, over recording data.
if track.get('title'):
Expand Down
4 changes: 3 additions & 1 deletion beetsplug/discogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ def get_tracks(self, tracklist):
# Only real tracks have `position`. Otherwise, it's an index track.
if track['position']:
index += 1
tracks.append(self.get_track_info(track, index))
track_info = self.get_track_info(track, index)
track_info.track_alt = track['position']
tracks.append(track_info)
else:
index_tracks[index + 1] = track['title']

Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ New features:

* Added support for DSF files, once a future version of Mutagen is released
that supports them. Thanks to :user:`docbobo`. :bug:`459` :bug:`2379`
* The MusicBrainz backend and :doc:`/plugins/discogs` now both provide a new
attribute called ``track_alt`` that stores more nuanced, possibly
non-numeric track index data. For example, some vinyl or tape media will
report the side of the record using a letter instead of a number in that
field. :bug:`1831` :bug:`2363`

Fixes:

Expand Down
1 change: 1 addition & 0 deletions test/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,7 @@ def mocked_get_release_by_id(id_, includes=[], release_status=[],
'length': 59,
},
'position': 9,
'number': 'A2'
}],
'position': 5,
}],
Expand Down
3 changes: 3 additions & 0 deletions test/test_mb.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def _make_release(self, date_str='2009', tracks=None, track_length=None,
track = {
'recording': recording,
'position': i + 1,
'number': 'A1',
}
if track_length:
# Track lengths are distinct from recording lengths.
Expand Down Expand Up @@ -182,6 +183,7 @@ def test_parse_medium_numbers_two_mediums(self):
second_track_list = [{
'recording': tracks[1],
'position': '1',
'number': 'A1',
}]
release['medium-list'].append({
'position': '2',
Expand Down Expand Up @@ -454,6 +456,7 @@ def test_match_album(self):
'length': 42,
},
'position': 9,
'number': 'A1',
}],
'position': 5,
}],
Expand Down