|
|
|
@@ -4,15 +4,51 @@ import aiohttp
|
|
|
|
|
|
|
|
|
|
|
|
from . import api_helpers, ytlounge
|
|
|
|
from . import api_helpers, ytlounge
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Constants for user input prompts
|
|
|
|
|
|
|
|
ATVS_REMOVAL_PROMPT = (
|
|
|
|
|
|
|
|
"Do you want to remove the legacy 'atvs' entry (the app won't start"
|
|
|
|
|
|
|
|
" with it present)? (y/N) "
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
PAIRING_CODE_PROMPT = "Enter pairing code (found in Settings - Link with TV code): "
|
|
|
|
|
|
|
|
ADD_MORE_DEVICES_PROMPT = "Paired with {num_devices} Device(s). Add more? (y/N) "
|
|
|
|
|
|
|
|
CHANGE_API_KEY_PROMPT = "API key already specified. Change it? (y/N) "
|
|
|
|
|
|
|
|
ADD_API_KEY_PROMPT = (
|
|
|
|
|
|
|
|
"API key only needed for the channel whitelist function. Add it? (y/N) "
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
ENTER_API_KEY_PROMPT = "Enter your API key: "
|
|
|
|
|
|
|
|
CHANGE_SKIP_CATEGORIES_PROMPT = "Skip categories already specified. Change them? (y/N) "
|
|
|
|
|
|
|
|
ENTER_SKIP_CATEGORIES_PROMPT = (
|
|
|
|
|
|
|
|
"Enter skip categories (space or comma sepparated) Options: [sponsor,"
|
|
|
|
|
|
|
|
" selfpromo, exclusive_access, interaction, poi_highlight, intro, outro,"
|
|
|
|
|
|
|
|
" preview, filler, music_offtopic]:\n"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
WHITELIST_CHANNELS_PROMPT = (
|
|
|
|
|
|
|
|
"Do you want to whitelist any channels from being ad-blocked? (y/N) "
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
SEARCH_CHANNEL_PROMPT = 'Enter a channel name or "/exit" to exit: '
|
|
|
|
|
|
|
|
SELECT_CHANNEL_PROMPT = "Select one option of the above [0-6]: "
|
|
|
|
|
|
|
|
ENTER_CHANNEL_ID_PROMPT = "Enter a channel ID: "
|
|
|
|
|
|
|
|
ENTER_CUSTOM_CHANNEL_NAME_PROMPT = "Enter the channel name: "
|
|
|
|
|
|
|
|
REPORT_SKIPPED_SEGMENTS_PROMPT = (
|
|
|
|
|
|
|
|
"Do you want to report skipped segments to sponsorblock. Only the segment"
|
|
|
|
|
|
|
|
" UUID will be sent? (Y/n) "
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
MUTE_ADS_PROMPT = "Do you want to mute native YouTube ads automatically? (y/N) "
|
|
|
|
|
|
|
|
SKIP_ADS_PROMPT = "Do you want to skip native YouTube ads automatically? (y/N) "
|
|
|
|
|
|
|
|
AUTOPLAY_PROMPT = "Do you want to enable autoplay? (Y/n) "
|
|
|
|
|
|
|
|
|
|
|
|
async def pair_device(web_session):
|
|
|
|
|
|
|
|
|
|
|
|
def get_yn_input(prompt):
|
|
|
|
|
|
|
|
while choice := input(prompt):
|
|
|
|
|
|
|
|
if choice.lower() in ["y", "n"]:
|
|
|
|
|
|
|
|
return choice.lower()
|
|
|
|
|
|
|
|
print("Invalid input. Please enter 'y' or 'n'.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def pair_device():
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
lounge_controller = ytlounge.YtLoungeApi(
|
|
|
|
lounge_controller = ytlounge.YtLoungeApi("iSponsorBlockTV")
|
|
|
|
"iSponsorBlockTV", web_session=web_session
|
|
|
|
pairing_code = input(PAIRING_CODE_PROMPT)
|
|
|
|
)
|
|
|
|
|
|
|
|
pairing_code = input(
|
|
|
|
|
|
|
|
"Enter pairing code (found in Settings - Link with TV code): "
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
pairing_code = int(
|
|
|
|
pairing_code = int(
|
|
|
|
pairing_code.replace("-", "").replace(" ", "")
|
|
|
|
pairing_code.replace("-", "").replace(" ", "")
|
|
|
|
) # remove dashes and spaces
|
|
|
|
) # remove dashes and spaces
|
|
|
|
@@ -45,59 +81,47 @@ def main(config, debug: bool) -> None:
|
|
|
|
" this for more information on how to upgrade to V2:"
|
|
|
|
" this for more information on how to upgrade to V2:"
|
|
|
|
" \nhttps://github.com/dmunozv04/iSponsorBlockTV/wiki/Migrate-from-V1-to-V2"
|
|
|
|
" \nhttps://github.com/dmunozv04/iSponsorBlockTV/wiki/Migrate-from-V1-to-V2"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if (
|
|
|
|
choice = get_yn_input(ATVS_REMOVAL_PROMPT)
|
|
|
|
input(
|
|
|
|
if choice == "y":
|
|
|
|
"Do you want to remove the legacy 'atvs' entry (the app won't start"
|
|
|
|
|
|
|
|
" with it present)? (y/n) "
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
== "y"
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
del config["atvs"]
|
|
|
|
del config["atvs"]
|
|
|
|
|
|
|
|
|
|
|
|
devices = config.devices
|
|
|
|
devices = config.devices
|
|
|
|
while not input(f"Paired with {len(devices)} Device(s). Add more? (y/n) ") == "n":
|
|
|
|
choice = get_yn_input(ADD_MORE_DEVICES_PROMPT.format(num_devices=len(devices)))
|
|
|
|
task = loop.create_task(pair_device(web_session))
|
|
|
|
while choice == "y":
|
|
|
|
|
|
|
|
task = loop.create_task(pair_device())
|
|
|
|
loop.run_until_complete(task)
|
|
|
|
loop.run_until_complete(task)
|
|
|
|
device = task.result()
|
|
|
|
device = task.result()
|
|
|
|
if device:
|
|
|
|
if device:
|
|
|
|
devices.append(device)
|
|
|
|
devices.append(device)
|
|
|
|
|
|
|
|
choice = get_yn_input(ADD_MORE_DEVICES_PROMPT.format(num_devices=len(devices)))
|
|
|
|
config.devices = devices
|
|
|
|
config.devices = devices
|
|
|
|
|
|
|
|
|
|
|
|
apikey = config.apikey
|
|
|
|
apikey = config.apikey
|
|
|
|
if apikey:
|
|
|
|
if apikey:
|
|
|
|
if input("API key already specified. Change it? (y/n) ") == "y":
|
|
|
|
choice = get_yn_input(CHANGE_API_KEY_PROMPT)
|
|
|
|
apikey = input("Enter your API key: ")
|
|
|
|
if choice == "y":
|
|
|
|
|
|
|
|
apikey = input(ENTER_API_KEY_PROMPT)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
if (
|
|
|
|
choice = get_yn_input(ADD_API_KEY_PROMPT)
|
|
|
|
input(
|
|
|
|
if choice == "y":
|
|
|
|
"API key only needed for the channel whitelist function. Add it? (y/n) "
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
== "y"
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
print(
|
|
|
|
print(
|
|
|
|
"Get youtube apikey here:"
|
|
|
|
"Get youtube apikey here:"
|
|
|
|
" https://developers.google.com/youtube/registering_an_application"
|
|
|
|
" https://developers.google.com/youtube/registering_an_application"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
apikey = input("Enter your API key: ")
|
|
|
|
apikey = input(ENTER_API_KEY_PROMPT)
|
|
|
|
config.apikey = apikey
|
|
|
|
config.apikey = apikey
|
|
|
|
|
|
|
|
|
|
|
|
skip_categories = config.skip_categories
|
|
|
|
skip_categories = config.skip_categories
|
|
|
|
if skip_categories:
|
|
|
|
if skip_categories:
|
|
|
|
if input("Skip categories already specified. Change them? (y/n) ") == "y":
|
|
|
|
choice = get_yn_input(CHANGE_SKIP_CATEGORIES_PROMPT)
|
|
|
|
categories = input(
|
|
|
|
if choice == "y":
|
|
|
|
"Enter skip categories (space or comma sepparated) Options: [sponsor"
|
|
|
|
categories = input(ENTER_SKIP_CATEGORIES_PROMPT)
|
|
|
|
" selfpromo exclusive_access interaction poi_highlight intro outro"
|
|
|
|
|
|
|
|
" preview filler music_offtopic]:\n"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
skip_categories = categories.replace(",", " ").split(" ")
|
|
|
|
skip_categories = categories.replace(",", " ").split(" ")
|
|
|
|
skip_categories = [
|
|
|
|
skip_categories = [
|
|
|
|
x for x in skip_categories if x != ""
|
|
|
|
x for x in skip_categories if x != ""
|
|
|
|
] # Remove empty strings
|
|
|
|
] # Remove empty strings
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
categories = input(
|
|
|
|
categories = input(ENTER_SKIP_CATEGORIES_PROMPT)
|
|
|
|
"Enter skip categories (space or comma sepparated) Options: [sponsor,"
|
|
|
|
|
|
|
|
" selfpromo, exclusive_access, interaction, poi_highlight, intro, outro,"
|
|
|
|
|
|
|
|
" preview, filler, music_offtopic:\n"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
skip_categories = categories.replace(",", " ").split(" ")
|
|
|
|
skip_categories = categories.replace(",", " ").split(" ")
|
|
|
|
skip_categories = [
|
|
|
|
skip_categories = [
|
|
|
|
x for x in skip_categories if x != ""
|
|
|
|
x for x in skip_categories if x != ""
|
|
|
|
@@ -105,10 +129,8 @@ def main(config, debug: bool) -> None:
|
|
|
|
config.skip_categories = skip_categories
|
|
|
|
config.skip_categories = skip_categories
|
|
|
|
|
|
|
|
|
|
|
|
channel_whitelist = config.channel_whitelist
|
|
|
|
channel_whitelist = config.channel_whitelist
|
|
|
|
if (
|
|
|
|
choice = get_yn_input(WHITELIST_CHANNELS_PROMPT)
|
|
|
|
input("Do you want to whitelist any channels from being ad-blocked? (y/n) ")
|
|
|
|
if choice == "y":
|
|
|
|
== "y"
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
if not apikey:
|
|
|
|
if not apikey:
|
|
|
|
print(
|
|
|
|
print(
|
|
|
|
"WARNING: You need to specify an API key to use this function,"
|
|
|
|
"WARNING: You need to specify an API key to use this function,"
|
|
|
|
@@ -118,7 +140,7 @@ def main(config, debug: bool) -> None:
|
|
|
|
api_helper = api_helpers.ApiHelper(config, web_session)
|
|
|
|
api_helper = api_helpers.ApiHelper(config, web_session)
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
channel_info = {}
|
|
|
|
channel_info = {}
|
|
|
|
channel = input('Enter a channel name or "/exit" to exit: ')
|
|
|
|
channel = input(SEARCH_CHANNEL_PROMPT)
|
|
|
|
if channel == "/exit":
|
|
|
|
if channel == "/exit":
|
|
|
|
break
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
@@ -136,15 +158,14 @@ def main(config, debug: bool) -> None:
|
|
|
|
print("5: Enter a custom channel ID")
|
|
|
|
print("5: Enter a custom channel ID")
|
|
|
|
print("6: Go back")
|
|
|
|
print("6: Go back")
|
|
|
|
|
|
|
|
|
|
|
|
choice = -1
|
|
|
|
while choice := input(SELECT_CHANNEL_PROMPT):
|
|
|
|
choice = input("Select one option of the above [0-6]: ")
|
|
|
|
if choice in [str(x) for x in range(7)]:
|
|
|
|
while choice not in [str(x) for x in range(7)]:
|
|
|
|
break
|
|
|
|
print("Invalid choice")
|
|
|
|
print("Invalid choice")
|
|
|
|
choice = input("Select one option of the above [0-6]: ")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if choice == "5":
|
|
|
|
if choice == "5":
|
|
|
|
channel_info["id"] = input("Enter a channel ID: ")
|
|
|
|
channel_info["id"] = input(ENTER_CHANNEL_ID_PROMPT)
|
|
|
|
channel_info["name"] = input("Enter the channel name: ")
|
|
|
|
channel_info["name"] = input(ENTER_CUSTOM_CHANNEL_NAME_PROMPT)
|
|
|
|
channel_whitelist.append(channel_info)
|
|
|
|
channel_whitelist.append(channel_info)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
if choice == "6":
|
|
|
|
if choice == "6":
|
|
|
|
@@ -157,15 +178,18 @@ def main(config, debug: bool) -> None:
|
|
|
|
|
|
|
|
|
|
|
|
config.channel_whitelist = channel_whitelist
|
|
|
|
config.channel_whitelist = channel_whitelist
|
|
|
|
|
|
|
|
|
|
|
|
config.skip_count_tracking = (
|
|
|
|
choice = get_yn_input(REPORT_SKIPPED_SEGMENTS_PROMPT)
|
|
|
|
not input(
|
|
|
|
config.skip_count_tracking = choice != "n"
|
|
|
|
"Do you want to report skipped segments to sponsorblock. Only the segment"
|
|
|
|
|
|
|
|
" UUID will be sent? (y/n) "
|
|
|
|
choice = get_yn_input(MUTE_ADS_PROMPT)
|
|
|
|
)
|
|
|
|
config.mute_ads = choice == "y"
|
|
|
|
== "n"
|
|
|
|
|
|
|
|
)
|
|
|
|
choice = get_yn_input(SKIP_ADS_PROMPT)
|
|
|
|
|
|
|
|
config.skip_ads = choice == "y"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
choice = get_yn_input(AUTOPLAY_PROMPT)
|
|
|
|
|
|
|
|
config.auto_play = choice != "n"
|
|
|
|
|
|
|
|
|
|
|
|
config.auto_play = not input("Do you want to enable autoplay? (y/n) ") == "n"
|
|
|
|
|
|
|
|
print("Config finished")
|
|
|
|
print("Config finished")
|
|
|
|
config.save()
|
|
|
|
config.save()
|
|
|
|
loop.run_until_complete(web_session.close())
|
|
|
|
loop.run_until_complete(web_session.close())
|
|
|
|
|