Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mediaplayer: add exclude player option #2958

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions resources/custom_modules/mediaplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def signal_handler(sig, frame):


class PlayerManager:
def __init__(self, selected_player=None):
def __init__(self, selected_player=None, excluded_player=[]):
self.manager = Playerctl.PlayerManager()
self.loop = GLib.MainLoop()
self.manager.connect(
Expand All @@ -35,11 +35,14 @@ def __init__(self, selected_player=None):
signal.signal(signal.SIGTERM, signal_handler)
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
self.selected_player = selected_player
self.excluded_player = excluded_player.split(',') if excluded_player else []

self.init_players()

def init_players(self):
for player in self.manager.props.player_names:
if player.name in self.excluded_player:
continue
if self.selected_player is not None and self.selected_player != player.name:
logger.debug(f"{player.name} is not the filtered player, skipping it")
continue
Expand Down Expand Up @@ -149,6 +152,8 @@ def parse_arguments():
# Increase verbosity with every occurrence of -v
parser.add_argument("-v", "--verbose", action="count", default=0)

parser.add_argument("-x", "--exclude", "- Comma-separated list of excluded player")

# Define for which player we"re listening
parser.add_argument("--player")

Expand All @@ -174,7 +179,10 @@ def main():
logger.info("Creating player manager")
if arguments.player:
logger.info(f"Filtering for player: {arguments.player}")
player = PlayerManager(arguments.player)
if arguments.exclude:
logger.info(f"Exclude player {arguments.exclude}")

player = PlayerManager(arguments.player, arguments.exclude)
player.run()


Expand Down