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
4 changes: 3 additions & 1 deletion beets/autotag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

def apply_item_metadata(item, track_info):
"""Set an item's metadata from its matched TrackInfo object.
"""
"""
item.artist = track_info.artist
item.artist_sort = track_info.artist_sort
item.artist_credit = track_info.artist_credit
Expand Down 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.alt_track_no = track_info.alt_track_no
4 changes: 3 additions & 1 deletion beets/autotag/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,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,
alt_track_no=None):
self.title = title
self.track_id = track_id
self.artist = artist
Expand All @@ -173,6 +174,7 @@ def __init__(self, title, track_id, artist=None, artist_id=None,
self.lyricist = lyricist
self.composer = composer
self.arranger = arranger
self.alt_track_no = alt_track_no

# As above, work around a bug in python-musicbrainz-ngs.
def decode(self, codec='utf-8'):
Expand Down
5 changes: 3 additions & 2 deletions beets/autotag/mb.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ def album_info(release):
all_tracks = medium['track-list']
if 'pregap' in medium:
all_tracks.insert(0, medium['pregap'])

for track in all_tracks:
for track in all_tracks:
# Basic information from the recording.
index += 1
ti = track_info(
Expand All @@ -265,6 +265,7 @@ def album_info(release):
)
ti.disctitle = disctitle
ti.media = format
ti.alt_track_no = track['number']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To complete my understanding, what does this number field usually hold? Is it typically a number, but sometimes something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding from looking at a handful of XML dumps is that position always holds an integer index of the track and the number holds whatever the user inputted when adding tracks. If you had an album on a double-sided CD, tape, vinyl, etc., then there's the potential of having the number being something like A1, or whatever the case may be.

So it seems to me that simply adding this data should have zero impact with sorting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool; that helps! Thanks for elaborating.


# Prefer track data, where present, over recording data.
if track.get('title'):
Expand Down
7 changes: 4 additions & 3 deletions beets/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def _template_funcs(self):
funcs.update(plugins.template_funcs())
return funcs

def store(self, fields=None):
def store(self, fields=None):
super(LibModel, self).store(fields)
plugins.send('database_change', lib=self._db, model=self)

Expand Down Expand Up @@ -423,9 +423,10 @@ class Item(LibModel):
'month': types.PaddedInt(2),
'day': types.PaddedInt(2),
'track': types.PaddedInt(2),
'alt_track_no': types.STRING,
'tracktotal': types.PaddedInt(2),
'disc': types.PaddedInt(2),
'disctotal': types.PaddedInt(2),
'disctotal': types.PaddedInt(2),
'lyrics': types.STRING,
'comments': types.STRING,
'bpm': types.INTEGER,
Expand Down Expand Up @@ -456,7 +457,7 @@ class Item(LibModel):
'original_year': types.PaddedInt(4),
'original_month': types.PaddedInt(2),
'original_day': types.PaddedInt(2),
'initial_key': MusicalKey(),
'initial_key': MusicalKey(),

'length': DurationType(),
'bitrate': types.ScaledInt(1000, u'kbps'),
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))
ti = self.get_track_info(track, index)
ti.alt_track_no = track['position']
tracks.append(ti)
else:
index_tracks[index + 1] = track['title']

Expand Down