From 21d919fbd0a4f49fce64070ff7214bcb23e242a1 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Fri, 23 Sep 2011 12:37:56 -0700 Subject: [PATCH] share last.fm API key among plugins --- beets/plugins.py | 5 ++++- beetsplug/lastgenre.py | 6 +++--- beetsplug/lastid.py | 10 ++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/beets/plugins.py b/beets/plugins.py index b7982df8c..bcb241024 100755 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -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') diff --git a/beetsplug/lastgenre.py b/beetsplug/lastgenre.py index b8ae806cc..4c6af79b1 100644 --- a/beetsplug/lastgenre.py +++ b/beetsplug/lastgenre.py @@ -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') diff --git a/beetsplug/lastid.py b/beetsplug/lastid.py index 667d2e5ab..4bfffb9eb 100644 --- a/beetsplug/lastid.py +++ b/beetsplug/lastid.py @@ -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: