Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions beets/autotag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ def apply_metadata(album_info, mapping):
'work',
'mb_workid',
'work_disambig',
'bpm',
'musical_key',
'genre'
)
}

Expand Down
6 changes: 5 additions & 1 deletion beets/autotag/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ def __init__(self, title, track_id, release_track_id=None, artist=None,
disctitle=None, artist_credit=None, data_source=None,
data_url=None, media=None, lyricist=None, composer=None,
composer_sort=None, arranger=None, track_alt=None,
work=None, mb_workid=None, work_disambig=None):
work=None, mb_workid=None, work_disambig=None, bpm=None,
musical_key=None, genre=None):
self.title = title
self.track_id = track_id
self.release_track_id = release_track_id
Expand All @@ -204,6 +205,9 @@ def __init__(self, title, track_id, release_track_id=None, artist=None,
self.work = work
self.mb_workid = mb_workid
self.work_disambig = work_disambig
self.bpm = bpm
self.musical_key = musical_key
self.genre = genre

# As above, work around a bug in python-musicbrainz-ngs.
def decode(self, codec='utf-8'):
Expand Down
13 changes: 12 additions & 1 deletion beetsplug/beatport.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,16 @@ def __init__(self, data):
self.url = "https://beatport.com/track/{0}/{1}" \
.format(data['slug'], data['id'])
self.track_number = data.get('trackNumber')
if 'bpm' in data:
self.bpm = data['bpm']
if 'key' in data:
self.musical_key = six.text_type(data['key'].get('shortName'))

# Use 'subgenre' and if not present, 'genre' as a fallback.
if 'subGenres' in data:
self.genre = six.text_type(data['subGenres'][0].get('name'))
if not self.genre and 'genres' in data:
self.genre = six.text_type(data['genres'][0].get('name'))


class BeatportPlugin(BeetsPlugin):
Expand Down Expand Up @@ -433,7 +443,8 @@ def _get_track_info(self, track):
artist=artist, artist_id=artist_id,
length=length, index=track.track_number,
medium_index=track.track_number,
data_source=u'Beatport', data_url=track.url)
data_source=u'Beatport', data_url=track.url,
bpm=track.bpm, musical_key=track.musical_key)

def _get_artist(self, artists):
"""Returns an artist string (all artists) and an artist_id (the main
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ New features:
you can now match tracks and albums using the `Deezer`_ database.
Thanks to :user:`rhlahuja`.
:bug:`3355`
* :doc:`/plugins/beatport`: The plugin now gets the musical key, BPM and the
genre for each track.
:bug:`2080`

Fixes:

Expand Down Expand Up @@ -136,6 +139,8 @@ For plugin developers:
APIs to provide metadata matches for the importer. Refer to the Spotify and
Deezer plugins for examples of using this template class.
:bug:`3355`
* The autotag hooks have been modified such that they now take 'bpm',
'musical_key' and a per-track based 'genre' as attributes.

For packagers:

Expand Down
15 changes: 10 additions & 5 deletions docs/plugins/beatport.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Beatport Plugin
The ``beatport`` plugin adds support for querying the `Beatport`_ catalogue
during the autotagging process. This can potentially be helpful for users
whose collection includes a lot of diverse electronic music releases, for which
both MusicBrainz and (to a lesser degree) Discogs show no matches.
both MusicBrainz and (to a lesser degree) `Discogs`_ show no matches.

.. _Discogs: https://discogs.com

Installation
------------
Expand All @@ -21,15 +23,18 @@ run the :ref:`import-cmd` command after enabling the plugin, it will ask you
to authorize with Beatport by visiting the site in a browser. On the site
you will be asked to enter your username and password to authorize beets
to query the Beatport API. You will then be displayed with a single line of
text that you should paste into your terminal. This will store the
authentication data for subsequent runs and you will not be required to
repeat the above steps.
text that you should paste as a whole into your terminal. This will store the
authentication data for subsequent runs and you will not be required to repeat
the above steps.

Matches from Beatport should now show up alongside matches
from MusicBrainz and other sources.

If you have a Beatport ID or a URL for a release or track you want to tag, you
can just enter one of the two at the "enter Id" prompt in the importer.
can just enter one of the two at the "enter Id" prompt in the importer. You can
also search for an id like so:

beet import path/to/music/library --search-id id

.. _requests: https://docs.python-requests.org/en/latest/
.. _requests_oauthlib: https://github.com/requests/requests-oauthlib
Expand Down
Loading