From 4c324fae2ab21eef860dea4dc7d6d49b736cfab3 Mon Sep 17 00:00:00 2001 From: Johannes Baiter Date: Wed, 29 Jun 2016 20:34:05 +0200 Subject: [PATCH] beatport: Use track numbers from API (#2091) * beatport: Use trackNumber from API instead of enumerating the tracks * beatport: Set medium_index to track number * Update changelog with fixes to beatport plugin --- beetsplug/beatport.py | 10 +++++----- docs/changelog.rst | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/beetsplug/beatport.py b/beetsplug/beatport.py index f7c52bd38..1ea1aea4e 100644 --- a/beetsplug/beatport.py +++ b/beetsplug/beatport.py @@ -252,6 +252,7 @@ class BeatportTrack(BeatportObject): if 'slug' in data: self.url = "http://beatport.com/track/{0}/{1}".format(data['slug'], data['id']) + self.track_number = data.get('trackNumber') class BeatportPlugin(BeetsPlugin): @@ -406,8 +407,7 @@ class BeatportPlugin(BeetsPlugin): artist, artist_id = self._get_artist(release.artists) if va: artist = u"Various Artists" - tracks = [self._get_track_info(x, index=idx) - for idx, x in enumerate(release.tracks, 1)] + tracks = [self._get_track_info(x) for x in release.tracks] return AlbumInfo(album=release.name, album_id=release.beatport_id, artist=artist, artist_id=artist_id, tracks=tracks, @@ -419,7 +419,7 @@ class BeatportPlugin(BeetsPlugin): catalognum=release.catalog_number, media=u'Digital', data_source=u'Beatport', data_url=release.url) - def _get_track_info(self, track, index=None): + def _get_track_info(self, track): """Returns a TrackInfo object for a Beatport Track object. """ title = track.name @@ -427,10 +427,10 @@ class BeatportPlugin(BeetsPlugin): title += u" ({0})".format(track.mix_name) artist, artist_id = self._get_artist(track.artists) length = track.length.total_seconds() - return TrackInfo(title=title, track_id=track.beatport_id, artist=artist, artist_id=artist_id, - length=length, index=index, + length=length, index=track.track_number, + medium_index=track.track_number, data_source=u'Beatport', data_url=track.url) def _get_artist(self, artists): diff --git a/docs/changelog.rst b/docs/changelog.rst index 6bf4a9681..8ac73257b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -23,6 +23,9 @@ Fixes: * :doc:`/plugins/permissions`: Fix a regression in the previous release where the plugin would always fail to set permissions (and log a warning). :bug:`2089` +* :doc:`/plugins/beatport`: Use track numbers from Beatport (instead of + determining them from the order of tracks) and set the `medium_index` + value. * With :ref:`per_disc_numbering` enabled, some metadata sources (notably, the :doc:`/plugins/beatport`) would not set the track number at all. This is fixed. :bug:`2085`