=== 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-07-26 18:21:10 +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-08-03 17:17:58 +0000 @@ -0,0 +1,133 @@ +# 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 +import gtk + +from xl.trax import search +from xl import event +from xl import settings +from xl import covers +from xl.nls import gettext as _ +import ecprefs + +logger = logging.getLogger(__name__) + +EXPORT_COVERS = None + +def get_preferences_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) + +def disable(exaile): + global EXPORT_COVERS + EXPORT_COVERS.destroy() + EXPORT_COVERS = None + +class Cover(object): + def __init__(self, exaile): + self.exaile = exaile + self.menu_item = gtk.MenuItem(_('Export Covers')) + self.menu_item.connect('activate', self.search_collection) + self.menu_item.set_tooltip_text(_('Export Exaile\'s covers to the collection directory')) + exaile.gui.builder.get_object('tools_menu').append(self.menu_item) + self.menu_item.show() + event.add_callback(self.export_cover, 'cover_set') + + def search_collection(self, menuitem): + """ + Gets all albums in collection and exports the covers to the + collection directory + """ + albums = [x.track for x in search.search_tracks_from_string( + self.exaile.collection, ('! %s==__null__' % 'album'))] + for album in albums: + logger.debug("Export cover: %s", album.get_tag_display('album')) + self.export_cover(None, None, album) + + def export_cover(self, type, player, track): + """ + Searches for cover filename and export it to the collection + """ + key = covers.MANAGER._get_track_key(track) + db_string = covers.MANAGER.db.get(key) + if not db_string: + return + logger.debug("DB_String: %s", db_string) + source, data = db_string.split(":", 1) + if source != 'cache': + return + + src = os.path.join(covers.MANAGER.location, 'cache', data) + if not os.path.exists(src): + return + + format = settings.get_option('plugin/export_covers/image_type', + ecprefs.ImageFormat.default) + logger.debug("Format: %s", format) + 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.get_local_path()), cover_name) + + if not os.path.exists(des): + + if not (settings.get_option('plugin/export_covers/remove_cache', False)): + logger.debug("Copy cover to: %s", des) + shutil.copyfile(src, des) + else: + logger.debug("Move cover to: %s", des) + shutil.move(src, des) + #logger.debug("Update cover database") + #covers.MANAGER.set_cover(track, "localfile:file://"+des) + + else: # convert the image into a specific file format + cover_name = cover_name + '.' + format.lower() + des = os.path.join(os.path.dirname(track.get_local_path()), cover_name) + if not os.path.exists(des): + logger.debug("Copy cover to: %s", des) + logger.debug("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.debug("Remove cover: %s", src) + #os.remove(src) + #logger.debug("Update cover database") + #covers.MANAGER.set_cover(track, "localfile:file://"+des) + + + def destroy(self): + """ + Cleans up + """ + event.remove_callback(self.export_cover, 'cover_set') + self.menu_item.hide() + self.menu_item.destroy() === 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-08-03 17:11:59 +0000 @@ -0,0 +1,23 @@ +import os +from xlgui.preferences 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.Preference): + default = 'cover' + name = 'plugin/export_covers/covername' + +class ImageFormat(widgets.ComboPreference): + default = _("Keep format") + name = 'plugin/export_covers/image_type' + preset_items = [default] + completion_items = [ default, "JPG", "PNG", "BMP", "GIF"] + +#class RemoveCache(widgets.CheckPreference): + #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-08-03 17:12:43 +0000 @@ -0,0 +1,116 @@ + + + + + + + + True + + + True + 3 + 2 + 5 + + + True + 0 + 5 + Cover name: + + + + + True + True + + cover + + + 1 + 2 + + + + + + True + 0 + 5 + Image format: + + + 1 + 2 + + + + + True + format_liststore + + + + 0 + + + + + 1 + 2 + 1 + 2 + + + + + + + + False + False + 0 + + + + + + + + + + + + + Keep format + + + JPG + + + PNG + + + BMP + + + GIF + + + +