Guest User

Untitled

a guest
Apr 24th, 2018
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. # savecover - saves Exaile album covers to the location of the music file
  2. # Copyright (C) 2008 slaytanic <slaytanic@gmail.com>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License along
  15. # with this program; if not, write to the Free Software Foundation, Inc.,
  16. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17.  
  18. import gtk
  19. from gettext import gettext as _
  20. import xl.plugins as plugins
  21. from shutil import copyfile
  22. import os
  23.  
  24. PLUGIN_NAME = _("Save Cover")
  25. PLUGIN_AUTHORS = ['slaytanic <slaytanic@gmail.com>']
  26. PLUGIN_VERSION = '0.1.1'
  27. PLUGIN_DESCRIPTION = _("Saves the album cover image to the location of the music file.")
  28. PLUGIN_ENABLED = False
  29.  
  30. b = gtk.Button()
  31. PLUGIN_ICON = b.render_icon(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_MENU)
  32. b.destroy()
  33.  
  34. CONNS = plugins.SignalContainer()
  35.  
  36. def initialize():
  37. """
  38. Called when the plugin is enabled
  39. """
  40. CONNS.connect(APP.player, 'play-track', _play_track)
  41. # CONNS.connect(APP.cover, 'image-changed', _image_changed)
  42. return True
  43.  
  44. def destroy():
  45. """
  46. Called when the plugin is disabled
  47. """
  48. CONNS.disconnect_all()
  49.  
  50. def _play_track(exaile, track):
  51. """
  52. Called when playback on a track starts ("play-track" event)
  53. """
  54.  
  55. cover = exaile.exaile.cover_manager.fetch_cover(track, True)
  56. if "nocover" in cover:
  57. print _("[savecover] No cover available for the current track!")
  58. else:
  59. print _("[savecover] Cover for the current track: %s" % cover)
  60.  
  61. track = track.loc
  62. print _("[savecover] Current track location: %s" % track)
  63.  
  64. if "nocover" in cover:
  65. return False
  66.  
  67. cover_dst = os.path.join(os.path.dirname(track), "folder.jpg")
  68.  
  69. if not os.path.exists(cover_dst):
  70. copyfile(cover, cover_dst)
  71. print _("[savecover] Cover saved: %s" % cover_dst)
  72. return True
  73. else:
  74. print _("[savecover] Cover already present: %s" % cover_dst)
  75. return False
Add Comment
Please, Sign In to add comment