=== added directory 'plugins/export_covers' === added file 'plugins/export_covers/PLUGININFO' --- plugins/export_covers/PLUGININFO 1970-01-01 00:00:00 +0000 +++ plugins/export_covers/PLUGININFO 2010-04-03 11:40:32 +0000 @@ -0,0 +1,4 @@ +Version='0.0.1' +Authors=['Johannes Schwarz '] +Name=_('Export Covers') +Description=_('This plugin exports all covers into the collection directory.') === added file 'plugins/export_covers/__init__.py' --- plugins/export_covers/__init__.py 1970-01-01 00:00:00 +0000 +++ plugins/export_covers/__init__.py 2010-04-04 15:19:56 +0000 @@ -0,0 +1,119 @@ +# 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 +import imghdr +import Image +import logging + +from xl.trax import search +from xl import event +from xl import settings +import ecprefs + +logger = logging.getLogger(__name__) + +EXPORT_COVERS = None + +def get_prefs_pane(): + return ecprefs + +def enable(exaile): + if exaile.loading: + event.add_callback(_enable, "exaile_loaded") + else: + _enable(None, exaile, None) + +def _enable(eventname, exaile, nothing): + global EXPORT_COVERS + EXPORT_COVERS = Cover(exaile) + + # if the plugin is enabled first, it will search the whole collection for covers and export them + if (settings.get_option('plugin/export_covers/search_collection', True)): + albums = [x.track for x in search.search_tracks_from_string( + exaile.collection, ('! %s==__null__' % 'album'))] + for album in albums: + logger.info("Export cover: %s", album.get_tag_display('album')) + EXPORT_COVERS.export_cover(None, None, album) + settings.set_option('plugin/export_covers/search_collection', False) + +def disable(exaile): + global EXPORT_COVERS + EXPORT_COVERS.remove() + EXPORT_COVERS = None + +class Cover(object): + def __init__(self, exaile): + self.exaile = exaile + event.add_callback(self.export_cover, 'cover_changed') + + def export_cover(self, type, player, track): + """ + Search for cover filename and export it to the collection + """ + 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': + src = os.path.join(self.exaile.covers.location, 'cache', data) + + if os.path.exists(src): + format = settings.get_option('plugin/export_covers/image_type', + ecprefs.ImageFormat.default) + cover_name = settings.get_option('plugin/move_covers/covername', 'cover') + extension = imghdr.what(src).replace('jpeg', 'jpg') + + if (format == ecprefs.ImageFormat.default or format.lower() == extension): + cover_name = cover_name + '.' + extension + des = os.path.join(os.path.dirname(track.local_file_name()), cover_name) + + if not os.path.exists(des): + + if not (settings.get_option('plugin/export_covers/remove_cache', False)): + logger.info("Copy cover to: %s", des) + shutil.copyfile(src, des) + else: + logger.info("Move cover to: %s", des) + shutil.move(src, des) + self.update_db(track) + else: # convert the image into a specific file format + cover_name = cover_name + '.' + format.lower() + des = os.path.join(os.path.dirname(track.local_file_name()), cover_name) + if not os.path.exists(des): + logger.info("Copy cover to: %s", des) + logger.info("Convert image to %s format", format) + im = Image.open(src) + im.save(des, format.lower()) + if (settings.get_option('plugin/export_covers/remove_cache', False)): + logger.info("Remove cover: %s", src) + os.remove(src) + self.update_db(track) + + def update_db(self, track): + """ + Update the cover db + """ + logger.info("Update cover database") + 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.export_cover, 'cover_changed') === added file 'plugins/export_covers/ecprefs.py' --- plugins/export_covers/ecprefs.py 1970-01-01 00:00:00 +0000 +++ plugins/export_covers/ecprefs.py 2010-04-04 11:30:37 +0000 @@ -0,0 +1,25 @@ +import os +from xlgui.prefs import widgets +from xl import xdg +from xl.nls import gettext as _ + +name = _('Export Covers') +basedir = os.path.dirname(os.path.realpath(__file__)) +ui = os.path.join(basedir, 'export_covers.ui') + + +class CoverName(widgets.PrefsItem): + default = 'cover' + name = 'plugin/export_covers/covername' + +class ImageFormat(widgets.ComboPrefsItem): + default = _("Keep format") + name = 'plugin/export_covers/image_type' + map = [_("Keep format"), "JPG", "PNG", "BMP"] + + def __init__(self, prefs, widget): + widgets.ComboPrefsItem.__init__(self, prefs, widget, use_map=True) + +class RemoveCache(widgets.CheckPrefsItem): + default = False + name = 'plugin/export_covers/remove_cache' === added file 'plugins/export_covers/export_covers.ui' --- plugins/export_covers/export_covers.ui 1970-01-01 00:00:00 +0000 +++ plugins/export_covers/export_covers.ui 2010-04-04 09:38:15 +0000 @@ -0,0 +1,116 @@ + + + + + + + + True + + + True + + + True + 0 + Image format: + + + 5 + 0 + + + + + True + format_liststore + 0 + + + + 0 + + + + + 1 + + + + + False + 5 + 0 + + + + + Remove covers from Exaile's cache + True + True + False + True + + + False + 5 + 1 + + + + + True + + + True + 0 + Cover name: + + + 5 + 0 + + + + + True + True + + + + 1 + + + + + False + 5 + 2 + + + + + + + + + + + + + + + Keep format + + + PNG + + + JPG + + + BMP + + + +