mirror of
https://github.com/dmunozv04/iSponsorBlockTV.git
synced 2025-12-07 20:36:44 +03:00
Compare commits
2 Commits
1f9f8ab0b1
...
add-custom
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e00c62af1 | ||
|
|
1567a33e51 |
@@ -18,5 +18,6 @@
|
|||||||
{"id": "",
|
{"id": "",
|
||||||
"name": ""
|
"name": ""
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"api_server": "https://sponsor.ajay.app"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ class ApiHelper:
|
|||||||
self.skip_count_tracking = config.skip_count_tracking
|
self.skip_count_tracking = config.skip_count_tracking
|
||||||
self.web_session = web_session
|
self.web_session = web_session
|
||||||
self.num_devices = len(config.devices)
|
self.num_devices = len(config.devices)
|
||||||
|
self.api_server = config.api_server
|
||||||
|
|
||||||
# Not used anymore, maybe it can stay here a little longer
|
# Not used anymore, maybe it can stay here a little longer
|
||||||
@AsyncLRU(maxsize=10)
|
@AsyncLRU(maxsize=10)
|
||||||
@@ -130,7 +131,7 @@ class ApiHelper:
|
|||||||
"service": constants.SponsorBlock_service,
|
"service": constants.SponsorBlock_service,
|
||||||
}
|
}
|
||||||
headers = {"Accept": "application/json"}
|
headers = {"Accept": "application/json"}
|
||||||
url = constants.SponsorBlock_api + "skipSegments/" + vid_id_hashed
|
url = self.api_server + "/api/skipSegments/" + vid_id_hashed
|
||||||
async with self.web_session.get(
|
async with self.web_session.get(
|
||||||
url, headers=headers, params=params
|
url, headers=headers, params=params
|
||||||
) as response:
|
) as response:
|
||||||
@@ -201,7 +202,7 @@ class ApiHelper:
|
|||||||
Lets the contributor know that someone skipped the segment (thanks)"""
|
Lets the contributor know that someone skipped the segment (thanks)"""
|
||||||
if self.skip_count_tracking:
|
if self.skip_count_tracking:
|
||||||
for i in uuids:
|
for i in uuids:
|
||||||
url = constants.SponsorBlock_api + "viewedVideoSponsorTime/"
|
url = self.api_server + "/api/viewedVideoSponsorTime/"
|
||||||
params = {"UUID": i}
|
params = {"UUID": i}
|
||||||
await self.web_session.post(url, params=params)
|
await self.web_session.post(url, params=params)
|
||||||
|
|
||||||
|
|||||||
@@ -1,195 +1,202 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
from . import api_helpers, ytlounge
|
from . import api_helpers, ytlounge
|
||||||
|
|
||||||
# Constants for user input prompts
|
# Constants for user input prompts
|
||||||
ATVS_REMOVAL_PROMPT = (
|
ATVS_REMOVAL_PROMPT = (
|
||||||
"Do you want to remove the legacy 'atvs' entry (the app won't start"
|
"Do you want to remove the legacy 'atvs' entry (the app won't start"
|
||||||
" with it present)? (y/N) "
|
" with it present)? (y/N) "
|
||||||
)
|
)
|
||||||
PAIRING_CODE_PROMPT = "Enter pairing code (found in Settings - Link with TV code): "
|
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) "
|
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) "
|
CHANGE_API_KEY_PROMPT = "API key already specified. Change it? (y/N) "
|
||||||
ADD_API_KEY_PROMPT = (
|
ADD_API_KEY_PROMPT = (
|
||||||
"API key only needed for the channel whitelist function. Add it? (y/N) "
|
"API key only needed for the channel whitelist function. Add it? (y/N) "
|
||||||
)
|
)
|
||||||
ENTER_API_KEY_PROMPT = "Enter your API key: "
|
ENTER_API_KEY_PROMPT = "Enter your API key: "
|
||||||
CHANGE_SKIP_CATEGORIES_PROMPT = "Skip categories already specified. Change them? (y/N) "
|
CHANGE_SKIP_CATEGORIES_PROMPT = "Skip categories already specified. Change them? (y/N) "
|
||||||
ENTER_SKIP_CATEGORIES_PROMPT = (
|
ENTER_SKIP_CATEGORIES_PROMPT = (
|
||||||
"Enter skip categories (space or comma sepparated) Options: [sponsor,"
|
"Enter skip categories (space or comma sepparated) Options: [sponsor,"
|
||||||
" selfpromo, exclusive_access, interaction, poi_highlight, intro, outro,"
|
" selfpromo, exclusive_access, interaction, poi_highlight, intro, outro,"
|
||||||
" preview, filler, music_offtopic]:\n"
|
" preview, filler, music_offtopic]:\n"
|
||||||
)
|
)
|
||||||
WHITELIST_CHANNELS_PROMPT = (
|
WHITELIST_CHANNELS_PROMPT = (
|
||||||
"Do you want to whitelist any channels from being ad-blocked? (y/N) "
|
"Do you want to whitelist any channels from being ad-blocked? (y/N) "
|
||||||
)
|
)
|
||||||
SEARCH_CHANNEL_PROMPT = 'Enter a channel name or "/exit" to exit: '
|
SEARCH_CHANNEL_PROMPT = 'Enter a channel name or "/exit" to exit: '
|
||||||
SELECT_CHANNEL_PROMPT = "Select one option of the above [0-6]: "
|
SELECT_CHANNEL_PROMPT = "Select one option of the above [0-6]: "
|
||||||
ENTER_CHANNEL_ID_PROMPT = "Enter a channel ID: "
|
ENTER_CHANNEL_ID_PROMPT = "Enter a channel ID: "
|
||||||
ENTER_CUSTOM_CHANNEL_NAME_PROMPT = "Enter the channel name: "
|
ENTER_CUSTOM_CHANNEL_NAME_PROMPT = "Enter the channel name: "
|
||||||
REPORT_SKIPPED_SEGMENTS_PROMPT = (
|
REPORT_SKIPPED_SEGMENTS_PROMPT = (
|
||||||
"Do you want to report skipped segments to sponsorblock. Only the segment"
|
"Do you want to report skipped segments to sponsorblock. Only the segment"
|
||||||
" UUID will be sent? (Y/n) "
|
" UUID will be sent? (Y/n) "
|
||||||
)
|
)
|
||||||
MUTE_ADS_PROMPT = "Do you want to mute native YouTube ads automatically? (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) "
|
SKIP_ADS_PROMPT = "Do you want to skip native YouTube ads automatically? (y/N) "
|
||||||
AUTOPLAY_PROMPT = "Do you want to enable autoplay? (Y/n) "
|
AUTOPLAY_PROMPT = "Do you want to enable autoplay? (Y/n) "
|
||||||
|
ENTER_API_SERVER_PROMPT = (
|
||||||
|
"Enter the custom API server URL (leave blank to use default): "
|
||||||
def get_yn_input(prompt):
|
)
|
||||||
while choice := input(prompt):
|
|
||||||
if choice.lower() in ["y", "n"]:
|
|
||||||
return choice.lower()
|
def get_yn_input(prompt):
|
||||||
print("Invalid input. Please enter 'y' or 'n'.")
|
while choice := input(prompt):
|
||||||
|
if choice.lower() in ["y", "n"]:
|
||||||
|
return choice.lower()
|
||||||
async def pair_device():
|
print("Invalid input. Please enter 'y' or 'n'.")
|
||||||
try:
|
|
||||||
lounge_controller = ytlounge.YtLoungeApi("iSponsorBlockTV")
|
|
||||||
pairing_code = input(PAIRING_CODE_PROMPT)
|
async def pair_device():
|
||||||
pairing_code = int(
|
try:
|
||||||
pairing_code.replace("-", "").replace(" ", "")
|
lounge_controller = ytlounge.YtLoungeApi("iSponsorBlockTV")
|
||||||
) # remove dashes and spaces
|
pairing_code = input(PAIRING_CODE_PROMPT)
|
||||||
print("Pairing...")
|
pairing_code = int(
|
||||||
paired = await lounge_controller.pair(pairing_code)
|
pairing_code.replace("-", "").replace(" ", "")
|
||||||
if not paired:
|
) # remove dashes and spaces
|
||||||
print("Failed to pair device")
|
print("Pairing...")
|
||||||
return
|
paired = await lounge_controller.pair(pairing_code)
|
||||||
device = {
|
if not paired:
|
||||||
"screen_id": lounge_controller.auth.screen_id,
|
print("Failed to pair device")
|
||||||
"name": lounge_controller.screen_name,
|
return
|
||||||
}
|
device = {
|
||||||
print(f"Paired device: {device['name']}")
|
"screen_id": lounge_controller.auth.screen_id,
|
||||||
return device
|
"name": lounge_controller.screen_name,
|
||||||
except Exception as e:
|
}
|
||||||
print(f"Failed to pair device: {e}")
|
print(f"Paired device: {device['name']}")
|
||||||
return
|
return device
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to pair device: {e}")
|
||||||
def main(config, debug: bool) -> None:
|
return
|
||||||
print("Welcome to the iSponsorBlockTV cli setup wizard")
|
|
||||||
loop = asyncio.get_event_loop_policy().get_event_loop()
|
|
||||||
web_session = aiohttp.ClientSession()
|
def main(config, debug: bool) -> None:
|
||||||
if debug:
|
print("Welcome to the iSponsorBlockTV cli setup wizard")
|
||||||
loop.set_debug(True)
|
loop = asyncio.get_event_loop_policy().get_event_loop()
|
||||||
asyncio.set_event_loop(loop)
|
web_session = aiohttp.ClientSession()
|
||||||
if hasattr(config, "atvs"):
|
if debug:
|
||||||
print(
|
loop.set_debug(True)
|
||||||
"The atvs config option is deprecated and has stopped working. Please read"
|
asyncio.set_event_loop(loop)
|
||||||
" this for more information on how to upgrade to V2:"
|
if hasattr(config, "atvs"):
|
||||||
" \nhttps://github.com/dmunozv04/iSponsorBlockTV/wiki/Migrate-from-V1-to-V2"
|
print(
|
||||||
)
|
"The atvs config option is deprecated and has stopped working. Please read"
|
||||||
choice = get_yn_input(ATVS_REMOVAL_PROMPT)
|
" this for more information on how to upgrade to V2:"
|
||||||
if choice == "y":
|
" \nhttps://github.com/dmunozv04/iSponsorBlockTV/wiki/Migrate-from-V1-to-V2"
|
||||||
del config["atvs"]
|
)
|
||||||
|
choice = get_yn_input(ATVS_REMOVAL_PROMPT)
|
||||||
devices = config.devices
|
if choice == "y":
|
||||||
choice = get_yn_input(ADD_MORE_DEVICES_PROMPT.format(num_devices=len(devices)))
|
del config["atvs"]
|
||||||
while choice == "y":
|
|
||||||
task = loop.create_task(pair_device())
|
devices = config.devices
|
||||||
loop.run_until_complete(task)
|
choice = get_yn_input(ADD_MORE_DEVICES_PROMPT.format(num_devices=len(devices)))
|
||||||
device = task.result()
|
while choice == "y":
|
||||||
if device:
|
task = loop.create_task(pair_device())
|
||||||
devices.append(device)
|
loop.run_until_complete(task)
|
||||||
choice = get_yn_input(ADD_MORE_DEVICES_PROMPT.format(num_devices=len(devices)))
|
device = task.result()
|
||||||
config.devices = devices
|
if device:
|
||||||
|
devices.append(device)
|
||||||
apikey = config.apikey
|
choice = get_yn_input(ADD_MORE_DEVICES_PROMPT.format(num_devices=len(devices)))
|
||||||
if apikey:
|
config.devices = devices
|
||||||
choice = get_yn_input(CHANGE_API_KEY_PROMPT)
|
|
||||||
if choice == "y":
|
apikey = config.apikey
|
||||||
apikey = input(ENTER_API_KEY_PROMPT)
|
if apikey:
|
||||||
else:
|
choice = get_yn_input(CHANGE_API_KEY_PROMPT)
|
||||||
choice = get_yn_input(ADD_API_KEY_PROMPT)
|
if choice == "y":
|
||||||
if choice == "y":
|
apikey = input(ENTER_API_KEY_PROMPT)
|
||||||
print(
|
else:
|
||||||
"Get youtube apikey here:"
|
choice = get_yn_input(ADD_API_KEY_PROMPT)
|
||||||
" https://developers.google.com/youtube/registering_an_application"
|
if choice == "y":
|
||||||
)
|
print(
|
||||||
apikey = input(ENTER_API_KEY_PROMPT)
|
"Get youtube apikey here:"
|
||||||
config.apikey = apikey
|
" https://developers.google.com/youtube/registering_an_application"
|
||||||
|
)
|
||||||
skip_categories = config.skip_categories
|
apikey = input(ENTER_API_KEY_PROMPT)
|
||||||
if skip_categories:
|
config.apikey = apikey
|
||||||
choice = get_yn_input(CHANGE_SKIP_CATEGORIES_PROMPT)
|
|
||||||
if choice == "y":
|
skip_categories = config.skip_categories
|
||||||
categories = input(ENTER_SKIP_CATEGORIES_PROMPT)
|
if skip_categories:
|
||||||
skip_categories = categories.replace(",", " ").split(" ")
|
choice = get_yn_input(CHANGE_SKIP_CATEGORIES_PROMPT)
|
||||||
skip_categories = [
|
if choice == "y":
|
||||||
x for x in skip_categories if x != ""
|
categories = input(ENTER_SKIP_CATEGORIES_PROMPT)
|
||||||
] # Remove empty strings
|
skip_categories = categories.replace(",", " ").split(" ")
|
||||||
else:
|
skip_categories = [
|
||||||
categories = input(ENTER_SKIP_CATEGORIES_PROMPT)
|
x for x in skip_categories if x != ""
|
||||||
skip_categories = categories.replace(",", " ").split(" ")
|
] # Remove empty strings
|
||||||
skip_categories = [
|
else:
|
||||||
x for x in skip_categories if x != ""
|
categories = input(ENTER_SKIP_CATEGORIES_PROMPT)
|
||||||
] # Remove empty strings
|
skip_categories = categories.replace(",", " ").split(" ")
|
||||||
config.skip_categories = skip_categories
|
skip_categories = [
|
||||||
|
x for x in skip_categories if x != ""
|
||||||
channel_whitelist = config.channel_whitelist
|
] # Remove empty strings
|
||||||
choice = get_yn_input(WHITELIST_CHANNELS_PROMPT)
|
config.skip_categories = skip_categories
|
||||||
if choice == "y":
|
|
||||||
if not apikey:
|
channel_whitelist = config.channel_whitelist
|
||||||
print(
|
choice = get_yn_input(WHITELIST_CHANNELS_PROMPT)
|
||||||
"WARNING: You need to specify an API key to use this function,"
|
if choice == "y":
|
||||||
" otherwise the program will fail to start.\nYou can add one by"
|
if not apikey:
|
||||||
" re-running this setup wizard."
|
print(
|
||||||
)
|
"WARNING: You need to specify an API key to use this function,"
|
||||||
api_helper = api_helpers.ApiHelper(config, web_session)
|
" otherwise the program will fail to start.\nYou can add one by"
|
||||||
while True:
|
" re-running this setup wizard."
|
||||||
channel_info = {}
|
)
|
||||||
channel = input(SEARCH_CHANNEL_PROMPT)
|
api_helper = api_helpers.ApiHelper(config, web_session)
|
||||||
if channel == "/exit":
|
while True:
|
||||||
break
|
channel_info = {}
|
||||||
|
channel = input(SEARCH_CHANNEL_PROMPT)
|
||||||
task = loop.create_task(
|
if channel == "/exit":
|
||||||
api_helper.search_channels(channel, apikey, web_session)
|
break
|
||||||
)
|
|
||||||
loop.run_until_complete(task)
|
task = loop.create_task(
|
||||||
results = task.result()
|
api_helper.search_channels(channel, apikey, web_session)
|
||||||
if len(results) == 0:
|
)
|
||||||
print("No channels found")
|
loop.run_until_complete(task)
|
||||||
continue
|
results = task.result()
|
||||||
|
if len(results) == 0:
|
||||||
for i, item in enumerate(results):
|
print("No channels found")
|
||||||
print(f"{i}: {item[1]} - Subs: {item[2]}")
|
continue
|
||||||
print("5: Enter a custom channel ID")
|
|
||||||
print("6: Go back")
|
for i, item in enumerate(results):
|
||||||
|
print(f"{i}: {item[1]} - Subs: {item[2]}")
|
||||||
while choice := input(SELECT_CHANNEL_PROMPT):
|
print("5: Enter a custom channel ID")
|
||||||
if choice in [str(x) for x in range(7)]:
|
print("6: Go back")
|
||||||
break
|
|
||||||
print("Invalid choice")
|
while choice := input(SELECT_CHANNEL_PROMPT):
|
||||||
|
if choice in [str(x) for x in range(7)]:
|
||||||
if choice == "5":
|
break
|
||||||
channel_info["id"] = input(ENTER_CHANNEL_ID_PROMPT)
|
print("Invalid choice")
|
||||||
channel_info["name"] = input(ENTER_CUSTOM_CHANNEL_NAME_PROMPT)
|
|
||||||
channel_whitelist.append(channel_info)
|
if choice == "5":
|
||||||
continue
|
channel_info["id"] = input(ENTER_CHANNEL_ID_PROMPT)
|
||||||
if choice == "6":
|
channel_info["name"] = input(ENTER_CUSTOM_CHANNEL_NAME_PROMPT)
|
||||||
continue
|
channel_whitelist.append(channel_info)
|
||||||
|
continue
|
||||||
channel_info["id"] = results[int(choice)][0]
|
if choice == "6":
|
||||||
channel_info["name"] = results[int(choice)][1]
|
continue
|
||||||
channel_whitelist.append(channel_info)
|
|
||||||
# Close web session asynchronously
|
channel_info["id"] = results[int(choice)][0]
|
||||||
|
channel_info["name"] = results[int(choice)][1]
|
||||||
config.channel_whitelist = channel_whitelist
|
channel_whitelist.append(channel_info)
|
||||||
|
# Close web session asynchronously
|
||||||
choice = get_yn_input(REPORT_SKIPPED_SEGMENTS_PROMPT)
|
|
||||||
config.skip_count_tracking = choice != "n"
|
config.channel_whitelist = channel_whitelist
|
||||||
|
|
||||||
choice = get_yn_input(MUTE_ADS_PROMPT)
|
choice = get_yn_input(REPORT_SKIPPED_SEGMENTS_PROMPT)
|
||||||
config.mute_ads = choice == "y"
|
config.skip_count_tracking = choice != "n"
|
||||||
|
|
||||||
choice = get_yn_input(SKIP_ADS_PROMPT)
|
choice = get_yn_input(MUTE_ADS_PROMPT)
|
||||||
config.skip_ads = choice == "y"
|
config.mute_ads = choice == "y"
|
||||||
|
|
||||||
choice = get_yn_input(AUTOPLAY_PROMPT)
|
choice = get_yn_input(SKIP_ADS_PROMPT)
|
||||||
config.auto_play = choice != "n"
|
config.skip_ads = choice == "y"
|
||||||
|
|
||||||
print("Config finished")
|
choice = get_yn_input(AUTOPLAY_PROMPT)
|
||||||
config.save()
|
config.auto_play = choice != "n"
|
||||||
loop.run_until_complete(web_session.close())
|
|
||||||
|
api_server = input(ENTER_API_SERVER_PROMPT)
|
||||||
|
if api_server:
|
||||||
|
config.api_server = api_server
|
||||||
|
|
||||||
|
print("Config finished")
|
||||||
|
config.save()
|
||||||
|
loop.run_until_complete(web_session.close())
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ userAgent = "iSponsorBlockTV/0.1"
|
|||||||
SponsorBlock_service = "youtube"
|
SponsorBlock_service = "youtube"
|
||||||
SponsorBlock_actiontype = "skip"
|
SponsorBlock_actiontype = "skip"
|
||||||
|
|
||||||
SponsorBlock_api = "https://sponsor.ajay.app/api/"
|
|
||||||
Youtube_api = "https://www.googleapis.com/youtube/v3/"
|
Youtube_api = "https://www.googleapis.com/youtube/v3/"
|
||||||
|
|
||||||
skip_categories = (
|
skip_categories = (
|
||||||
@@ -20,5 +19,4 @@ skip_categories = (
|
|||||||
|
|
||||||
youtube_client_blacklist = ["TVHTML5_FOR_KIDS"]
|
youtube_client_blacklist = ["TVHTML5_FOR_KIDS"]
|
||||||
|
|
||||||
|
|
||||||
config_file_blacklist_keys = ["config_file", "data_dir"]
|
config_file_blacklist_keys = ["config_file", "data_dir"]
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class Config:
|
|||||||
self.mute_ads = False
|
self.mute_ads = False
|
||||||
self.skip_ads = False
|
self.skip_ads = False
|
||||||
self.auto_play = True
|
self.auto_play = True
|
||||||
|
self.api_server = "https://sponsor.ajay.app"
|
||||||
self.__load()
|
self.__load()
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
|||||||
@@ -876,6 +876,31 @@ class AutoPlayManager(Vertical):
|
|||||||
self.config.auto_play = event.checkbox.value
|
self.config.auto_play = event.checkbox.value
|
||||||
|
|
||||||
|
|
||||||
|
class ApiServerManager(Vertical):
|
||||||
|
"""Manager for the custom API server URL."""
|
||||||
|
|
||||||
|
def __init__(self, config, **kwargs) -> None:
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.config = config
|
||||||
|
|
||||||
|
def compose(self) -> ComposeResult:
|
||||||
|
yield Label("Custom API Server", classes="title")
|
||||||
|
yield Label(
|
||||||
|
"You can specify a custom SponsorBlock API server URL here.",
|
||||||
|
classes="subtitle",
|
||||||
|
)
|
||||||
|
with Grid(id="api-server-grid"):
|
||||||
|
yield Input(
|
||||||
|
placeholder="Custom API Server URL",
|
||||||
|
id="api-server-input",
|
||||||
|
value=self.config.api_server,
|
||||||
|
)
|
||||||
|
|
||||||
|
@on(Input.Changed, "#api-server-input")
|
||||||
|
def changed_api_server(self, event: Input.Changed):
|
||||||
|
self.config.api_server = event.input.value
|
||||||
|
|
||||||
|
|
||||||
class ISponsorBlockTVSetupMainScreen(Screen):
|
class ISponsorBlockTVSetupMainScreen(Screen):
|
||||||
"""Making this a separate screen to avoid a bug: https://github.com/Textualize/textual/issues/3221"""
|
"""Making this a separate screen to avoid a bug: https://github.com/Textualize/textual/issues/3221"""
|
||||||
|
|
||||||
@@ -915,6 +940,9 @@ class ISponsorBlockTVSetupMainScreen(Screen):
|
|||||||
yield AutoPlayManager(
|
yield AutoPlayManager(
|
||||||
config=self.config, id="autoplay-manager", classes="container"
|
config=self.config, id="autoplay-manager", classes="container"
|
||||||
)
|
)
|
||||||
|
yield ApiServerManager(
|
||||||
|
config=self.config, id="api-server-manager", classes="container"
|
||||||
|
)
|
||||||
|
|
||||||
def on_mount(self) -> None:
|
def on_mount(self) -> None:
|
||||||
if self.check_for_old_config_entries():
|
if self.check_for_old_config_entries():
|
||||||
|
|||||||
Reference in New Issue
Block a user