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 3e3bb95..7e223f2 100644 --- a/src/iSponsorBlockTV/config_setup.py +++ b/src/iSponsorBlockTV/config_setup.py @@ -164,6 +164,8 @@ 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() loop.run_until_complete(web_session.close()) 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 @@ class Config: 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-style.tcss b/src/iSponsorBlockTV/setup-wizard-style.tcss index e6dd886..4f6d25e 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; +} diff --git a/src/iSponsorBlockTV/setup_wizard.py b/src/iSponsorBlockTV/setup_wizard.py index da4d66f..669c581 100644 --- a/src/iSponsorBlockTV/setup_wizard.py +++ b/src/iSponsorBlockTV/setup_wizard.py @@ -850,6 +850,32 @@ class ChannelWhitelistManager(Vertical): 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""" @@ -886,6 +912,9 @@ class ISponsorBlockTVSetupMainScreen(Screen): 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 625329f..ce5f398 100644 --- a/src/iSponsorBlockTV/ytlounge.py +++ b/src/iSponsorBlockTV/ytlounge.py @@ -30,9 +30,11 @@ class YtLoungeApi(pyytlounge.YtLoungeApi): 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): @@ -146,6 +148,8 @@ class YtLoungeApi(pyytlounge.YtLoungeApi): 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)