Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add more logging information on plugins and MPD helper

  • Loading branch information...
commit 0695b3e3ec09110d6a5a6ba1ef0b89d0ae6f97b5 1 parent 3267219
@multani authored
View
8 sonata/lyricwiki.py
@@ -56,11 +56,14 @@ def get_content(page):
try:
addr = 'http://lyrics.wikia.com/index.php?title=%s:%s&action=edit' \
% (self.lyricwiki_format(artist), self.lyricwiki_format(title))
+ self.logger.debug("Searching lyrics for %r from %r using %r",
+ title, artist, addr)
content = get_content(urllib.urlopen(addr))
if content.lower().startswith("#redirect"):
addr = "http://lyrics.wikia.com/index.php?title=%s&action=edit" \
% urllib.quote(content.split("[[")[1].split("]]")[0])
+ self.logger.debug("Redirected to %r", addr)
content = get_content(urllib.urlopen(addr))
lyrics = content.split("<lyrics>")[1].split("</lyrics>")[0].strip()
@@ -68,12 +71,15 @@ def get_content(page):
lyrics = misc.unescape_html(lyrics)
lyrics = misc.wiki_to_html(lyrics)
lyrics = lyrics.decode("utf-8")
+ self.logger.debug("Found lyrics for %r from %r", title, artist)
self.call_back(callback, lyrics=lyrics)
else:
+ self.logger.debug("No lyrics found for %r from %r", title, artist)
error = _("Lyrics not found")
self.call_back(callback, error=error)
except:
- self.logger.exception("Error while fetching the lyrics")
+ self.logger.exception(
+ "Error while fetching the lyrics for %r from %r", title, artist)
error = _("Fetching lyrics failed")
self.call_back(callback, error=error)
View
7 sonata/mpdhelper.py
@@ -67,6 +67,13 @@ def conout(s):
def call(mpdclient, mpd_cmd, *mpd_args):
+
+ # This is potentially called (too) many times. In the cas the logging is not
+ # active, just don't try to do anything at all. This is supposed to save
+ # some performance in the case it is not active.
+ if logger.isEnabledFor(logging.DEBUG):
+ logger.debug("Calling MPD %s%r", mpd_cmd, mpd_args)
+
try:
retval = getattr(mpdclient, mpd_cmd)(*mpd_args)
except Exception, e:
View
6 sonata/rhapsodycovers.py
@@ -1,3 +1,4 @@
+import logging
import os
import urllib
import urllib2
@@ -7,6 +8,7 @@
class RhapsodyCovers(object):
def __init__(self):
+ self.logger = logging.getLogger(__name__)
pluginsystem.plugin_infos.append(BuiltinPlugin(
'rhapsodycovers', "Rhapsody Covers",
"Fetch album covers from Rhapsody.com.",
@@ -26,13 +28,15 @@ def artwork_download_img_to_file(self, progress_callback, artist, album, dest_fi
rhapsody_uri = "http://feeds.rhapsody.com"
url = "%s/%s/%s/data.xml" % (rhapsody_uri, artist, album)
url = self._sanitize_query(url)
+ self.logger.debug("Finding cover from %r", url)
request = urllib2.Request(url)
opener = urllib2.build_opener()
try:
body = opener.open(request).read()
xml = ElementTree.fromstring(body)
imgs = xml.getiterator("img")
- except:
+ except Exception, e:
+ self.logger.error("Unable to find cover from %r: %s", url, e)
return False
imglist = [img.attrib['src'] for img in imgs if img.attrib['src']]
Please sign in to comment.
Something went wrong with that request. Please try again.