Skip to content

Commit

Permalink
Merge pull request #161 from Ravioli8235/autoplay
Browse files Browse the repository at this point in the history
Implement autoplay on/off toggle
  • Loading branch information
dmunozv04 authored Jun 21, 2024
2 parents 015f5a7 + b1333a2 commit 49fba2f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"skip_count_tracking": true,
"mute_ads": true,
"skip_ads": true,
"autoplay": true,
"apikey": "",
"channel_whitelist": [
{"id": "",
Expand Down
2 changes: 2 additions & 0 deletions src/iSponsorBlockTV/config_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
1 change: 1 addition & 0 deletions src/iSponsorBlockTV/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 6 additions & 0 deletions src/iSponsorBlockTV/setup-wizard-style.tcss
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,9 @@ MigrationScreen {
width: 1fr;
content-align: center middle;
}

/* Autoplay */
#autoplay-container{
padding: 1;
height: auto;
}
29 changes: 29 additions & 0 deletions src/iSponsorBlockTV/setup_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,32 @@ 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"""

Expand Down Expand Up @@ -886,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():
Expand Down
4 changes: 4 additions & 0 deletions src/iSponsorBlockTV/ytlounge.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ def __init__(
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):
Expand Down Expand Up @@ -146,6 +148,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)

Expand Down

0 comments on commit 49fba2f

Please sign in to comment.