diff options
author | Anton Khirnov <wyskas@gmail.com> | 2009-05-18 18:23:49 +0200 |
---|---|---|
committer | Anton Khirnov <wyskas@gmail.com> | 2009-05-18 18:23:49 +0200 |
commit | 056b1bb9edc8d48ab157915ccd6757b07401f1ea (patch) | |
tree | ac837633fe3a0399bd46009153b100250a05cebe /nephilim/plugins/AlbumCover.py | |
parent | 9ba0559587b26349997515ac16efef1ef5d0b6b0 (diff) |
AlbumCover: use per-plugin logger.
Diffstat (limited to 'nephilim/plugins/AlbumCover.py')
-rw-r--r-- | nephilim/plugins/AlbumCover.py | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/nephilim/plugins/AlbumCover.py b/nephilim/plugins/AlbumCover.py index feccbe5..9c9746d 100644 --- a/nephilim/plugins/AlbumCover.py +++ b/nephilim/plugins/AlbumCover.py @@ -18,7 +18,6 @@ from PyQt4 import QtGui, QtCore from PyQt4.QtCore import QVariant -import logging import os from ..plugin import Plugin @@ -36,6 +35,8 @@ class wgAlbumCover(QtGui.QLabel): cover_loaded = False "plugin object" plugin = None + "logger" + logger = None _cover_dirname = None # Directory and full filepath where cover _cover_filepath = None # for current song should be stored. @@ -44,6 +45,7 @@ class wgAlbumCover(QtGui.QLabel): def __init__(self, plugin): QtGui.QLabel.__init__(self) self.plugin = plugin + self.logger = plugin.logger self.setAlignment(QtCore.Qt.AlignCenter) # popup menu @@ -84,7 +86,7 @@ class wgAlbumCover(QtGui.QLabel): """Set cover for current song, attempt to write it to a file if write is True and it's globally allowed.""" - logging.info('Setting cover') + self.logger.info('Setting cover') if not cover or cover.isNull(): self.cover = None self.cover_loaded = False @@ -99,14 +101,14 @@ class wgAlbumCover(QtGui.QLabel): self.cover_loaded = True self.setPixmap(self.cover.scaled(self.size(), QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)) self.plugin.emit(QtCore.SIGNAL('cover_changed'), self.cover) - logging.info('Cover set.') + self.logger.info('Cover set.') if (write and self.plugin.settings().value(self.plugin.name() + '/store').toBool() and self._cover_filepath): if self.cover.save(self._cover_filepath, 'png'): - logging.info('Cover saved.') + self.logger.info('Cover saved.') else: - logging.error('Error saving cover.') + self.logger.error('Error saving cover.') class FetchThread(QtCore.QThread): def __init__(self, parent, fetch_func, song): @@ -129,7 +131,7 @@ class wgAlbumCover(QtGui.QLabel): def _fetch_auto(self, song): """Autofetch cover for currently playing song.""" - logging.info("autorefreshing cover") + self.logger.info("autorefreshing cover") # generate filenames (self._cover_dirname, self._cover_filepath) = generate_metadata_path(self.plugin.parent(), song, self.plugin.settings().value(self.plugin.name() + '/coverdir').toString(), @@ -168,7 +170,7 @@ class wgAlbumCover(QtGui.QLabel): self.emit(QtCore.SIGNAL('new_cover_fetched'), song, cover, True) def _fetch_local(self, song): - logging.info('Trying to guess local cover name.') + self.logger.info('Trying to guess local cover name.') # guess cover name covers = ['cover', 'album', 'front'] @@ -183,7 +185,7 @@ class wgAlbumCover(QtGui.QLabel): dir = QtCore.QDir(self._cover_dirname) if not dir: - logging.warning('Error opening directory' + self._cover_dirname) + self.logger.error('Error opening directory' + self._cover_dirname) return None dir.setNameFilters(filter) @@ -191,7 +193,7 @@ class wgAlbumCover(QtGui.QLabel): if files: cover = QtGui.QImage(dir.filePath(files[0])) if not cover.isNull(): - logging.info('Found a cover.') + self.logger.info('Found a cover.') return cover # if this failed, try any supported image @@ -199,7 +201,7 @@ class wgAlbumCover(QtGui.QLabel): files = dir.entryList() if files: return QtGui.QImage(dir.filePath(files[0])) - logging.info('No matching cover found') + self.logger.info('No matching cover found') return None def _fetch_amazon_manual(self, song): @@ -213,9 +215,9 @@ class wgAlbumCover(QtGui.QLabel): return None # get the url from amazon WS coverURL = AmazonAlbumImage(song.artist(), song.album()).fetch() - logging.info("fetching from Amazon") + self.logger.info('Fetching cover from Amazon') if not coverURL: - logging.info("not found on Amazon") + self.logger.info('Cover not found on Amazon') return None img = urllib.urlopen(coverURL) @@ -239,7 +241,7 @@ class wgAlbumCover(QtGui.QLabel): file = QtGui.QFileDialog.getSaveFileName(None, '', os.path.expanduser('~')) if file: if not cover.save(file): - logging.error('Saving cover failed.') + self.logger.error('Saving cover failed.') class AlbumCover(Plugin): o = None @@ -253,8 +255,8 @@ class AlbumCover(Plugin): def info(self): return "Display the album cover of the currently playing album." - def refresh(self, params = None): - self.o.refresh() + def refresh(self): + self.o.refresh() if self.o else self.logger.warning('Attemped to refresh when not loaded.') def cover(self): if not self.o: @@ -348,7 +350,7 @@ class AmazonAlbumImage(object): try: prod_data = urllib.urlopen(url).read() except: - logging.warning('timeout opening %s'%(url)) + self.logger.warning('timeout opening %s'%(url)) return None m = img_re.search(prod_data) if not m: |