From fb3ed6b39a17bc3f2921af576990670a324508e6 Mon Sep 17 00:00:00 2001 From: Ravioli8235 Date: Thu, 30 May 2024 08:53:35 +0200 Subject: [PATCH 1/5] Implement autoplay --- config.json.template | 1 + src/iSponsorBlockTV/config_setup.py | 7 +++++++ src/iSponsorBlockTV/helpers.py | 1 + src/iSponsorBlockTV/setup_wizard.py | 31 +++++++++++++++++++++++++++++ src/iSponsorBlockTV/ytlounge.py | 4 ++++ 5 files changed, 44 insertions(+) diff --git a/config.json.template b/config.json.template index 59f2b9d..5e828f9 100644 --- a/config.json.template +++ b/config.json.template @@ -12,6 +12,7 @@ "skip_count_tracking": true, "mute_ads": true, "skip_ads": true, + "autoplay": true, "apikey": "", "channel_whitelist": [ {"id": "", diff --git a/src/iSponsorBlockTV/config_setup.py b/src/iSponsorBlockTV/config_setup.py index 51b0138..393d712 100644 --- a/src/iSponsorBlockTV/config_setup.py +++ b/src/iSponsorBlockTV/config_setup.py @@ -163,5 +163,12 @@ def main(config, debug: bool) -> None: ) == "n" ) + + config.auto_play = ( + not input( + "Do you want to enable autoplay? (y/n) " + ) + == "n" + ) print("Config finished") config.save() diff --git a/src/iSponsorBlockTV/helpers.py b/src/iSponsorBlockTV/helpers.py index 0627c29..3bce12c 100644 --- a/src/iSponsorBlockTV/helpers.py +++ b/src/iSponsorBlockTV/helpers.py @@ -41,6 +41,7 @@ def __init__(self, data_dir): self.skip_count_tracking = True self.mute_ads = False self.skip_ads = False + self.auto_play = True self.__load() def validate(self): diff --git a/src/iSponsorBlockTV/setup_wizard.py b/src/iSponsorBlockTV/setup_wizard.py index e692abe..e45a02e 100644 --- a/src/iSponsorBlockTV/setup_wizard.py +++ b/src/iSponsorBlockTV/setup_wizard.py @@ -848,6 +848,34 @@ def add_channel(self, event: Button.Pressed): self.app.push_screen(AddChannel(self.config), callback=self.new_channel) +class AutoPlayManager(Vertical): + """Manager for autoplay, allows enabling/disabling autoplay.""" + + def __init__(self, config, **kwargs) -> None: + super().__init__(**kwargs) + self.config = config + + def compose(self) -> ComposeResult: + yield Label("Autoplay", classes="title") + yield Label( + ( + "This feature allows you to enable/disable autoplay" + ), + classes="subtitle", + id="autoplay-subtitle", + ) + with Horizontal(id="autoplay-container"): + yield Checkbox( + value=self.config.auto_play, + id="autoplay-switch", + label="Enable autoplay", + ) + + @on(Checkbox.Changed, "#autoplay-switch") + def changed_skip(self, event: Checkbox.Changed): + self.config.auto_play = event.checkbox.value + + class ISponsorBlockTVSetupMainScreen(Screen): """Making this a separate screen to avoid a bug: https://github.com/Textualize/textual/issues/3221""" @@ -884,6 +912,9 @@ def compose(self) -> ComposeResult: yield ApiKeyManager( config=self.config, id="api-key-manager", classes="container" ) + yield AutoPlayManager( + config=self.config, id="autoplay-manager", classes="container" + ) def on_mount(self) -> None: if self.check_for_old_config_entries(): diff --git a/src/iSponsorBlockTV/ytlounge.py b/src/iSponsorBlockTV/ytlounge.py index 18087f7..430021e 100644 --- a/src/iSponsorBlockTV/ytlounge.py +++ b/src/iSponsorBlockTV/ytlounge.py @@ -20,9 +20,11 @@ def __init__(self, screen_id, config=None, api_helper=None, logger=None): self.callback = None self.logger = logger self.shorts_disconnected = False + self.auto_play = True if config: self.mute_ads = config.mute_ads self.skip_ads = config.skip_ads + self.auto_play = config.auto_play # Ensures that we still are subscribed to the lounge async def _watchdog(self): @@ -136,6 +138,8 @@ def _process_event(self, event_id: int, event_type: str, args): data = args[0] if data["reason"] == "disconnectedByUserScreenInitiated": # Short playing? self.shorts_disconnected = True + elif event_type == "onAutoplayModeChanged": + create_task(self.set_auto_play_mode(self.auto_play)) super()._process_event(event_id, event_type, args) From faa0379b8991ebc94b5908959637cf1151adcc29 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 May 2024 07:03:27 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/iSponsorBlockTV/config_setup.py | 7 +------ src/iSponsorBlockTV/setup_wizard.py | 4 +--- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/iSponsorBlockTV/config_setup.py b/src/iSponsorBlockTV/config_setup.py index 393d712..db5b30f 100644 --- a/src/iSponsorBlockTV/config_setup.py +++ b/src/iSponsorBlockTV/config_setup.py @@ -164,11 +164,6 @@ def main(config, debug: bool) -> None: == "n" ) - config.auto_play = ( - not input( - "Do you want to enable autoplay? (y/n) " - ) - == "n" - ) + config.auto_play = not input("Do you want to enable autoplay? (y/n) ") == "n" print("Config finished") config.save() diff --git a/src/iSponsorBlockTV/setup_wizard.py b/src/iSponsorBlockTV/setup_wizard.py index e45a02e..dcef224 100644 --- a/src/iSponsorBlockTV/setup_wizard.py +++ b/src/iSponsorBlockTV/setup_wizard.py @@ -858,9 +858,7 @@ def __init__(self, config, **kwargs) -> None: def compose(self) -> ComposeResult: yield Label("Autoplay", classes="title") yield Label( - ( - "This feature allows you to enable/disable autoplay" - ), + "This feature allows you to enable/disable autoplay", classes="subtitle", id="autoplay-subtitle", ) From bfefa94a7bf18f1e1e71ff4026052fac9e985e1a Mon Sep 17 00:00:00 2001 From: Ravioli8235 Date: Fri, 21 Jun 2024 15:58:15 +0200 Subject: [PATCH 3/5] fix panel fill --- src/iSponsorBlockTV/setup_wizard.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/iSponsorBlockTV/setup_wizard.py b/src/iSponsorBlockTV/setup_wizard.py index e45a02e..ede8bee 100644 --- a/src/iSponsorBlockTV/setup_wizard.py +++ b/src/iSponsorBlockTV/setup_wizard.py @@ -864,12 +864,11 @@ def compose(self) -> ComposeResult: classes="subtitle", id="autoplay-subtitle", ) - with Horizontal(id="autoplay-container"): - yield Checkbox( - value=self.config.auto_play, - id="autoplay-switch", - label="Enable autoplay", - ) + yield Checkbox( + value=self.config.auto_play, + id="autoplay-switch", + label="Enable autoplay", + ) @on(Checkbox.Changed, "#autoplay-switch") def changed_skip(self, event: Checkbox.Changed): From cfef219d3243c5d1e8094f52574e1470b524ff04 Mon Sep 17 00:00:00 2001 From: dmunozv04 <39565245+dmunozv04@users.noreply.github.com> Date: Fri, 21 Jun 2024 16:29:17 +0200 Subject: [PATCH 4/5] fix autoplay padding --- src/iSponsorBlockTV/setup-wizard-style.tcss | 6 ++++++ src/iSponsorBlockTV/setup_wizard.py | 11 ++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/iSponsorBlockTV/setup-wizard-style.tcss b/src/iSponsorBlockTV/setup-wizard-style.tcss index e6dd886..e10f091 100644 --- a/src/iSponsorBlockTV/setup-wizard-style.tcss +++ b/src/iSponsorBlockTV/setup-wizard-style.tcss @@ -363,3 +363,9 @@ MigrationScreen { width: 1fr; content-align: center middle; } + +/* Autoplay */ +#autoplay-container{ + padding: 1; + height: auto; +} \ No newline at end of file diff --git a/src/iSponsorBlockTV/setup_wizard.py b/src/iSponsorBlockTV/setup_wizard.py index 083d062..669c581 100644 --- a/src/iSponsorBlockTV/setup_wizard.py +++ b/src/iSponsorBlockTV/setup_wizard.py @@ -864,11 +864,12 @@ def compose(self) -> ComposeResult: classes="subtitle", id="autoplay-subtitle", ) - yield Checkbox( - value=self.config.auto_play, - id="autoplay-switch", - label="Enable autoplay", - ) + with Horizontal(id="autoplay-container"): + yield Checkbox( + value=self.config.auto_play, + id="autoplay-switch", + label="Enable autoplay", + ) @on(Checkbox.Changed, "#autoplay-switch") def changed_skip(self, event: Checkbox.Changed): From b1333a2f6186648984ca6b9f7f0a1c620f6285f7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 21 Jun 2024 14:29:34 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/iSponsorBlockTV/setup-wizard-style.tcss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/iSponsorBlockTV/setup-wizard-style.tcss b/src/iSponsorBlockTV/setup-wizard-style.tcss index e10f091..4f6d25e 100644 --- a/src/iSponsorBlockTV/setup-wizard-style.tcss +++ b/src/iSponsorBlockTV/setup-wizard-style.tcss @@ -368,4 +368,4 @@ MigrationScreen { #autoplay-container{ padding: 1; height: auto; -} \ No newline at end of file +}