From 095294389ba06be88e260ac89525c2c618c08b43 Mon Sep 17 00:00:00 2001 From: Daniel Voogsgerd Date: Wed, 27 Mar 2019 17:30:14 +0100 Subject: [PATCH] feat(Spotify): Add option to select player --- resources/custom_modules/mediaplayer.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/resources/custom_modules/mediaplayer.py b/resources/custom_modules/mediaplayer.py index 4d5f5146..189b49fe 100755 --- a/resources/custom_modules/mediaplayer.py +++ b/resources/custom_modules/mediaplayer.py @@ -38,6 +38,13 @@ def on_metadata(player, metadata, manager): sys.stdout.flush() +def on_player_appeared(manager, player, selected_player=None): + if player is not None and player.name == selected_player: + init_player(manager, player) + else: + logger.debug('New player appeared, but it\'s not the selected player, skipping') + + def on_player_vanished(manager, player): logger.info("Player has vanished") sys.stdout.write("\n") @@ -67,6 +74,9 @@ def parse_arguments(): # Increase verbosity with every occurance of -v parser.add_argument('-v', '--verbose', action="count", default=0) + # Define for which player we're listening + parser.add_argument('--player') + return parser.parse_args() @@ -87,13 +97,19 @@ def main(): manager = Playerctl.PlayerManager() loop = GLib.MainLoop() - manager.connect('name-appeared', init_player) + manager.connect('name-appeared', lambda *args: on_player_appeared(*args, arguments.player)) manager.connect('player-vanished', on_player_vanished) signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) for player in manager.props.player_names: + if arguments.player is not None and arguments.player != player.name: + logger.debug('{player} is not the filtered player, skipping it' + .format(player=player.name) + ) + continue + init_player(manager, player) loop.run()