From 4babc40fd8c48f07542542e266699b05cf0bf776 Mon Sep 17 00:00:00 2001 From: Bruno Cauet Date: Thu, 8 Jan 2015 10:39:18 +0100 Subject: [PATCH] Delete useless "config['mypluginname']" mentions Replace with self.config where this is painless. More plugins would benefit from this update but that requires turning functions into methods. --- beetsplug/convert.py | 20 ++++++++++---------- beetsplug/echonest.py | 8 ++++---- beetsplug/embedart.py | 14 +++++++------- beetsplug/fetchart.py | 6 +++--- beetsplug/fuzzy.py | 5 ++--- beetsplug/importadded.py | 5 ++--- beetsplug/importfeeds.py | 12 ++++++------ beetsplug/lyrics.py | 4 ++-- beetsplug/mpdstats.py | 6 +++--- beetsplug/scrub.py | 2 +- 10 files changed, 40 insertions(+), 42 deletions(-) diff --git a/beetsplug/convert.py b/beetsplug/convert.py index 899846e88..baf084423 100644 --- a/beetsplug/convert.py +++ b/beetsplug/convert.py @@ -166,7 +166,7 @@ class ConvertPlugin(BeetsPlugin): Raises `subprocess.CalledProcessError` if the command exited with a non-zero status code. """ - quiet = config['convert']['quiet'].get() + quiet = self.config['quiet'].get() if not quiet and not pretend: self._log.info(u'Encoding {0}', util.displayable_path(source)) @@ -280,7 +280,7 @@ class ConvertPlugin(BeetsPlugin): item.read() item.store() # Store new path and audio data. - if config['convert']['embed']: + if self.config['embed']: album = item.get_album() if album and album.artpath: EmbedCoverArtPlugin().embed_item(item, album.artpath, @@ -336,24 +336,24 @@ class ConvertPlugin(BeetsPlugin): def convert_func(self, lib, opts, args): if not opts.dest: - opts.dest = config['convert']['dest'].get() + opts.dest = self.config['dest'].get() if not opts.dest: raise ui.UserError('no convert destination set') opts.dest = util.bytestring_path(opts.dest) if not opts.threads: - opts.threads = config['convert']['threads'].get(int) + opts.threads = self.config['threads'].get(int) - if config['convert']['paths']: - path_formats = ui.get_path_formats(config['convert']['paths']) + if self.config['paths']: + path_formats = ui.get_path_formats(self.config['paths']) else: path_formats = ui.get_path_formats() if not opts.format: - opts.format = config['convert']['format'].get(unicode).lower() + opts.format = self.config['format'].get(unicode).lower() pretend = opts.pretend if opts.pretend is not None else \ - config['convert']['pretend'].get(bool) + self.config['pretend'].get(bool) if not pretend: ui.commands.list_items(lib, ui.decargs(args), opts.album, None) @@ -364,7 +364,7 @@ class ConvertPlugin(BeetsPlugin): if opts.album: albums = lib.albums(ui.decargs(args)) items = (i for a in albums for i in a.items()) - if config['convert']['copy_album_art']: + if self.config['copy_album_art']: for album in albums: self.copy_album_art(album, opts.dest, path_formats, pretend) @@ -383,7 +383,7 @@ class ConvertPlugin(BeetsPlugin): """Transcode a file automatically after it is imported into the library. """ - format = config['convert']['format'].get(unicode).lower() + format = self.config['format'].get(unicode).lower() if should_transcode(item, format): command, ext = get_format() fd, dest = tempfile.mkstemp('.' + ext) diff --git a/beetsplug/echonest.py b/beetsplug/echonest.py index 8c60de409..a2b24bf20 100644 --- a/beetsplug/echonest.py +++ b/beetsplug/echonest.py @@ -134,7 +134,7 @@ class EchonestMetadataPlugin(plugins.BeetsPlugin): self.config.add(ATTRIBUTES) pyechonest.config.ECHO_NEST_API_KEY = \ - config['echonest']['apikey'].get(unicode) + self.config['apikey'].get(unicode) if self.config['auto']: self.import_stages = [self.imported] @@ -263,13 +263,13 @@ class EchonestMetadataPlugin(plugins.BeetsPlugin): source = item.path tmp = None if item.format not in ALLOWED_FORMATS: - if config['echonest']['convert']: + if self.config['convert']: tmp = source = self.convert(source) if not tmp: return if os.stat(source).st_size > UPLOAD_MAX_SIZE: - if config['echonest']['truncate']: + if self.config['truncate']: source = self.truncate(source) if tmp is not None: util.remove(tmp) @@ -394,7 +394,7 @@ class EchonestMetadataPlugin(plugins.BeetsPlugin): # There are four different ways to get a song. Each method is a # callable that takes the Item as an argument. methods = [self.profile, self.search] - if config['echonest']['upload']: + if self.config['upload']: methods.append(self.analyze) # Try each method in turn. diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index 1fa6b714b..fbed76c26 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -61,9 +61,9 @@ class EmbedCoverArtPlugin(BeetsPlugin): embed_cmd.parser.add_option( '-f', '--file', metavar='PATH', help='the image file to embed' ) - maxwidth = config['embedart']['maxwidth'].get(int) - compare_threshold = config['embedart']['compare_threshold'].get(int) - ifempty = config['embedart']['ifempty'].get(bool) + maxwidth = self.config['maxwidth'].get(int) + compare_threshold = self.config['compare_threshold'].get(int) + ifempty = self.config['ifempty'].get(bool) def embed_func(lib, opts, args): if opts.file: @@ -102,8 +102,8 @@ class EmbedCoverArtPlugin(BeetsPlugin): def album_imported(self, lib, album): """Automatically embed art into imported albums. """ - if album.artpath and config['embedart']['auto']: - max_width = config['embedart']['maxwidth'].get(int) + if album.artpath and self.config['auto']: + max_width = self.config['maxwidth'].get(int) self.embed_album(album, max_width, True) def embed_item(self, item, imagepath, maxwidth=None, itempath=None, @@ -157,8 +157,8 @@ class EmbedCoverArtPlugin(BeetsPlugin): ) for item in album.items(): - thresh = config['embedart']['compare_threshold'].get(int) - ifempty = config['embedart']['ifempty'].get(bool) + thresh = self.config['compare_threshold'].get(int) + ifempty = self.config['ifempty'].get(bool) self.embed_item(item, imagepath, maxwidth, None, thresh, ifempty, as_album=True) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index e17eb929e..d86d942ee 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -329,9 +329,9 @@ class FetchArtPlugin(plugins.BeetsPlugin): out = None # Local art. - cover_names = config['fetchart']['cover_names'].as_str_seq() + cover_names = self.config['cover_names'].as_str_seq() cover_names = map(util.bytestring_path, cover_names) - cautious = config['fetchart']['cautious'].get(bool) + cautious = self.config['cautious'].get(bool) if paths: for path in paths: # FIXME @@ -340,7 +340,7 @@ class FetchArtPlugin(plugins.BeetsPlugin): break # Web art sources. - remote_priority = config['fetchart']['remote_priority'].get(bool) + remote_priority = self.config['remote_priority'].get(bool) if not local_only and (remote_priority or not out): for url in self._source_urls(album): if self.maxwidth: diff --git a/beetsplug/fuzzy.py b/beetsplug/fuzzy.py index fcc59ef5a..789f862b8 100644 --- a/beetsplug/fuzzy.py +++ b/beetsplug/fuzzy.py @@ -17,7 +17,6 @@ from beets.plugins import BeetsPlugin from beets.dbcore.query import StringFieldQuery -import beets import difflib @@ -28,7 +27,7 @@ class FuzzyQuery(StringFieldQuery): if pattern.islower(): val = val.lower() queryMatcher = difflib.SequenceMatcher(None, pattern, val) - threshold = beets.config['fuzzy']['threshold'].as_number() + threshold = self.config['threshold'].as_number() return queryMatcher.quick_ratio() >= threshold @@ -41,5 +40,5 @@ class FuzzyPlugin(BeetsPlugin): }) def queries(self): - prefix = beets.config['fuzzy']['prefix'].get(basestring) + prefix = self.config['prefix'].get(basestring) return {prefix: FuzzyQuery} diff --git a/beetsplug/importadded.py b/beetsplug/importadded.py index 66639d143..b55d67171 100644 --- a/beetsplug/importadded.py +++ b/beetsplug/importadded.py @@ -8,7 +8,6 @@ from __future__ import unicode_literals, absolute_import, print_function import os -from beets import config from beets import util from beets.plugins import BeetsPlugin @@ -100,7 +99,7 @@ class ImportAddedPlugin(BeetsPlugin): mtime = self.item_mtime.pop(item.path, None) if mtime: album_mtimes.append(mtime) - if config['importadded']['preserve_mtimes'].get(bool): + if self.config['preserve_mtimes'].get(bool): self.write_item_mtime(item, mtime) item.store() album.added = min(album_mtimes) @@ -116,7 +115,7 @@ class ImportAddedPlugin(BeetsPlugin): mtime = self.item_mtime.pop(item.path, None) if mtime: item.added = mtime - if config['importadded']['preserve_mtimes'].get(bool): + if self.config['preserve_mtimes'].get(bool): self.write_item_mtime(item, mtime) self._log.debug(u"Import of item '{0}', selected item.added={1}", util.displayable_path(item.path), item.added) diff --git a/beetsplug/importfeeds.py b/beetsplug/importfeeds.py index 86b7ede74..40d036832 100644 --- a/beetsplug/importfeeds.py +++ b/beetsplug/importfeeds.py @@ -94,15 +94,15 @@ class ImportFeedsPlugin(BeetsPlugin): def _record_items(self, lib, basename, items): """Records relative paths to the given items for each feed format """ - feedsdir = bytestring_path(config['importfeeds']['dir'].as_filename()) - formats = config['importfeeds']['formats'].as_str_seq() - relative_to = config['importfeeds']['relative_to'].get() \ - or config['importfeeds']['dir'].as_filename() + feedsdir = bytestring_path(self.config['dir'].as_filename()) + formats = self.config['formats'].as_str_seq() + relative_to = self.config['relative_to'].get() \ + or self.config['dir'].as_filename() relative_to = bytestring_path(relative_to) paths = [] for item in items: - if config['importfeeds']['absolute_path']: + if self.config['absolute_path']: paths.append(item.path) else: try: @@ -115,7 +115,7 @@ class ImportFeedsPlugin(BeetsPlugin): if 'm3u' in formats: basename = bytestring_path( - config['importfeeds']['m3u_name'].get(unicode) + self.config['m3u_name'].get(unicode) ) m3u_path = os.path.join(feedsdir, basename) _write_m3u(m3u_path, paths) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index a85ce3efa..625e8fff1 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -407,8 +407,8 @@ class Google(Backend): def fetch(self, artist, title): query = u"%s %s" % (artist, title) - api_key = config['lyrics']['google_API_key'].get(unicode) - engine_id = config['lyrics']['google_engine_ID'].get(unicode) + api_key = self.config['google_API_key'].get(unicode) + engine_id = self.config['google_engine_ID'].get(unicode) url = u'https://www.googleapis.com/customsearch/v1?key=%s&cx=%s&q=%s' % \ (api_key, engine_id, urllib.quote(query.encode('utf8'))) diff --git a/beetsplug/mpdstats.py b/beetsplug/mpdstats.py index 86206f9df..0b2c8ba9b 100644 --- a/beetsplug/mpdstats.py +++ b/beetsplug/mpdstats.py @@ -57,7 +57,7 @@ class MPDClientWrapper(object): self._log = log self.music_directory = ( - config['mpdstats']['music_directory'].get(unicode)) + self.config['music_directory'].get(unicode)) self.client = MPDClient() @@ -144,8 +144,8 @@ class MPDStats(object): self.lib = lib self._log = log - self.do_rating = config['mpdstats']['rating'].get(bool) - self.rating_mix = config['mpdstats']['rating_mix'].get(float) + self.do_rating = self.config['rating'].get(bool) + self.rating_mix = self.config['rating_mix'].get(float) self.time_threshold = 10.0 # TODO: maybe add config option? self.now_playing = None diff --git a/beetsplug/scrub.py b/beetsplug/scrub.py index 929b3d9ee..64bbcc9b5 100644 --- a/beetsplug/scrub.py +++ b/beetsplug/scrub.py @@ -134,6 +134,6 @@ class ScrubPlugin(BeetsPlugin): def write_item(self, path): """Automatically embed art into imported albums.""" - if not scrubbing and config['scrub']['auto']: + if not scrubbing and self.config['auto']: self._log.debug(u'auto-scrubbing {0}', util.displayable_path(path)) self._scrub(path)