-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
AcousticBrainz Plugin #1784
Merged
Merged
AcousticBrainz Plugin #1784
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ff81bbf
ABrainz: Added first pass of plugin. Only prints MBID and response st…
opatel99 29e6cbe
ABrainz: Added copyright header, docstrings, and followed long line
opatel99 9daa02b
ABrainz: Added write for three attributes to metadata and easier
opatel99 59a1333
ABrainz: Renamed danceable to dance to match five character attribute
opatel99 ed6d908
ABrainz: Added error catching and renamed to abrainz
opatel99 d15d7ef
ABrainz: Removed repeated portion of error message
opatel99 bcd4c6d
ABrainz: Added initial documentation
opatel99 6183095
ABrainz: Fix slight bugs on Doc page
opatel99 fdd1534
ABrainz: Doc title underline too short
opatel99 ff89716
ABrainz: Add abrainz doc to toctree
opatel99 5201e1c
Rename
opatel99 6337b7f
Rename commands and files
opatel99 fa90393
Update docs
opatel99 ad57943
Updated Copyright Year
opatel99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# -*- coding: utf-8 -*- | ||
# This file is part of beets. | ||
# Copyright 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('abrainz', | ||
help="fetch metadata from AcousticBrainz") | ||
|
||
def func(lib, opts, args): | ||
fetch_info(self, lib) | ||
|
||
cmd.func = func | ||
return [cmd] | ||
|
||
|
||
def fetch_info(self, lib): | ||
"""Currently outputs MBID and corresponding request status code | ||
""" | ||
for item in lib.items(): | ||
if item.mb_trackid: | ||
rs = requests.get(generate_url(item.mb_trackid)) | ||
|
||
try: | ||
rs.json() | ||
except ValueError: | ||
self._log.debug('Invalid Response: {}', rs.text) | ||
|
||
item.danceable = get_value(self._log, rs.json(), ["highlevel", | ||
"danceability", | ||
"all", | ||
"danceable"]) | ||
item.mood_happy = get_value(self._log, rs.json(), ["highlevel", | ||
"mood_happy", | ||
"all", | ||
"happy"]) | ||
item.mood_party = get_value(self._log, rs.json(), ["highlevel", | ||
"mood_party", | ||
"all", | ||
"party"]) | ||
|
||
item.write() | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
ABrainz Plugin | ||
============== | ||
|
||
The ``abrainz`` plugin provides a command that traverses through a library and tags tracks with valid MusicBrainz IDs with additional metadata such as | ||
|
||
* ``danceable`` | ||
+ Predicts how easy the track is danceable to | ||
* ``mood_happy`` | ||
+ Predicts the probability this track is played to invoke happiness | ||
* ``mood_party`` | ||
+ Predicts the probability this track is played in a party environment | ||
|
||
Enable the ``abrainz`` plugin in your configuration (see :ref:`using-plugins`) and run with: | ||
|
||
$ beet abrainz | ||
|
||
Additional command-line options coming soon. |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What timezone are you in again? 😆 Unless you're in Japan or Eastern Australasia, I would assume that judging by the earliest commit here, it should at least be 2015-2016. :)