Compare commits

...

10 Commits

Author SHA1 Message Date
dmunozv04
d17e59bf0d bump version 2024-07-07 17:36:01 +02:00
David
205191f442 Merge pull request #150 from ryankupk/update-cli
Refactor CLI setup script, add prompts for muting and skipping native youtube ads
2024-06-21 17:08:47 +02:00
dmunozv04
810cd5eec3 change default options for autoplay and reporting, and mark default option 2024-06-21 17:08:15 +02:00
pre-commit-ci[bot]
e2ace8629f [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-06-21 15:01:56 +00:00
dmunozv04
e54ead26d2 Merge remote-tracking branch 'origin' into pr/ryankupk/150 2024-06-21 17:01:45 +02:00
David
49fba2f28f Merge pull request #161 from Ravioli8235/autoplay
Implement autoplay on/off toggle
2024-06-21 16:56:57 +02:00
pre-commit-ci[bot]
b1333a2f61 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-06-21 14:29:35 +00:00
dmunozv04
cfef219d32 fix autoplay padding 2024-06-21 16:29:17 +02:00
pre-commit-ci[bot]
865f5469a2 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-05-03 16:24:21 +00:00
Ryan Kupka
daa7026221 Refactor CLI setup script, add prompts for muting and skipping native youtube ads 2024-05-03 10:18:16 -06:00
4 changed files with 208 additions and 177 deletions

View File

@@ -1,6 +1,6 @@
[project] [project]
name = "iSponsorBlockTV" name = "iSponsorBlockTV"
version = "2.0.8" version = "2.1.0"
authors = [ authors = [
{"name" = "dmunozv04"} {"name" = "dmunozv04"}
] ]

View File

@@ -1,171 +1,195 @@
import asyncio import asyncio
import aiohttp import aiohttp
from . import api_helpers, ytlounge from . import api_helpers, ytlounge
# Constants for user input prompts
async def pair_device(web_session): ATVS_REMOVAL_PROMPT = (
try: "Do you want to remove the legacy 'atvs' entry (the app won't start"
lounge_controller = ytlounge.YtLoungeApi( " with it present)? (y/N) "
"iSponsorBlockTV", web_session=web_session )
) PAIRING_CODE_PROMPT = "Enter pairing code (found in Settings - Link with TV code): "
pairing_code = input( ADD_MORE_DEVICES_PROMPT = "Paired with {num_devices} Device(s). Add more? (y/N) "
"Enter pairing code (found in Settings - Link with TV code): " CHANGE_API_KEY_PROMPT = "API key already specified. Change it? (y/N) "
) ADD_API_KEY_PROMPT = (
pairing_code = int( "API key only needed for the channel whitelist function. Add it? (y/N) "
pairing_code.replace("-", "").replace(" ", "") )
) # remove dashes and spaces ENTER_API_KEY_PROMPT = "Enter your API key: "
print("Pairing...") CHANGE_SKIP_CATEGORIES_PROMPT = "Skip categories already specified. Change them? (y/N) "
paired = await lounge_controller.pair(pairing_code) ENTER_SKIP_CATEGORIES_PROMPT = (
if not paired: "Enter skip categories (space or comma sepparated) Options: [sponsor,"
print("Failed to pair device") " selfpromo, exclusive_access, interaction, poi_highlight, intro, outro,"
return " preview, filler, music_offtopic]:\n"
device = { )
"screen_id": lounge_controller.auth.screen_id, WHITELIST_CHANNELS_PROMPT = (
"name": lounge_controller.screen_name, "Do you want to whitelist any channels from being ad-blocked? (y/N) "
} )
print(f"Paired device: {device['name']}") SEARCH_CHANNEL_PROMPT = 'Enter a channel name or "/exit" to exit: '
return device SELECT_CHANNEL_PROMPT = "Select one option of the above [0-6]: "
except Exception as e: ENTER_CHANNEL_ID_PROMPT = "Enter a channel ID: "
print(f"Failed to pair device: {e}") ENTER_CUSTOM_CHANNEL_NAME_PROMPT = "Enter the channel name: "
return REPORT_SKIPPED_SEGMENTS_PROMPT = (
"Do you want to report skipped segments to sponsorblock. Only the segment"
" UUID will be sent? (Y/n) "
def main(config, debug: bool) -> None: )
print("Welcome to the iSponsorBlockTV cli setup wizard") MUTE_ADS_PROMPT = "Do you want to mute native YouTube ads automatically? (y/N) "
loop = asyncio.get_event_loop_policy().get_event_loop() SKIP_ADS_PROMPT = "Do you want to skip native YouTube ads automatically? (y/N) "
web_session = aiohttp.ClientSession() AUTOPLAY_PROMPT = "Do you want to enable autoplay? (Y/n) "
if debug:
loop.set_debug(True)
asyncio.set_event_loop(loop) def get_yn_input(prompt):
if hasattr(config, "atvs"): while choice := input(prompt):
print( if choice.lower() in ["y", "n"]:
"The atvs config option is deprecated and has stopped working. Please read" return choice.lower()
" this for more information on how to upgrade to V2:" print("Invalid input. Please enter 'y' or 'n'.")
" \nhttps://github.com/dmunozv04/iSponsorBlockTV/wiki/Migrate-from-V1-to-V2"
)
if ( async def pair_device():
input( try:
"Do you want to remove the legacy 'atvs' entry (the app won't start" lounge_controller = ytlounge.YtLoungeApi("iSponsorBlockTV")
" with it present)? (y/n) " pairing_code = input(PAIRING_CODE_PROMPT)
) pairing_code = int(
== "y" pairing_code.replace("-", "").replace(" ", "")
): ) # remove dashes and spaces
del config["atvs"] print("Pairing...")
devices = config.devices paired = await lounge_controller.pair(pairing_code)
while not input(f"Paired with {len(devices)} Device(s). Add more? (y/n) ") == "n": if not paired:
task = loop.create_task(pair_device(web_session)) print("Failed to pair device")
loop.run_until_complete(task) return
device = task.result() device = {
if device: "screen_id": lounge_controller.auth.screen_id,
devices.append(device) "name": lounge_controller.screen_name,
config.devices = devices }
print(f"Paired device: {device['name']}")
apikey = config.apikey return device
if apikey: except Exception as e:
if input("API key already specified. Change it? (y/n) ") == "y": print(f"Failed to pair device: {e}")
apikey = input("Enter your API key: ") return
else:
if (
input( def main(config, debug: bool) -> None:
"API key only needed for the channel whitelist function. Add it? (y/n) " print("Welcome to the iSponsorBlockTV cli setup wizard")
) loop = asyncio.get_event_loop_policy().get_event_loop()
== "y" web_session = aiohttp.ClientSession()
): if debug:
print( loop.set_debug(True)
"Get youtube apikey here:" asyncio.set_event_loop(loop)
" https://developers.google.com/youtube/registering_an_application" if hasattr(config, "atvs"):
) print(
apikey = input("Enter your API key: ") "The atvs config option is deprecated and has stopped working. Please read"
config.apikey = apikey " this for more information on how to upgrade to V2:"
" \nhttps://github.com/dmunozv04/iSponsorBlockTV/wiki/Migrate-from-V1-to-V2"
skip_categories = config.skip_categories )
if skip_categories: choice = get_yn_input(ATVS_REMOVAL_PROMPT)
if input("Skip categories already specified. Change them? (y/n) ") == "y": if choice == "y":
categories = input( del config["atvs"]
"Enter skip categories (space or comma sepparated) Options: [sponsor"
" selfpromo exclusive_access interaction poi_highlight intro outro" devices = config.devices
" preview filler music_offtopic]:\n" choice = get_yn_input(ADD_MORE_DEVICES_PROMPT.format(num_devices=len(devices)))
) while choice == "y":
skip_categories = categories.replace(",", " ").split(" ") task = loop.create_task(pair_device())
skip_categories = [ loop.run_until_complete(task)
x for x in skip_categories if x != "" device = task.result()
] # Remove empty strings if device:
else: devices.append(device)
categories = input( choice = get_yn_input(ADD_MORE_DEVICES_PROMPT.format(num_devices=len(devices)))
"Enter skip categories (space or comma sepparated) Options: [sponsor," config.devices = devices
" selfpromo, exclusive_access, interaction, poi_highlight, intro, outro,"
" preview, filler, music_offtopic:\n" apikey = config.apikey
) if apikey:
skip_categories = categories.replace(",", " ").split(" ") choice = get_yn_input(CHANGE_API_KEY_PROMPT)
skip_categories = [ if choice == "y":
x for x in skip_categories if x != "" apikey = input(ENTER_API_KEY_PROMPT)
] # Remove empty strings else:
config.skip_categories = skip_categories choice = get_yn_input(ADD_API_KEY_PROMPT)
if choice == "y":
channel_whitelist = config.channel_whitelist print(
if ( "Get youtube apikey here:"
input("Do you want to whitelist any channels from being ad-blocked? (y/n) ") " https://developers.google.com/youtube/registering_an_application"
== "y" )
): apikey = input(ENTER_API_KEY_PROMPT)
if not apikey: config.apikey = apikey
print(
"WARNING: You need to specify an API key to use this function," skip_categories = config.skip_categories
" otherwise the program will fail to start.\nYou can add one by" if skip_categories:
" re-running this setup wizard." choice = get_yn_input(CHANGE_SKIP_CATEGORIES_PROMPT)
) if choice == "y":
api_helper = api_helpers.ApiHelper(config, web_session) categories = input(ENTER_SKIP_CATEGORIES_PROMPT)
while True: skip_categories = categories.replace(",", " ").split(" ")
channel_info = {} skip_categories = [
channel = input('Enter a channel name or "/exit" to exit: ') x for x in skip_categories if x != ""
if channel == "/exit": ] # Remove empty strings
break else:
categories = input(ENTER_SKIP_CATEGORIES_PROMPT)
task = loop.create_task( skip_categories = categories.replace(",", " ").split(" ")
api_helper.search_channels(channel, apikey, web_session) skip_categories = [
) x for x in skip_categories if x != ""
loop.run_until_complete(task) ] # Remove empty strings
results = task.result() config.skip_categories = skip_categories
if len(results) == 0:
print("No channels found") channel_whitelist = config.channel_whitelist
continue choice = get_yn_input(WHITELIST_CHANNELS_PROMPT)
if choice == "y":
for i, item in enumerate(results): if not apikey:
print(f"{i}: {item[1]} - Subs: {item[2]}") print(
print("5: Enter a custom channel ID") "WARNING: You need to specify an API key to use this function,"
print("6: Go back") " otherwise the program will fail to start.\nYou can add one by"
" re-running this setup wizard."
choice = -1 )
choice = input("Select one option of the above [0-6]: ") api_helper = api_helpers.ApiHelper(config, web_session)
while choice not in [str(x) for x in range(7)]: while True:
print("Invalid choice") channel_info = {}
choice = input("Select one option of the above [0-6]: ") channel = input(SEARCH_CHANNEL_PROMPT)
if channel == "/exit":
if choice == "5": break
channel_info["id"] = input("Enter a channel ID: ")
channel_info["name"] = input("Enter the channel name: ") task = loop.create_task(
channel_whitelist.append(channel_info) api_helper.search_channels(channel, apikey, web_session)
continue )
if choice == "6": loop.run_until_complete(task)
continue results = task.result()
if len(results) == 0:
channel_info["id"] = results[int(choice)][0] print("No channels found")
channel_info["name"] = results[int(choice)][1] continue
channel_whitelist.append(channel_info)
# Close web session asynchronously for i, item in enumerate(results):
print(f"{i}: {item[1]} - Subs: {item[2]}")
config.channel_whitelist = channel_whitelist print("5: Enter a custom channel ID")
print("6: Go back")
config.skip_count_tracking = (
not input( while choice := input(SELECT_CHANNEL_PROMPT):
"Do you want to report skipped segments to sponsorblock. Only the segment" if choice in [str(x) for x in range(7)]:
" UUID will be sent? (y/n) " break
) print("Invalid choice")
== "n"
) if choice == "5":
channel_info["id"] = input(ENTER_CHANNEL_ID_PROMPT)
config.auto_play = not input("Do you want to enable autoplay? (y/n) ") == "n" channel_info["name"] = input(ENTER_CUSTOM_CHANNEL_NAME_PROMPT)
print("Config finished") channel_whitelist.append(channel_info)
config.save() continue
loop.run_until_complete(web_session.close()) if choice == "6":
continue
channel_info["id"] = results[int(choice)][0]
channel_info["name"] = results[int(choice)][1]
channel_whitelist.append(channel_info)
# Close web session asynchronously
config.channel_whitelist = channel_whitelist
choice = get_yn_input(REPORT_SKIPPED_SEGMENTS_PROMPT)
config.skip_count_tracking = choice != "n"
choice = get_yn_input(MUTE_ADS_PROMPT)
config.mute_ads = choice == "y"
choice = get_yn_input(SKIP_ADS_PROMPT)
config.skip_ads = choice == "y"
choice = get_yn_input(AUTOPLAY_PROMPT)
config.auto_play = choice != "n"
print("Config finished")
config.save()
loop.run_until_complete(web_session.close())

View File

@@ -363,3 +363,9 @@ MigrationScreen {
width: 1fr; width: 1fr;
content-align: center middle; content-align: center middle;
} }
/* Autoplay */
#autoplay-container{
padding: 1;
height: auto;
}

View File

@@ -864,11 +864,12 @@ class AutoPlayManager(Vertical):
classes="subtitle", classes="subtitle",
id="autoplay-subtitle", id="autoplay-subtitle",
) )
yield Checkbox( with Horizontal(id="autoplay-container"):
value=self.config.auto_play, yield Checkbox(
id="autoplay-switch", value=self.config.auto_play,
label="Enable autoplay", id="autoplay-switch",
) label="Enable autoplay",
)
@on(Checkbox.Changed, "#autoplay-switch") @on(Checkbox.Changed, "#autoplay-switch")
def changed_skip(self, event: Checkbox.Changed): def changed_skip(self, event: Checkbox.Changed):