From bd3518719e49f1ec1fe8da3420d74a680472fcb9 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sun, 5 Apr 2020 12:29:34 +0100 Subject: [PATCH] feat(args): ability to override play on add config New CLI arguments `--play` and `--noplay` allow the config `play_on_add` setting to be overriden per run. --- rofi_mpd/rofi_mpd.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/rofi_mpd/rofi_mpd.py b/rofi_mpd/rofi_mpd.py index c897538..985271c 100755 --- a/rofi_mpd/rofi_mpd.py +++ b/rofi_mpd/rofi_mpd.py @@ -23,6 +23,11 @@ parser.add_argument('-c', '--host', help='Use the specified MPD host') parser.add_argument('-p', '--port', help='Use the specified MPD port') +parser.add_argument('--play', action='store_true', help='Start playback on add (overrides config)', dest='play_on_add', + default=None) +parser.add_argument('--noplay', action='store_false', help='Do not start playback on add (overrides config)', + dest='play_on_add', default=None) + parser.add_argument('-i', '--case-sensitive', action='store_true', help='Enable case sensitivity') parser.add_argument('-r', '--args', nargs=argparse.REMAINDER, help='Command line arguments for rofi. ' @@ -236,6 +241,13 @@ def run(): else: client.add(track['file']) - if 'play_on_add' in config and config['play_on_add']: - if client.status()['state'] != 'play': - client.play() + play_on_add = None + if 'play_on_add' in config: + play_on_add = config['play_on_add'] + + if args.play_on_add is not None: + play_on_add = args.play_on_add + + if play_on_add: + if client.status()['state'] != 'play': + client.play()