diff options
author | jerous <jerous@gmail.com> | 2008-10-31 01:04:21 +0100 |
---|---|---|
committer | jerous <jerous@gmail.com> | 2008-10-31 01:04:21 +0100 |
commit | 02add72c4afae453702a3e2d93d754bc2b7c3464 (patch) | |
tree | 35234942d264c5f72a8ad6989c09ea39f51d5939 | |
parent | 2f08c0d78c80758dcb6c1982e09519d3cb63cc73 (diff) |
AlbumCover: open-file-dialog to select album cover
-rw-r--r-- | plugins/AlbumCover.py | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/plugins/AlbumCover.py b/plugins/AlbumCover.py index 943dceb..09c0baf 100644 --- a/plugins/AlbumCover.py +++ b/plugins/AlbumCover.py @@ -2,6 +2,8 @@ from clPlugin import * from traceback import print_exc from thread import start_new_thread import format +import os +import shutil # FETCH MODES AC_NO_FETCH='0' @@ -24,6 +26,23 @@ class wgAlbumCover(QtGui.QWidget): self.setMinimumSize(64,64) def mousePressEvent(self, event): + if event.button()==QtCore.Qt.RightButton: + song=monty.getCurrentSong() + file=QtGui.QFileDialog.getOpenFileName(self + , "Select album cover for %s - %s"%(song.getArtist(), song.getAlbum()) + , "" + , "Images ("+" ".join(map(lambda ext: "*.%s"%(ext), AC_DEFAULT_GFX_EXTS.split(',')))+")" + ) + if file: + cur=self.getLocalACPath(monty.getCurrentSong(), True) + # remove the previous cover + try: + os.remove(cur) + shutil.copy(file, cur) + except Exception, e: + self.p.normal("failed to set new cover: %s"%(str(e))) + else: + return self.refresh() def getIMG(self): @@ -49,7 +68,8 @@ class wgAlbumCover(QtGui.QWidget): start_new_thread(self.fetchCover, (song,)) def fetchCover(self, song): - # set default cover, in case all else fails! + """Fetch cover (from internet or local dir)""" + # set default cover self.imgLoaded=False self.img.load('gfx/no-cd-cover.png') self.acFormat=format.compile(settings.get('albumcover.downloadto', AC_DEFAULT_DOWNTO)) @@ -61,8 +81,16 @@ class wgAlbumCover(QtGui.QWidget): break self.update() - def getLocalACPath(self, song, probe, covers, exts): + def getLocalACPath(self, song, probe): """Get the local path of an albumcover. If $probe, then try covers*exts for existing file.""" + # fetch gfx extensions + exts=settings.get('albumcover.gfx.ext', AC_DEFAULT_GFX_EXTS).split(',') + exts=map(lambda ext: ext.strip(), exts) + + # fetch cover album titles + covers=settings.get('albumcover.files', AC_DEFAULT_FILES).split(',') + covers=map(lambda title: title.strip(), covers) + params={'music_dir': mpdSettings.get('music_directory'), 'cover':'%s.%s'%(covers[0], exts[0])} if probe: self.p.debug("probing ...") @@ -90,14 +118,6 @@ class wgAlbumCover(QtGui.QWidget): print "wgAlbumCover::fetchCover - invalid source "+str(src) return False - # fetch gfx extensions - exts=settings.get('albumcover.gfx.ext', AC_DEFAULT_GFX_EXTS).split(',') - exts=map(lambda ext: ext.strip(), exts) - - # fetch cover album titles - coverTitles=settings.get('albumcover.files', AC_DEFAULT_FILES).split(',') - coverTitles=map(lambda title: title.strip(), coverTitles) - if src==AC_FETCH_INTERNET: # look on the internetz! try: @@ -112,7 +132,7 @@ class wgAlbumCover(QtGui.QWidget): # read the url, i.e. retrieve image data img=urllib.urlopen(coverURL) # where do we save to? - file=self.getLocalACPath(song, False, coverTitles, exts) + file=self.getLocalACPath(song, False) # open file, and write the read of img! f=open(file,'wb') f.write(img.read()) @@ -126,7 +146,7 @@ class wgAlbumCover(QtGui.QWidget): print_exc() return False - file=self.getLocalACPath(song, True, coverTitles, exts) + file=self.getLocalACPath(song, True) if file: try: self.img.load(file) |