feat(Spotify): Add option to select player

This commit is contained in:
Daniel Voogsgerd 2019-03-27 17:30:14 +01:00
parent 3bcf3befec
commit 095294389b
1 changed files with 17 additions and 1 deletions

View File

@ -38,6 +38,13 @@ def on_metadata(player, metadata, manager):
sys.stdout.flush() 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): def on_player_vanished(manager, player):
logger.info("Player has vanished") logger.info("Player has vanished")
sys.stdout.write("\n") sys.stdout.write("\n")
@ -67,6 +74,9 @@ def parse_arguments():
# Increase verbosity with every occurance of -v # Increase verbosity with every occurance of -v
parser.add_argument('-v', '--verbose', action="count", default=0) parser.add_argument('-v', '--verbose', action="count", default=0)
# Define for which player we're listening
parser.add_argument('--player')
return parser.parse_args() return parser.parse_args()
@ -87,13 +97,19 @@ def main():
manager = Playerctl.PlayerManager() manager = Playerctl.PlayerManager()
loop = GLib.MainLoop() 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) manager.connect('player-vanished', on_player_vanished)
signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler) signal.signal(signal.SIGTERM, signal_handler)
for player in manager.props.player_names: 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) init_player(manager, player)
loop.run() loop.run()