mirror of
https://github.com/beetbox/beets.git
synced 2026-02-20 06:14:22 +01:00
share last.fm API key among plugins
This commit is contained in:
parent
d6431b992e
commit
21d919fbd0
3 changed files with 11 additions and 10 deletions
|
|
@ -1,5 +1,5 @@
|
|||
# This file is part of beets.
|
||||
# Copyright 2010, Adrian Sampson.
|
||||
# Copyright 2011, Adrian Sampson.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
|
|
@ -22,6 +22,9 @@ from collections import defaultdict
|
|||
PLUGIN_NAMESPACE = 'beetsplug'
|
||||
DEFAULT_PLUGINS = []
|
||||
|
||||
# Plugins using the Last.fm API can share the same API key.
|
||||
LASTFM_KEY = '2dc3914abf35f0d9c92d97d8f8e42b43'
|
||||
|
||||
# Global logger.
|
||||
log = logging.getLogger('beets')
|
||||
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@
|
|||
import logging
|
||||
import pylast
|
||||
|
||||
from beets.plugins import BeetsPlugin
|
||||
from beets import plugins
|
||||
|
||||
log = logging.getLogger('beets')
|
||||
LASTFM = pylast.LastFMNetwork(api_key='2dc3914abf35f0d9c92d97d8f8e42b43')
|
||||
LASTFM = pylast.LastFMNetwork(api_key=plugins.LASTFM_KEY)
|
||||
WEIGHT_THRESH = 50
|
||||
|
||||
def _tags_for(obj):
|
||||
|
|
@ -52,7 +52,7 @@ def _tags_to_genre(tags):
|
|||
return None
|
||||
return tags[0].title()
|
||||
|
||||
class LastGenrePlugin(BeetsPlugin):
|
||||
class LastGenrePlugin(plugins.BeetsPlugin):
|
||||
pass
|
||||
|
||||
@LastGenrePlugin.listen('album_imported')
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# This file is part of beets.
|
||||
# Copyright 2010, Adrian Sampson.
|
||||
# Copyright 2011, Adrian Sampson.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
|
|
@ -17,15 +17,13 @@ Requires the pylastfp library.
|
|||
"""
|
||||
|
||||
from __future__ import with_statement
|
||||
from beets.plugins import BeetsPlugin
|
||||
from beets import plugins
|
||||
from beets import autotag
|
||||
from beets.autotag import mb
|
||||
from beets.util import plurality
|
||||
import lastfp
|
||||
import logging
|
||||
|
||||
API_KEY = '2dc3914abf35f0d9c92d97d8f8e42b43'
|
||||
|
||||
# The amplification factor for distances calculated from fingerprinted
|
||||
# data. With this set to 2.0, for instance, "fingerprinted" track titles
|
||||
# will be considered twice as important as track titles from ID3 tags.
|
||||
|
|
@ -45,7 +43,7 @@ def match(path, metadata=None):
|
|||
|
||||
# Actually perform fingerprinting and lookup.
|
||||
try:
|
||||
xml = lastfp.gst_match(API_KEY, path, metadata)
|
||||
xml = lastfp.gst_match(plugins.LASTFM_KEY, path, metadata)
|
||||
matches = lastfp.parse_metadata(xml)
|
||||
except lastfp.FingerprintError:
|
||||
# Fail silently and cache the failure.
|
||||
|
|
@ -76,7 +74,7 @@ def get_cur_artist(items):
|
|||
|
||||
return artist, artist_id
|
||||
|
||||
class LastIdPlugin(BeetsPlugin):
|
||||
class LastIdPlugin(plugins.BeetsPlugin):
|
||||
def track_distance(self, item, info):
|
||||
last_data = match(item.path)
|
||||
if not last_data:
|
||||
|
|
|
|||
Loading…
Reference in a new issue