Added optional argument for play-plugin

* New config key "play -> optargs"
 * New Subcommand argument "-o", "--optargs"
 * Set position using "{}" within "play -> command"-string
This commit is contained in:
Oliver Rümpelein 2015-07-02 20:14:46 +02:00
parent 1f72184533
commit 0a995c218a

View file

@ -35,6 +35,7 @@ class PlayPlugin(BeetsPlugin):
'command': None,
'use_folders': False,
'relative_to': None,
'optional_args': None,
})
def commands(self):
@ -43,19 +44,28 @@ class PlayPlugin(BeetsPlugin):
help='send music to a player as a playlist'
)
play_command.parser.add_album_option()
play_command.parser.add_option('-o','--optargs',action='store_true',
help='Insert additional arguments into command string')
play_command.func = self.play_music
return [play_command]
def play_music(self, lib, opts, args):
"""Execute query, create temporary playlist and execute player
command passing that playlist.
command passing that playlist, at request insert optional arguments.
"""
command_str = config['play']['command'].get()
use_folders = config['play']['use_folders'].get(bool)
relative_to = config['play']['relative_to'].get()
optional_args = config['play']['optional_args'].get()
if relative_to:
relative_to = util.normpath(relative_to)
# Prepare command strings wirh optional args
if opts.optargs:
command_str=command_str.format(optional_args or '')
else:
command_str=command_str.format('')
# Perform search by album and add folders rather than tracks to
# playlist.
if opts.album: