From 2d82aa85b56d39839a4a7f8838070f79e1a39f56 Mon Sep 17 00:00:00 2001 From: kerobaros Date: Sat, 1 Nov 2014 21:47:55 -0500 Subject: [PATCH 1/7] Starting on freedesktop plugin. --- beetsplug/freedesktop.py | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 beetsplug/freedesktop.py diff --git a/beetsplug/freedesktop.py b/beetsplug/freedesktop.py new file mode 100644 index 000000000..f3dc3f5d5 --- /dev/null +++ b/beetsplug/freedesktop.py @@ -0,0 +1,43 @@ +from beets.plugins import BeetsPlugin +from beets.ui import Subcommand + +from beets.ui import decargs + +import os.path + +freedesktop_command = Subcommand("freedesktop", help="Create .directory files") + + +def process_query(lib, opts, args): + for album in lib.albums(decargs(args)): + albumpath = album.item_dir() + fullartpath = album.artpath + artfile = os.path.split(fullartpath)[1] + create_file(albumpath, artfile) + + +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): + """Creates freedesktop.org-compliant .directory files on an album level. + """ + def __init__(self): + super(FreedesktopPlugin, self).__init__() + self.config.add({ + 'auto': False + }) + + def commands(self): + return [freedesktop_command] From 6ca34632de95cca697745ad2e085878c6fc9e1ec Mon Sep 17 00:00:00 2001 From: kerobaros Date: Sun, 2 Nov 2014 22:05:37 -0600 Subject: [PATCH 2/7] fd plugin now runs on album_imported hook. also logs when album has no art. --- beetsplug/freedesktop.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/beetsplug/freedesktop.py b/beetsplug/freedesktop.py index f3dc3f5d5..44a5c3c6a 100644 --- a/beetsplug/freedesktop.py +++ b/beetsplug/freedesktop.py @@ -4,16 +4,26 @@ from beets.ui import Subcommand from beets.ui import decargs 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)): - albumpath = album.item_dir() + 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): @@ -38,6 +48,15 @@ class FreedesktopPlugin(BeetsPlugin): self.config.add({ 'auto': False }) + global automatic + automatic = self.config['auto'].get(bool) def commands(self): return [freedesktop_command] + + +@FreedesktopPlugin.listen('album_imported') +def imported(lib, album): + if not automatic: + return + process_album(album) From a85069c4ec22744d349f01d9cd70f9b6eee7b47d Mon Sep 17 00:00:00 2001 From: kerobaros Date: Sun, 2 Nov 2014 22:16:33 -0600 Subject: [PATCH 3/7] Add doc page for freedesktop plugin. --- docs/plugins/freedesktop.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 docs/plugins/freedesktop.rst 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 From 7a6411781a96462c61d9d360761b607305ea4068 Mon Sep 17 00:00:00 2001 From: kerobaros Date: Sun, 2 Nov 2014 22:21:35 -0600 Subject: [PATCH 4/7] Add freedesktop doc page to plugins index. --- docs/plugins/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/plugins/index.rst b/docs/plugins/index.rst index 74058bf56..b92b9b039 100644 --- a/docs/plugins/index.rst +++ b/docs/plugins/index.rst @@ -129,6 +129,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 ------------- From 05ae354ffa42c9d1361c23d42448a0fa15e02f4b Mon Sep 17 00:00:00 2001 From: kerobaros Date: Sun, 2 Nov 2014 22:25:47 -0600 Subject: [PATCH 5/7] Add freedesktop doc page to plugins index, take two. --- docs/plugins/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/plugins/index.rst b/docs/plugins/index.rst index b92b9b039..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 --------------------- From 8daeb7d79e503e5c388870a5b725af82a92a9d1e Mon Sep 17 00:00:00 2001 From: kerobaros Date: Sun, 2 Nov 2014 22:35:40 -0600 Subject: [PATCH 6/7] Fixed up config checking to make freedesktop plugin pass flake8. --- beetsplug/freedesktop.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/beetsplug/freedesktop.py b/beetsplug/freedesktop.py index 44a5c3c6a..e365a1297 100644 --- a/beetsplug/freedesktop.py +++ b/beetsplug/freedesktop.py @@ -3,6 +3,8 @@ from beets.ui import Subcommand from beets.ui import decargs +from beets import config + import os.path import logging @@ -48,8 +50,6 @@ class FreedesktopPlugin(BeetsPlugin): self.config.add({ 'auto': False }) - global automatic - automatic = self.config['auto'].get(bool) def commands(self): return [freedesktop_command] @@ -57,6 +57,7 @@ class FreedesktopPlugin(BeetsPlugin): @FreedesktopPlugin.listen('album_imported') def imported(lib, album): + automatic = config['auto'].get(bool) if not automatic: return process_album(album) From 3516fb67ebaf1637d20c881b26e283183d83a078 Mon Sep 17 00:00:00 2001 From: kerobaros Date: Sun, 2 Nov 2014 22:41:03 -0600 Subject: [PATCH 7/7] Added docstring, copyright and license to plugin. --- beetsplug/freedesktop.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/beetsplug/freedesktop.py b/beetsplug/freedesktop.py index e365a1297..732bea544 100644 --- a/beetsplug/freedesktop.py +++ b/beetsplug/freedesktop.py @@ -1,3 +1,20 @@ +# 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 @@ -43,8 +60,6 @@ freedesktop_command.func = process_query class FreedesktopPlugin(BeetsPlugin): - """Creates freedesktop.org-compliant .directory files on an album level. - """ def __init__(self): super(FreedesktopPlugin, self).__init__() self.config.add({