|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | import os |
3 | | -from re import split |
4 | | -from warnings import catch_warnings |
| 3 | +# from re import split |
| 4 | +# from warnings import catch_warnings |
5 | 5 | import gi |
6 | 6 |
|
7 | 7 | gi.require_version("Playerctl", "2.0") |
|
26 | 26 | # for each player. Key = player_name |
27 | 27 | # |
28 | 28 | players_data = {} |
29 | | -currentplayer = None |
| 29 | +current_player = None |
30 | 30 |
|
31 | 31 |
|
32 | 32 | def load_env_file(filepath: str) -> None: |
@@ -177,7 +177,7 @@ def on_player_appeared(manager, player, selected_players=None): |
177 | 177 |
|
178 | 178 | def on_player_vanished(manager, player, loop): |
179 | 179 | logger.info("Player has vanished") |
180 | | - if currentplayer.props.player_name == player.props.player_name: |
| 180 | + if current_player.props.player_name == player.props.player_name: |
181 | 181 | if manager.props.players: |
182 | 182 | set_player(manager, manager.props.players[0]) |
183 | 183 | on_metadata(player, player.props.metadata, manager) |
@@ -368,44 +368,43 @@ def main(): |
368 | 368 | found[players.index(player.name)] = p |
369 | 369 | if found: |
370 | 370 | found = list(filter(lambda x: x is not None, found)) |
371 | | - try: |
372 | | - p = next(player for player in found if player.props.status == "Playing") |
373 | | - except StopIteration: |
374 | | - p = None |
375 | | - if not p: |
376 | | - p = found[0] |
377 | | - set_player(manager, p) |
378 | | - player_found = True |
379 | | - # If no player is found, generate the standby output |
| 371 | + if found: |
| 372 | + try: |
| 373 | + p = next(player for player in found if player.props.status == "Playing") |
| 374 | + except StopIteration: |
| 375 | + p = None |
| 376 | + if not p: |
| 377 | + p = found[0] |
| 378 | + set_player(manager, p) |
| 379 | + player_found = True |
| 380 | + # If no player is found, generate the standby output and continue running the loop |
380 | 381 | if not player_found: |
381 | 382 | output = { |
382 | 383 | "text": standby_text, |
383 | 384 | "class": "custom-nothing-playing", |
384 | 385 | "alt": "player-closed", |
385 | 386 | "tooltip": "", |
386 | 387 | } |
387 | | - |
388 | 388 | sys.stdout.write(json.dumps(output) + "\n") |
389 | 389 | sys.stdout.flush() |
390 | | - |
391 | 390 | # Set up a single 1-second timer to update song position |
392 | 391 | GLib.timeout_add_seconds(1, update_positions, manager) |
393 | 392 |
|
394 | 393 | loop.run() |
395 | 394 |
|
396 | 395 |
|
397 | 396 | def set_player(manager, player): |
398 | | - global currentplayer |
399 | | - if currentplayer: |
400 | | - if currentplayer.props.player_name != player.props.player_name: |
401 | | - currentplayer.pause() |
402 | | - currentplayer = player |
| 397 | + global current_player |
| 398 | + if current_player: |
| 399 | + if current_player.props.player_name != player.props.player_name: |
| 400 | + current_player.pause() |
| 401 | + current_player = player |
403 | 402 | manager.move_player_to_top(player) |
404 | 403 |
|
405 | 404 |
|
406 | 405 | def control_music(sig, frame, action): |
407 | | - if currentplayer: |
408 | | - getattr(currentplayer, action)() |
| 406 | + if current_player: |
| 407 | + getattr(current_player, action)() |
409 | 408 |
|
410 | 409 |
|
411 | 410 | def escape(string): |
|
0 commit comments