diff --git a/beetsplug/freedesktop.py b/beetsplug/freedesktop.py new file mode 100644 index 000000000..732bea544 --- /dev/null +++ b/beetsplug/freedesktop.py @@ -0,0 +1,78 @@ +# This file is part of beets. +# Copyright 2014, Matt Lichtenberg. +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. + +"""Creates freedesktop.org-compliant .directory files on an album level. +""" + +from beets.plugins import BeetsPlugin +from beets.ui import Subcommand + +from beets.ui import decargs + +from beets import config + +import os.path +import logging + +log = logging.getLogger('beets.freedesktop') + +freedesktop_command = Subcommand("freedesktop", help="Create .directory files") + + +def process_query(lib, opts, args): + for album in lib.albums(decargs(args)): + process_album(album) + + +def process_album(album): + albumpath = album.item_dir() + if album.artpath: + fullartpath = album.artpath + artfile = os.path.split(fullartpath)[1] + create_file(albumpath, artfile) + else: + log.debug(u'freedesktop: album has no art') + + +def create_file(albumpath, artfile): + file_contents = "[Desktop Entry]\nIcon=./" + artfile + outfilename = os.path.join(albumpath, ".directory") + + if not os.path.exists(outfilename): + file = open(outfilename, 'w') + file.write(file_contents) + file.close() + pass + + +freedesktop_command.func = process_query + + +class FreedesktopPlugin(BeetsPlugin): + def __init__(self): + super(FreedesktopPlugin, self).__init__() + self.config.add({ + 'auto': False + }) + + def commands(self): + return [freedesktop_command] + + +@FreedesktopPlugin.listen('album_imported') +def imported(lib, album): + automatic = config['auto'].get(bool) + if not automatic: + return + process_album(album) diff --git a/docs/plugins/freedesktop.rst b/docs/plugins/freedesktop.rst new file mode 100644 index 000000000..4d7a57234 --- /dev/null +++ b/docs/plugins/freedesktop.rst @@ -0,0 +1,25 @@ +Freedesktop Plugin +================== + +The ``freedesktop`` plugin creates .directory files in your album folders. This +allows, when using a freedesktop.org compliant file manager, such as +Dolphin or Nautilus, an album to have its cover art as the folder's thumbnail. + +To use the ``freedesktop`` plugin, enable it (see :doc:`/plugins/index`). + +Configuration +------------- + +To configure the plugin, make a ``freedesktop:`` section in your configuration +file. The only available option is: + +- ``auto``: Create .directory files automatically during import. + Default: ``no`` + +Creating .directory Files Manually +---------------------------------- + +The ``freedesktop`` command provided by this plugin creates .directory files +for albums that match a query (see :doc:`/reference/query`). For example, ``beet +freedesktop man the animal cannon`` will create the .directory file for the +folder containing the album Man the Animal Cannon. \ No newline at end of file diff --git a/docs/plugins/index.rst b/docs/plugins/index.rst index 74058bf56..446e2921b 100644 --- a/docs/plugins/index.rst +++ b/docs/plugins/index.rst @@ -70,6 +70,7 @@ Each plugin has its own set of options that can be defined in a section bearing spotify types lastimport + freedesktop Autotagger Extensions --------------------- @@ -129,6 +130,7 @@ Interoperability * :doc:`importfeeds`: Keep track of imported files via ``.m3u`` playlist file(s) or symlinks. * :doc:`smartplaylist`: Generate smart playlists based on beets queries. * :doc:`play`: Play beets queries in your music player. +* :doc:`freedesktop`: Create .directory files in album folders. Miscellaneous -------------