=== added directory 'plugins/move_covers' === added file 'plugins/move_covers/PLUGININFO' --- plugins/move_covers/PLUGININFO 1970-01-01 00:00:00 +0000 +++ plugins/move_covers/PLUGININFO 2010-03-20 16:21:21 +0000 @@ -0,0 +1,4 @@ +Version='0.0.1' +Authors=['Johannes Schwarz '] +Name=_('Move Covers') +Description=_('Plugin to move all downloaded covers to your music directory.') === added file 'plugins/move_covers/__init__.py' --- plugins/move_covers/__init__.py 1970-01-01 00:00:00 +0000 +++ plugins/move_covers/__init__.py 2010-03-20 19:41:50 +0000 @@ -0,0 +1,83 @@ +# Copyright (C) 2010 Johannes Schwarz +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +import shutil +import os.path +import Image + +from xl.trax import search +from xl import event +from xl import settings +import mcprefs + +MOVE_COVERS = None + +def get_prefs_pane(): + return mcprefs + +def enable(exaile): + if exaile.loading: + event.add_callback(_enable, "exaile_loaded") + else: + _enable(None, exaile, None) + +def _enable(eventname, exaile, nothing): + global MOVE_COVERS + MOVE_COVERS = Cover(exaile) + + if (settings.get_option('plugin/move_covers/search_collection', True)): + albums = [x.track for x in search.search_tracks_from_string( + exaile.collection, ('! %s==__null__' % 'album'))] + for album in albums: + MOVE_COVERS.move_cover(None, None, album) + settings.set_option('plugin/move_covers/search_collection', False) + +def disable(exaile): + global MOVE_COVERS + MOVE_COVERS.remove() + MOVE_COVERS = None + +class Cover(object): + def __init__(self, exaile): + self.exaile = exaile + event.add_callback(self.move_cover, 'cover_changed') + + def move_cover(self, type, player, track): + print "move_cover1" + key = self.exaile.covers._get_track_key(track) + db_string = self.exaile.covers.db.get(key) + if db_string: + source, data = db_string.split(":", 1) + if source == 'cache': + print "move_cover2" + src = os.path.join(self.exaile.covers.location, 'cache', data) + + if os.path.exists(src): + print "move_cover3" + #maybe there's a better way to get the image file format + im = Image.open(src) + cover_name = settings.get_option('plugin/move_covers/covername', 'cover') + '.' + im.format.lower() + des = os.path.join(os.path.dirname(track.local_file_name()), cover_name) + + if not os.path.exists(des): + shutil.move(src, des) + # update the db + cover = self.exaile.covers.find_covers(track, limit=1, local_only=True)[0] + data = self.exaile.covers.get_cover_data(cover) + self.exaile.covers.set_cover(track, cover, data) + + def remove(self): + event.remove_callback(self.move_cover, 'cover_changed') === added file 'plugins/move_covers/mcprefs.py' --- plugins/move_covers/mcprefs.py 1970-01-01 00:00:00 +0000 +++ plugins/move_covers/mcprefs.py 2010-03-20 16:55:40 +0000 @@ -0,0 +1,12 @@ +import os +from xlgui.prefs import widgets +from xl import xdg +from xl.nls import gettext as _ + +name = _('Move Covers') +basedir = os.path.dirname(os.path.realpath(__file__)) +ui = os.path.join(basedir, 'move_covers.ui') + +class CoverName(widgets.PrefsItem): + default = 'cover' + name = 'plugin/move_covers/covername' === added file 'plugins/move_covers/move_covers.ui' --- plugins/move_covers/move_covers.ui 1970-01-01 00:00:00 +0000 +++ plugins/move_covers/move_covers.ui 2010-03-20 15:07:09 +0000 @@ -0,0 +1,44 @@ + + + + + + + + True + vertical + + + True + 2 + + + True + 0 + 5 + Cover name: + + + + + True + True + + cover + + + 1 + 2 + + + + + False + False + 0 + + + + + + === modified file 'xl/cover.py' --- xl/cover.py 2010-03-13 20:24:47 +0000 +++ xl/cover.py 2010-03-20 19:42:51 +0000 @@ -239,6 +239,7 @@ if key: self.db[key] = db_string self.__set_save_timeout() + event.log_event("cover_changed", self, track) def remove_cover(self, track): """