Permalink
Browse files

PEP8 cleanup

  • Loading branch information...
fossfreedom committed Oct 4, 2015
1 parent ea3c82f commit 00dee49e58beb46bae1d127e4c8bf31be5cdc691
View
@@ -1,4 +1,4 @@
coverart-search-providers v1.2.1
coverart-search-providers v1.2.2-testing
=========================
Drop in Rhythmbox replacement for the default CoverArt Search plugin to provide new and updated coverart search providers both local and by internet image hosts
@@ -52,12 +52,11 @@ v1.1
- fix bug to carry on search after binning poor MusicBrainz image download
- restructure rate-limits to ensure faster downloads whilst keeping to providers rate-limits
v1.2
v1.2.x
- support song-info dialog for Rhythmbox 3.2
- use RB's own embedded art search method as well as mutagen for wider embedded-art coverage
v1.2.1
- bug fix - for locales not found, exit the language installer gracefully
- PEP8 cleanup; remove odd embedded provider duplicate
Recommended order for Search Providers
View
@@ -42,7 +42,6 @@
import rb
from coverart_search_tracks import mutagen_library
ITEMS_PER_NOTIFICATION = 10
IGNORED_SCHEMES = ('http', 'cdda', 'daap', 'mms')
REPEAT_SEARCH_PERIOD = 86400 * 7
@@ -73,7 +72,7 @@ def rate_limit(self, callback_func, args, per_second_rate):
print("rate_limit")
diff = time.time() - self.current_time
if diff < (1.0 / per_second_rate):
#Gdk.threads_add_timeout(GLib.PRIORITY_DEFAULT_IDLE,
# Gdk.threads_add_timeout(GLib.PRIORITY_DEFAULT_IDLE,
# int((1.0 / per_second_rate) *100), delay, None)
time.sleep((1.0 / per_second_rate) - diff)
print("sleeping")
@@ -91,14 +90,14 @@ def __init__(self, store, key, last_time, searches):
self.searches = searches
def next_search(self, continue_search):
'''
"""
main routine that calls the search routine for each search provider
unless one of the searches has found something
outputs - return False means that nothing found
inputs - True means continue with searching
- False means a search routine recommends no more searching
'''
"""
print("next search")
print(continue_search)
@@ -107,7 +106,7 @@ def next_search(self, continue_search):
album = self.key.get_field("album")
if not album:
return False
key = RB.ExtDBKey.create_storage("album", album)
key.add_field("artist", self.key.get_field("artist"))
self.store.store(key, RB.ExtDBSourceType.NONE, None)
@@ -151,7 +150,7 @@ def _enum_dir_cb(self, fileenum, result, results):
try:
files = fileenum.next_files_finish(result)
if files is None or len(files) == 0:
#print "okay, done; got %d files" % len(results)
# print "okay, done; got %d files" % len(results)
self.finished(results)
return
@@ -163,7 +162,7 @@ def _enum_dir_cb(self, fileenum, result, results):
readable = f.get_attribute_boolean("access::can-read")
if ct is not None and ct.startswith("audio/") and readable:
#print "_enum_dir_cb %s " % f.get_name()
# print "_enum_dir_cb %s " % f.get_name()
results.append(f.get_name())
fileenum.next_files_async(ITEMS_PER_NOTIFICATION, GLib.PRIORITY_DEFAULT, None, self._enum_dir_cb, results)
@@ -174,7 +173,6 @@ def _enum_dir_cb(self, fileenum, result, results):
sys.excepthook(*sys.exc_info())
self.finished(results)
def _enum_children_cb(self, parent, result, data):
try:
enumfiles = parent.enumerate_children_finish(result)
@@ -186,7 +184,6 @@ def _enum_children_cb(self, parent, result, data):
sys.excepthook(*sys.exc_info())
self.callback(True)
def search(self, key, last_time, store, callback, args):
# ignore last_time
print("calling search")
@@ -220,7 +217,7 @@ def get_embedded_image(self, search):
if not self.album:
return False
key = RB.ExtDBKey.create_storage("album", self.album)
key.add_field("artist", self.artists[0])
parent = self.file.get_parent()
@@ -241,7 +238,7 @@ def get_embedded_image(self, search):
print("possible flac")
try:
#flac
# flac
module = mutagen_library('')
music = module.File(search)
imagefilename.write(music.pictures[0].data)
@@ -344,7 +341,7 @@ def search(self, key, last_time, store, callback, args):
if album in ("", _("Unknown")):
album = None
if album == None or len(artists) == 0:
if album is None or len(artists) == 0:
callback(True)
return
@@ -406,7 +403,6 @@ def __init__(self):
def search_url(self, artist, album):
# Remove variants of Disc/CD [1-9] from album title before search
orig_album = album
for exp in DISC_NUMBER_REGEXS:
p = re.compile(exp, re.IGNORECASE)
album = p.sub('', album)
@@ -422,7 +418,6 @@ def search_url(self, artist, album):
print("spotify query url = %s" % url)
return url
def album_info_cb(self, data, album_name):
if data is None:
print("spotify query returned nothing")
@@ -474,7 +469,7 @@ def search(self, key, last_time, store, callback, args):
if album in ("", _("Unknown")):
album = None
if album == None or len(artists) == 0:
if album is None or len(artists) == 0:
print("can't search: no useful details")
callback(True)
return
View
@@ -35,7 +35,6 @@
import rb
import rb3compat
gettext.install('rhythmbox', RB.locale_dir())
if rb3compat.PYVER >= 3:
@@ -51,6 +50,7 @@
def file_root(f_name):
return os.path.splitext(f_name)[0].lower()
# this API key belongs to foss.freedom@gmail.com
# and was generated specifically for this use
API_KEY = '844353bce568b93accd9ca47674d6c3e'
@@ -79,14 +79,14 @@ def __init__(self, store, key, last_time, searches):
self.searches = searches
def next_search(self, continue_search):
'''
"""
main routine that calls the search routine for each search provider
unless one of the searches has found something
outputs - return False means that nothing found
inputs - True means continue with searching
- False means a search routine recommends no more searching
'''
"""
if len(self.searches) == 0 and continue_search:
key = RB.ExtDBKey.create_storage("artist", self.key.get_field("artist"))
@@ -110,7 +110,7 @@ def __init__(self):
def search_url(self, artist):
print(("searching for (%s)" % (artist)))
print("searching for (%s)" % (artist))
url = API_URL + "?method=artist.getinfo&"
url = url + "artist=%s&" % (rb3compat.quote_plus(artist))
url = url + "format=json&"
@@ -153,7 +153,7 @@ def artist_info_cb(self, data):
# images tags appear in order of increasing size, and we want the largest. probably.
url = image_urls.pop()
#last check - ensure the size is relatively large to hide false positives
# last check - ensure the size is relatively large to hide false positives
site = rb3compat.urlopen(url)
meta = site.info()
@@ -180,20 +180,20 @@ def search_next(self, artist):
l.get_url(url, self.artist_info_cb)
def search(self, key, last_time, store, callback, args):
#if last_time > (time.time() - REPEAT_SEARCH_PERIOD):
# if last_time > (time.time() - REPEAT_SEARCH_PERIOD):
# print("we already tried this one")
# callback (True)
# return
if user_has_account() == False:
if not user_has_account():
print("can't search: no last.fm account details")
callback(True)
return
artist = key.get_field("artist")
self.key = key
if artist == None:
if artist is None:
print("can't search: no useful details")
callback(True)
return
View
@@ -18,24 +18,19 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
import time
from gi.repository import RB
from gi.repository import GObject
from gi.repository import GdkPixbuf
from gi.repository import Gio
import os
import json
import rb3compat
if rb3compat.PYVER >= 3:
import dbm.gnu as gdbm
else:
import gdbm
import os
import json
class Queue:
def __init__(self):
self.items = []
@@ -54,7 +49,7 @@ def size(self):
class CoverArtExtDB:
'''
"""
This is a simplified version of the RB.ExtDB capability. This
resolves the bugs in the extant capability, primarily around using
signals for none "album-art" databases.
@@ -67,7 +62,7 @@ class CoverArtExtDB:
ported to python3 - this uses the analagous gdbm format.
:param name: `str` name of the external database.
'''
"""
# storage for the instance references
__instances = {}
@@ -84,7 +79,7 @@ class _impl(GObject.Object):
}
# added (ExtDB self, ExtDBKey object, String path, Value pixbuf)
#request (ExtDB self, ExtDBKey object, guint64 last_time)
# request (ExtDB self, ExtDBKey object, guint64 last_time)
_callback = {}
@@ -138,11 +133,11 @@ def _construct_key(self, key):
return keyval
def store(self, key, source_type, data):
'''
"""
:param key: `ExtDBKey`
:param source_type: `ExtDBSourceType`
:param data: `GdkPixbuf.Pixbuf`
'''
"""
print("store")
self.store_uri(key, source_type, data)
@@ -201,23 +196,23 @@ def do_store_request(self, *args):
return False
def store_uri(self, key, source_type, data):
'''
"""
:param key: `ExtDBKey`
:param source_type: `ExtDBSourceType`
:param data: `str` which is a uri
'''
"""
print("store_uri")
self.queue.enqueue((key, source_type, data))
#Gio.io_scheduler_push_job(self.do_store_request, None,
# Gio.io_scheduler_push_job(self.do_store_request, None,
# GLib.PRIORITY_DEFAULT, None)
self.do_store_request()
def lookup(self, key):
'''
"""
:param key: `ExtDBKey`
'''
"""
lookup = self._construct_key(key)
filename = ''
if lookup in self.db:
@@ -227,16 +222,15 @@ def lookup(self, key):
return str(filename)
def request(self, key, callback, user_data):
'''
"""
:param key: `ExtDBKey`
:param callback: `Function` callback
:param user_data: `Value`
where callback is
Function (ExtDBKey key, String filename, GdkPixbuf.Pixbuf data, void* user_data) boolean
'''
"""
lookup = self._construct_key(key)
@@ -276,4 +270,3 @@ def __getattr__(self, attr):
def __setattr__(self, attr, value):
""" Delegate access to implementation """
return setattr(self.__dict__['_CoverArtExtDB__instance'], attr, value)
Oops, something went wrong.

0 comments on commit 00dee49

Please sign in to comment.