[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot]
2024-01-14 14:03:37 +00:00
parent 3cee674e91
commit ecb3583c35
5 changed files with 105 additions and 51 deletions

View File

@@ -138,8 +138,8 @@ class ApiHelper:
if response.status != 200: if response.status != 200:
response_text = await response.text() response_text = await response.text()
print( print(
f"Error getting segments for video {vid_id}, hashed as {vid_id_hashed}. " f"Error getting segments for video {vid_id}, hashed as {vid_id_hashed}."
f"Code: {response.status} - {response_text}" f" Code: {response.status} - {response_text}"
) )
return [], True return [], True
for i in response_json: for i in response_json:

View File

@@ -38,12 +38,14 @@ def main(config, debug: bool) -> None:
asyncio.set_event_loop(loop) asyncio.set_event_loop(loop)
if hasattr(config, "atvs"): if hasattr(config, "atvs"):
print( print(
"The atvs config option is deprecated and has stopped working. Please read this for more information on " "The atvs config option is deprecated and has stopped working. Please read"
"how to upgrade to V2: \nhttps://github.com/dmunozv04/iSponsorBlockTV/wiki/Migrate-from-V1-to-V2" " this for more information on how to upgrade to V2:"
" \nhttps://github.com/dmunozv04/iSponsorBlockTV/wiki/Migrate-from-V1-to-V2"
) )
if ( if (
input( input(
"Do you want to remove the legacy 'atvs' entry (the app won't start with it present)? (y/n) " "Do you want to remove the legacy 'atvs' entry (the app won't start"
" with it present)? (y/n) "
) )
== "y" == "y"
): ):
@@ -69,7 +71,8 @@ def main(config, debug: bool) -> None:
== "y" == "y"
): ):
print( print(
"Get youtube apikey here: https://developers.google.com/youtube/registering_an_application" "Get youtube apikey here:"
" https://developers.google.com/youtube/registering_an_application"
) )
apikey = input("Enter your API key: ") apikey = input("Enter your API key: ")
config.apikey = apikey config.apikey = apikey
@@ -78,8 +81,9 @@ def main(config, debug: bool) -> None:
if skip_categories: if skip_categories:
if input("Skip categories already specified. Change them? (y/n) ") == "y": if input("Skip categories already specified. Change them? (y/n) ") == "y":
categories = input( categories = input(
"Enter skip categories (space or comma sepparated) Options: [sponsor selfpromo exclusive_access " "Enter skip categories (space or comma sepparated) Options: [sponsor"
"interaction poi_highlight intro outro preview filler music_offtopic]:\n" " 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 = [
@@ -87,8 +91,9 @@ def main(config, debug: bool) -> None:
] # Remove empty strings ] # Remove empty strings
else: else:
categories = input( categories = input(
"Enter skip categories (space or comma sepparated) Options: [sponsor, selfpromo, exclusive_access, " "Enter skip categories (space or comma sepparated) Options: [sponsor,"
"interaction, poi_highlight, intro, outro, preview, filler, music_offtopic:\n" " 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 = [
@@ -103,8 +108,9 @@ def main(config, debug: bool) -> None:
): ):
if not apikey: if not apikey:
print( print(
"WARNING: You need to specify an API key to use this function, otherwise the program will fail to " "WARNING: You need to specify an API key to use this function,"
"start.\nYou can add one by re-running this setup wizard." " otherwise the program will fail to start.\nYou can add one by"
" re-running this setup wizard."
) )
web_session = aiohttp.ClientSession() web_session = aiohttp.ClientSession()
api_helper = api_helpers.ApiHelper(config, web_session) api_helper = api_helpers.ApiHelper(config, web_session)
@@ -152,7 +158,8 @@ def main(config, debug: bool) -> None:
config.skip_count_tracking = ( config.skip_count_tracking = (
not input( not input(
"Do you want to report skipped segments to sponsorblock. Only the segment UUID will be sent? (y/n) " "Do you want to report skipped segments to sponsorblock. Only the segment"
" UUID will be sent? (y/n) "
) )
== "n" == "n"
) )

View File

@@ -46,8 +46,12 @@ class Config:
def validate(self): def validate(self):
if hasattr(self, "atvs"): if hasattr(self, "atvs"):
print( print(
"The atvs config option is deprecated and has stopped working. Please read this for more information " (
"on how to upgrade to V2: \nhttps://github.com/dmunozv04/iSponsorBlockTV/wiki/Migrate-from-V1-to-V2", "The atvs config option is deprecated and has stopped working."
" Please read this for more information "
"on how to upgrade to V2:"
" \nhttps://github.com/dmunozv04/iSponsorBlockTV/wiki/Migrate-from-V1-to-V2"
),
) )
print("Exiting in 10 seconds...") print("Exiting in 10 seconds...")
time.sleep(10) time.sleep(10)
@@ -82,12 +86,19 @@ class Config:
os.makedirs(self.data_dir) os.makedirs(self.data_dir)
else: # Running in docker without mounting the data dir else: # Running in docker without mounting the data dir
print( print(
"Running in docker without mounting the data dir, check the wiki for more information: " "Running in docker without mounting the data dir, check the"
" wiki for more information: "
"https://github.com/dmunozv04/iSponsorBlockTV/wiki/Installation#Docker" "https://github.com/dmunozv04/iSponsorBlockTV/wiki/Installation#Docker"
) )
print( print(
"This image has recently been updated to v2, and requires changes.", (
"Please read this for more information on how to upgrade to V2:", "This image has recently been updated to v2, and requires"
" changes."
),
(
"Please read this for more information on how to upgrade"
" to V2:"
),
"https://github.com/dmunozv04/iSponsorBlockTV/wiki/Migrate-from-V1-to-V2", "https://github.com/dmunozv04/iSponsorBlockTV/wiki/Migrate-from-V1-to-V2",
) )
print("Exiting in 10 seconds...") print("Exiting in 10 seconds...")

View File

@@ -42,8 +42,9 @@ def main():
create_plist(correct_path) create_plist(correct_path)
run_setup(correct_path + "/config.json") run_setup(correct_path + "/config.json")
print( print(
"Launch daemon installed. Please restart the computer to enable it or use:\n launchctl load " "Launch daemon installed. Please restart the computer to enable it or"
"~/Library/LaunchAgents/com.dmunozv04.iSponsorBlockTV.plist" " use:\n launchctl load"
" ~/Library/LaunchAgents/com.dmunozv04.iSponsorBlockTV.plist"
) )
else: else:
if not os.path.exists(correct_path): if not os.path.exists(correct_path):

View File

@@ -108,7 +108,7 @@ class Device(Element):
self.element_name = self.element_data["name"] self.element_name = self.element_data["name"]
else: else:
self.element_name = ( self.element_name = (
f"Unnamed device with id " "Unnamed device with id "
f"{self.element_data['screen_id'][:5]}..." f"{self.element_data['screen_id'][:5]}..."
f"{self.element_data['screen_id'][-5:]}" f"{self.element_data['screen_id'][-5:]}"
) )
@@ -148,8 +148,11 @@ class MigrationScreen(ModalWithClickExit):
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
yield Grid( yield Grid(
Label( Label(
"Welcome to the new configurator! You seem to have the legacy 'atvs' entry on your config file, " (
"do you want to remove it?\n(The app won't start with it present)", "Welcome to the new configurator! You seem to have the legacy"
" 'atvs' entry on your config file, do you want to remove it?\n(The"
" app won't start with it present)"
),
id="question", id="question",
classes="button-100", classes="button-100",
), ),
@@ -255,7 +258,9 @@ class AddDevice(ModalWithClickExit):
): ):
with Container(id="add-device-pin-container"): with Container(id="add-device-pin-container"):
yield Input( yield Input(
placeholder="Pairing Code (found in Settings - Link with TV code)", placeholder=(
"Pairing Code (found in Settings - Link with TV code)"
),
id="pairing-code-input", id="pairing-code-input",
validators=[ validators=[
Function( Function(
@@ -276,9 +281,13 @@ class AddDevice(ModalWithClickExit):
yield Label(id="add-device-info") yield Label(id="add-device-info")
with Container(id="add-device-dial-container"): with Container(id="add-device-dial-container"):
yield Label( yield Label(
"Make sure your device is on the same network as this computer\nIf it isn't showing up, " (
"try restarting the app.\nIf running in docker, make sure to use `--network=host`\nTo refresh " "Make sure your device is on the same network as this"
"the list, close and open the dialog again", " computer\nIf it isn't showing up, try restarting the"
" app.\nIf running in docker, make sure to use"
" `--network=host`\nTo refresh the list, close and open the"
" dialog again"
),
classes="subtitle", classes="subtitle",
) )
yield SelectionList( yield SelectionList(
@@ -320,9 +329,9 @@ class AddDevice(ModalWithClickExit):
@on(Input.Changed, "#pairing-code-input") @on(Input.Changed, "#pairing-code-input")
def changed_pairing_code(self, event: Input.Changed): def changed_pairing_code(self, event: Input.Changed):
self.query_one( self.query_one("#add-device-pin-add-button").disabled = (
"#add-device-pin-add-button" not event.validation_result.is_valid
).disabled = not event.validation_result.is_valid )
@on(Input.Submitted, "#pairing-code-input") @on(Input.Submitted, "#pairing-code-input")
@on(Button.Pressed, "#add-device-pin-add-button") @on(Button.Pressed, "#add-device-pin-add-button")
@@ -367,9 +376,9 @@ class AddDevice(ModalWithClickExit):
@on(SelectionList.SelectedChanged, "#dial-devices-list") @on(SelectionList.SelectedChanged, "#dial-devices-list")
def changed_device_list(self, event: SelectionList.SelectedChanged): def changed_device_list(self, event: SelectionList.SelectedChanged):
self.query_one( self.query_one("#add-device-dial-add-button").disabled = (
"#add-device-dial-add-button" not event.selection_list.selected
).disabled = not event.selection_list.selected )
class AddChannel(ModalWithClickExit): class AddChannel(ModalWithClickExit):
@@ -387,7 +396,10 @@ class AddChannel(ModalWithClickExit):
with Container(id="add-channel-container"): with Container(id="add-channel-container"):
yield Label("Add Channel", classes="title") yield Label("Add Channel", classes="title")
yield Label( yield Label(
"Select a method to add a channel. Adding via search only works if a YouTube api key has been set", (
"Select a method to add a channel. Adding via search only works if"
" a YouTube api key has been set"
),
id="add-channel-label", id="add-channel-label",
classes="subtitle", classes="subtitle",
) )
@@ -429,18 +441,25 @@ class AddChannel(ModalWithClickExit):
) )
else: else:
yield Label( yield Label(
"[#ff0000]No api key set, cannot search for channels. You can add it the config section " (
"below", "[#ff0000]No api key set, cannot search for channels."
" You can add it the config section below"
),
id="add-channel-search-no-key", id="add-channel-search-no-key",
classes="subtitle", classes="subtitle",
) )
with Vertical(id="add-channel-id-container"): with Vertical(id="add-channel-id-container"):
yield Input( yield Input(
placeholder="Enter channel ID (example: UCuAXFkgsw1L7xaCfnd5JJOw)", placeholder=(
"Enter channel ID (example: UCuAXFkgsw1L7xaCfnd5JJOw)"
),
id="channel-id-input", id="channel-id-input",
) )
yield Input( yield Input(
placeholder="Enter channel name (only used to display in the config file)", placeholder=(
"Enter channel name (only used to display in the config"
" file)"
),
id="channel-name-input-id", id="channel-name-input-id",
) )
yield Button( yield Button(
@@ -643,9 +662,10 @@ class ApiKeyManager(Vertical):
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
yield Label("YouTube Api Key", classes="title") yield Label("YouTube Api Key", classes="title")
yield Label( yield Label(
"You can get a YouTube Data API v3 Key from the [" "You can get a YouTube Data API v3 Key from the"
"link=https://console.developers.google.com/apis/credentials]Google Cloud Console[/link]. This key is " " [link=https://console.developers.google.com/apis/credentials]Google Cloud"
"only required if you're whitelisting channels." " Console[/link]. This key is only required if you're whitelisting"
" channels."
) )
with Grid(id="api-key-grid"): with Grid(id="api-key-grid"):
yield Input( yield Input(
@@ -705,10 +725,14 @@ class SkipCountTrackingManager(Vertical):
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
yield Label("Skip count tracking", classes="title") yield Label("Skip count tracking", classes="title")
yield Label( yield Label(
"This feature tracks which segments you have skipped to let users know how much their submission has " (
"helped others and used as a metric along with upvotes to ensure that spam doesn't get into the database. " "This feature tracks which segments you have skipped to let users know"
"The program sends a message to the sponsor block server each time you skip a segment. Hopefully most " " how much their submission has helped others and used as a metric"
"people don't change this setting so that the view numbers are accurate. :)", " along with upvotes to ensure that spam doesn't get into the database."
" The program sends a message to the sponsor block server each time you"
" skip a segment. Hopefully most people don't change this setting so"
" that the view numbers are accurate. :)"
),
classes="subtitle", classes="subtitle",
id="skip-count-tracking-subtitle", id="skip-count-tracking-subtitle",
) )
@@ -733,8 +757,11 @@ class AdSkipMuteManager(Vertical):
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
yield Label("Skip/Mute ads", classes="title") yield Label("Skip/Mute ads", classes="title")
yield Label( yield Label(
"This feature allows you to automatically mute and/or skip native YouTube ads. Skipping ads only works if " (
"that ad shows the 'Skip Ad' button, if it doesn't then it will only be able to be muted.", "This feature allows you to automatically mute and/or skip native"
" YouTube ads. Skipping ads only works if that ad shows the 'Skip Ad'"
" button, if it doesn't then it will only be able to be muted."
),
classes="subtitle", classes="subtitle",
id="skip-count-tracking-subtitle", id="skip-count-tracking-subtitle",
) )
@@ -769,13 +796,19 @@ class ChannelWhitelistManager(Vertical):
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
yield Label("Channel Whitelist", classes="title") yield Label("Channel Whitelist", classes="title")
yield Label( yield Label(
"This feature allows to whitelist channels from being skipped. This feature is automatically disabled " (
"when no channels have been specified.", "This feature allows to whitelist channels from being skipped. This"
" feature is automatically disabled when no channels have been"
" specified."
),
classes="subtitle", classes="subtitle",
id="channel-whitelist-subtitle", id="channel-whitelist-subtitle",
) )
yield Label( yield Label(
":warning: [#FF0000]You need to set your YouTube Api Key in order to use this feature", (
":warning: [#FF0000]You need to set your YouTube Api Key in order to"
" use this feature"
),
id="warning-no-key", id="warning-no-key",
) )
with Horizontal(id="add-channel-button-container"): with Horizontal(id="add-channel-button-container"):
@@ -885,7 +918,9 @@ class ISponsorBlockTVSetupMainScreen(Screen):
class ISponsorBlockTVSetup(App): class ISponsorBlockTVSetup(App):
CSS_PATH = "setup-wizard-style.tcss" # tcss is the recommended extension for textual css files CSS_PATH = ( # tcss is the recommended extension for textual css files
"setup-wizard-style.tcss"
)
# Bindings for the whole app here, so they are available in all screens # Bindings for the whole app here, so they are available in all screens
BINDINGS = [("q,ctrl+c", "exit_modal", "Exit"), ("s", "save", "Save")] BINDINGS = [("q,ctrl+c", "exit_modal", "Exit"), ("s", "save", "Save")]