Merge pull request #251 from DanielVoogsgerd/feature-select-player

Feature select player
This commit is contained in:
Alex 2019-03-30 09:19:24 +01:00 committed by GitHub
commit 30725824d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -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()