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

AcousticBrainz Plugin #1784

Merged
merged 14 commits into from
Dec 31, 2015
Merged
38 changes: 38 additions & 0 deletions beetsplug/acoustic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from __future__ import (division, absolute_import, print_function,
Copy link
Member

Choose a reason for hiding this comment

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

This will (eventually) need the standard comment header found at the top of all the files in the tree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in 29e6cbe

unicode_literals)


from beets import plugins, ui
import requests

ACOUSTIC_URL = "http://acousticbrainz.org/"
LEVEL = "/high-level"
PLUGIN_DESCRIPTION = "Fetch metadata from AcousticBrainz"
Copy link
Member

Choose a reason for hiding this comment

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

I think most of the help text in beets starts with a lower-case letter.



class AcousticPlugin(plugins.BeetsPlugin):
def __init__(self):
super(AcousticPlugin, self).__init__()

def commands(self):
cmd = ui.Subcommand('acoustic', help=PLUGIN_DESCRIPTION)
Copy link
Member

Choose a reason for hiding this comment

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

The usual way to format long lines like this is to wrap inside the parentheses. For example:

cmd = ui.Subcommand('acoustic',
                    help='...')

or:

cmd = ui.Subcommand(
    'acoustic',
    help='...',
)

rather than using a constant.


def func(lib, opts, args):
fetch_info(lib)

cmd.func = func
return [cmd]


# Currently outputs MBID and corresponding request status code
def fetch_info(lib):
for item in lib.items():
if item.mb_trackid:
r = requests.get(generate_url(item.mb_trackid))
print(item.mb_trackid)
print(r.status_code)
Copy link
Member

Choose a reason for hiding this comment

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

As a hint for the next step, you can get the data from the response with r.json().



# Generates url of AcousticBrainz end point for given MBID
Copy link
Member

Choose a reason for hiding this comment

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

In Python, these per-function (or per-class) comments can actually be docstrings (worth a google). For example:

def generate_url(mbid):
    """Generate the URL of the AcousticBrainz end point for given MBID.
    """
    return ACOUSTIC_URL + mbid + LEVEL

def generate_url(mbid):
return ACOUSTIC_URL + mbid + LEVEL