-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1056 from kerobaros/master
New plugin: freedesktop
- Loading branch information
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters