-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:sampsyo/beets into prompthook
Conflicts: docs/changelog.rst
- Loading branch information
Showing
11 changed files
with
181 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# -*- coding: utf-8 -*- | ||
# This file is part of beets. | ||
# Copyright 2015-2016, Ohm Patel. | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining | ||
# a copy of this software and associated documentation files (the | ||
# "Software"), to deal in the Software without restriction, including | ||
# without limitation the rights to use, copy, modify, merge, publish, | ||
# distribute, sublicense, and/or sell copies of the Software, and to | ||
# permit persons to whom the Software is furnished to do so, subject to | ||
# the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be | ||
# included in all copies or substantial portions of the Software. | ||
|
||
""" Fetch various AcousticBrainz metadata using MBID | ||
""" | ||
from __future__ import (division, absolute_import, print_function, | ||
unicode_literals) | ||
|
||
import requests | ||
|
||
from beets import plugins, ui | ||
|
||
ACOUSTIC_URL = "http://acousticbrainz.org/" | ||
LEVEL = "/high-level" | ||
|
||
|
||
class AcousticPlugin(plugins.BeetsPlugin): | ||
def __init__(self): | ||
super(AcousticPlugin, self).__init__() | ||
|
||
def commands(self): | ||
cmd = ui.Subcommand('acousticbrainz', | ||
help="fetch metadata from AcousticBrainz") | ||
|
||
def func(lib, opts, args): | ||
items = lib.items(ui.decargs(args)) | ||
fetch_info(self._log, items) | ||
|
||
cmd.func = func | ||
return [cmd] | ||
|
||
|
||
def fetch_info(log, items): | ||
"""Currently outputs MBID and corresponding request status code | ||
""" | ||
for item in items: | ||
if item.mb_trackid: | ||
log.info('getting data for: {}', item) | ||
|
||
# Fetch the data from the AB API. | ||
url = generate_url(item.mb_trackid) | ||
log.debug('fetching URL: {}', url) | ||
try: | ||
rs = requests.get(url) | ||
except requests.RequestException as exc: | ||
log.info('request error: {}', exc) | ||
continue | ||
|
||
# Check for missing tracks. | ||
if rs.status_code == 404: | ||
log.info('recording ID {} not found', item.mb_trackid) | ||
continue | ||
|
||
# Parse the JSON response. | ||
try: | ||
data = rs.json() | ||
except ValueError: | ||
log.debug('Invalid Response: {}', rs.text) | ||
|
||
# Get each field and assign it on the item. | ||
item.danceable = get_value( | ||
log, | ||
data, | ||
["highlevel", "danceability", "all", "danceable"], | ||
) | ||
item.mood_happy = get_value( | ||
log, | ||
data, | ||
["highlevel", "mood_happy", "all", "happy"], | ||
) | ||
item.mood_party = get_value( | ||
log, | ||
data, | ||
["highlevel", "mood_party", "all", "party"], | ||
) | ||
|
||
# Store the data. We only update flexible attributes, so we | ||
# don't call `item.try_write()` here. | ||
item.store() | ||
|
||
|
||
def generate_url(mbid): | ||
"""Generates url of AcousticBrainz end point for given MBID | ||
""" | ||
return ACOUSTIC_URL + mbid + LEVEL | ||
|
||
|
||
def get_value(log, data, map_path): | ||
"""Allows traversal of dictionary with cleaner formatting | ||
""" | ||
try: | ||
return reduce(lambda d, k: d[k], map_path, data) | ||
except KeyError: | ||
log.debug('Invalid Path: {}', map_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
AcousticBrainz Plugin | ||
===================== | ||
|
||
The ``acoustricbrainz`` plugin gets acoustic-analysis information from the | ||
`AcousticBrainz`_ project. The spirit is similar to the | ||
:doc:`/plugins/echonest`. | ||
|
||
.. _AcousticBrainz: http://acousticbrainz.org/ | ||
|
||
Enable the ``acousticbrainz`` plugin in your configuration (see :ref:`using-plugins`) and run it by typing:: | ||
|
||
$ beet acousticbrainz [QUERY] | ||
|
||
For all tracks with a MusicBrainz recording ID, the plugin currently sets | ||
these fields: | ||
|
||
* ``danceable``: Predicts how easy the track is to dance to. | ||
* ``mood_happy``: Predicts the probability this track will evoke happiness. | ||
* ``mood_party``: Predicts the probability this track should be played at a | ||
party. | ||
|
||
These three fields are all numbers between 0.0 and 1.0. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters