mirror of
https://github.com/dmunozv04/iSponsorBlockTV.git
synced 2025-12-09 21:46:45 +03:00
Merge pull request #161 from Ravioli8235/autoplay
Implement autoplay on/off toggle
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
"skip_count_tracking": true,
|
||||
"mute_ads": true,
|
||||
"skip_ads": true,
|
||||
"autoplay": true,
|
||||
"apikey": "",
|
||||
"channel_whitelist": [
|
||||
{"id": "",
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -363,3 +363,9 @@ MigrationScreen {
|
||||
width: 1fr;
|
||||
content-align: center middle;
|
||||
}
|
||||
|
||||
/* Autoplay */
|
||||
#autoplay-container{
|
||||
padding: 1;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user