forked from Freso/picard-acousticbrainz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacousticbrainz.py
44 lines (38 loc) · 1.34 KB
/
acousticbrainz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
PLUGIN_NAME = u'AcousticBrainz'
PLUGIN_AUTHOR = u'Andrew Cook'
PLUGIN_DESCRIPTION = u'''Uses AcousticBrainz for mood and genre.'''
PLUGIN_VERSION = "0.0"
PLUGIN_API_VERSIONS = ["0.15"]
from json import loads
from functools import partial
from picard import log
from picard.metadata import register_track_metadata_processor
ACOUSTICBRAINZ_HOST = "acousticbrainz.org"
ACOUSTICBRAINZ_PORT = 80
def result(album, metadata, release, track, data, reply, error):
moods = []
genres = []
bpm = False
try:
data = loads(data)["highlevel"]
for k, v in data.items():
if k.startswith("genre_") and not v["value"].startswith("not_"):
genres.append(v["value"])
if k.startswith("mood_") and not v["value"].startswith("not_"):
moods.append(v["value"])
metadata["genre"] = genres
metadata["moods"] = moods
finally:
album._requests -= 1
album._finalize_loading(None)
def process_track(album, metadata, release, track):
album.tagger.xmlws.download(
ACOUSTICBRAINZ_HOST,
ACOUSTICBRAINZ_PORT,
u"/%s/high-level" % (metadata["musicbrainz_recordingid"]),
partial(result, album, metadata, release, track),
priority=True
)
album._requests += 1
register_track_metadata_processor(process_track)