From 0a995c218afe033124fdff198ec67ae487a7575c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20R=C3=BCmpelein?= Date: Thu, 2 Jul 2015 20:14:46 +0200 Subject: [PATCH 1/7] Added optional argument for play-plugin * New config key "play -> optargs" * New Subcommand argument "-o", "--optargs" * Set position using "{}" within "play -> command"-string --- beetsplug/play.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/beetsplug/play.py b/beetsplug/play.py index 65d5b91ec..1c8a062c9 100644 --- a/beetsplug/play.py +++ b/beetsplug/play.py @@ -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: From 3b2c3a5b31f127c390fd423611dc1a451b7d234d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20R=C3=BCmpelein?= Date: Thu, 2 Jul 2015 20:46:10 +0200 Subject: [PATCH 2/7] Renamed options, corrected small typos. --- beetsplug/play.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/beetsplug/play.py b/beetsplug/play.py index 1c8a062c9..3e8e51d25 100644 --- a/beetsplug/play.py +++ b/beetsplug/play.py @@ -35,7 +35,7 @@ class PlayPlugin(BeetsPlugin): 'command': None, 'use_folders': False, 'relative_to': None, - 'optional_args': None, + 'optargs': None, }) def commands(self): @@ -56,13 +56,13 @@ class PlayPlugin(BeetsPlugin): 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() + optargs = config['play']['optargs'].get() if relative_to: relative_to = util.normpath(relative_to) - # Prepare command strings wirh optional args + # Prepare command strings with optional args if opts.optargs: - command_str=command_str.format(optional_args or '') + command_str=command_str.format(optargs or '') else: command_str=command_str.format('') From 3b6373541ad76030d39cf6bc998656c714266670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20R=C3=BCmpelein?= Date: Sun, 5 Jul 2015 15:00:46 +0200 Subject: [PATCH 3/7] Fixed Errors indicated by travis-ci See https://travis-ci.org/sampsyo/beets/jobs/69335554 --- beetsplug/play.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/beetsplug/play.py b/beetsplug/play.py index 3e8e51d25..0a51789d3 100644 --- a/beetsplug/play.py +++ b/beetsplug/play.py @@ -44,8 +44,11 @@ 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.parser.add_option( + '-o', '--optargs', + action='store_true', + help='Insert additional arguments into command string' + ) play_command.func = self.play_music return [play_command] @@ -62,9 +65,9 @@ class PlayPlugin(BeetsPlugin): # Prepare command strings with optional args if opts.optargs: - command_str=command_str.format(optargs or '') + command_str = command_str.format(optargs or '') else: - command_str=command_str.format('') + command_str = command_str.format('') # Perform search by album and add folders rather than tracks to # playlist. From 5f9068cb50a7549afae5f648162af4af62aaaf0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20R=C3=BCmpelein?= Date: Sat, 1 Aug 2015 13:55:17 +0200 Subject: [PATCH 4/7] Implemented Idea 2 from #1532 * New argument `--optargs` reads string from option * If "{}" is present in the given string, the `optargs` from config-file get inserted at that point. --- beetsplug/play.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/beetsplug/play.py b/beetsplug/play.py index 0a51789d3..560370335 100644 --- a/beetsplug/play.py +++ b/beetsplug/play.py @@ -46,7 +46,7 @@ class PlayPlugin(BeetsPlugin): play_command.parser.add_album_option() play_command.parser.add_option( '-o', '--optargs', - action='store_true', + action='store', help='Insert additional arguments into command string' ) play_command.func = self.play_music @@ -59,16 +59,15 @@ class PlayPlugin(BeetsPlugin): command_str = config['play']['command'].get() use_folders = config['play']['use_folders'].get(bool) relative_to = config['play']['relative_to'].get() - optargs = config['play']['optargs'].get() + confargs = config['play']['optargs'].get() if relative_to: relative_to = util.normpath(relative_to) # Prepare command strings with optional args if opts.optargs: - command_str = command_str.format(optargs or '') - else: - command_str = command_str.format('') - + command_str = command_str.format(opts.optargs or '')\ + .format(confargs or '') + # Perform search by album and add folders rather than tracks to # playlist. if opts.album: From 90bb4081feba35d024e74134b2bce5ca7303041a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20R=C3=BCmpelein?= Date: Sun, 2 Aug 2015 20:44:56 +0200 Subject: [PATCH 5/7] Implemented `--args`-feature * as discussed in #1532, with args-parameter, and optionally inserted config-key * updated changelog/docs --- beetsplug/play.py | 10 +++++----- docs/changelog.rst | 3 ++- docs/plugins/play.rst | 41 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/beetsplug/play.py b/beetsplug/play.py index 560370335..3cf3ad7d9 100644 --- a/beetsplug/play.py +++ b/beetsplug/play.py @@ -35,7 +35,7 @@ class PlayPlugin(BeetsPlugin): 'command': None, 'use_folders': False, 'relative_to': None, - 'optargs': None, + 'args': None, }) def commands(self): @@ -45,7 +45,7 @@ class PlayPlugin(BeetsPlugin): ) play_command.parser.add_album_option() play_command.parser.add_option( - '-o', '--optargs', + '-A', '--args', action='store', help='Insert additional arguments into command string' ) @@ -59,13 +59,13 @@ class PlayPlugin(BeetsPlugin): command_str = config['play']['command'].get() use_folders = config['play']['use_folders'].get(bool) relative_to = config['play']['relative_to'].get() - confargs = config['play']['optargs'].get() + confargs = config['play']['args'].get() if relative_to: relative_to = util.normpath(relative_to) # Prepare command strings with optional args - if opts.optargs: - command_str = command_str.format(opts.optargs or '')\ + if opts.args: + command_str = command_str.format(opts.args or '')\ .format(confargs or '') # Perform search by album and add folders rather than tracks to diff --git a/docs/changelog.rst b/docs/changelog.rst index 335b88346..5673f86f0 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -26,7 +26,8 @@ New features: :bug:`1104` :bug:`1493` * :doc:`/plugins/plexupdate`: A new ``token`` configuration option lets you specify a key for Plex Home setups. Thanks to :user:`edcarroll`. :bug:`1494` - +* :doc:`/plugins/play`: A new option `--args`/`-A` has been added, used to + hand over options to the player. Fixes: diff --git a/docs/plugins/play.rst b/docs/plugins/play.rst index 939e3bec4..45c8ab641 100644 --- a/docs/plugins/play.rst +++ b/docs/plugins/play.rst @@ -29,6 +29,12 @@ would on the command-line):: While playing you'll be able to interact with the player if it is a command-line oriented, and you'll get its output in real time. +The ``--args``-argument can be used to pass additional parameters to the +command. The position for these is marked by ``{}`` in the command-section. + +For additional features and usage of the ``--args``-argument, see the example +below. + Configuration ------------- @@ -37,10 +43,43 @@ configuration file. The available options are: - **command**: The command used to open the playlist. Default: ``open`` on OS X, ``xdg-open`` on other Unixes and ``start`` on - Windows. + Windows. Insert ``{}`` to make use of the ``--args``-feature. - **relative_to**: Emit paths relative to base directory. Default: None. - **use_folders**: When using the ``-a`` option, the m3u will contain the paths to each track on the matched albums. Enable this option to store paths to folders instead. Default: ``no``. +- **optargs**: Static, additional parameters that may be inserted + using ``--args``. For this to work, you need ``{}`` inserted into your + command-section of the config file as well as into the parameter given to + ``--args`` (see example) + +Args-Example +------------ + +Assume you have the following in your config file:: + + play: + command: player --opt1 arg1 {} --opt2 + args: --opt3 + +If you just call ``beet play`` without the usage of ``--args``, the command +will be called as if the ``{}`` wasn't there:: + + player --opt1 arg1 --opt2 + +If ``--args`` is given, the ``{}`` gets replaced by the argument, thus +``beet play --args "--opt4"`` results in a call of:: + + player --opt1 arg1 --opt4 --opt2 + +To insert the options configured with the args-key in the config-file, +call ``beet play --args "{}"``, resulting in:: + + player --opt1 arg1 --opt3 --opt2 + +Of course, this can be combined with other parameters as well, like in +``beet play --args "{} --opt4"``, which calls the following:: + + player --opt1 arg1 --opt3 --opt4 --opt2 From 69377291ff42b928cb7182f4af3cdf3822447ae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20R=C3=BCmpelein?= Date: Sun, 2 Aug 2015 21:08:44 +0200 Subject: [PATCH 6/7] Try to fix TravisCI-errors. --- beetsplug/play.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beetsplug/play.py b/beetsplug/play.py index 3cf3ad7d9..6d4a93c4d 100644 --- a/beetsplug/play.py +++ b/beetsplug/play.py @@ -66,8 +66,8 @@ class PlayPlugin(BeetsPlugin): # Prepare command strings with optional args if opts.args: command_str = command_str.format(opts.args or '')\ - .format(confargs or '') - + .format(confargs or '') + # Perform search by album and add folders rather than tracks to # playlist. if opts.album: From 94258110a74c30acfbdbcaea4643a2d00863904a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20R=C3=BCmpelein?= Date: Mon, 3 Aug 2015 17:01:56 +0200 Subject: [PATCH 7/7] Forgot to remove an if-statement. --- beetsplug/play.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/beetsplug/play.py b/beetsplug/play.py index 6d4a93c4d..6404ab7cf 100644 --- a/beetsplug/play.py +++ b/beetsplug/play.py @@ -64,10 +64,9 @@ class PlayPlugin(BeetsPlugin): relative_to = util.normpath(relative_to) # Prepare command strings with optional args - if opts.args: - command_str = command_str.format(opts.args or '')\ - .format(confargs or '') - + command_str = command_str.format(opts.args or '')\ + .format(confargs or '') + # Perform search by album and add folders rather than tracks to # playlist. if opts.album: