From 138c97c375d59a613ce37d286cd9908db5307cfe Mon Sep 17 00:00:00 2001 From: bourkemcrobbo Date: Mon, 10 Jun 2024 13:25:48 +1000 Subject: [PATCH 1/7] Added support for specifying minimum skip length --- config.json.template | 1 + src/iSponsorBlockTV/api_helpers.py | 9 ++++++--- src/iSponsorBlockTV/config_setup.py | 10 ++++++++++ src/iSponsorBlockTV/helpers.py | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/config.json.template b/config.json.template index 59f2b9d..84d64bb 100644 --- a/config.json.template +++ b/config.json.template @@ -12,6 +12,7 @@ "skip_count_tracking": true, "mute_ads": true, "skip_ads": true, + "minimum_skip_length": 1, "apikey": "", "channel_whitelist": [ {"id": "", diff --git a/src/iSponsorBlockTV/api_helpers.py b/src/iSponsorBlockTV/api_helpers.py index 8cfe3e8..27c757c 100644 --- a/src/iSponsorBlockTV/api_helpers.py +++ b/src/iSponsorBlockTV/api_helpers.py @@ -27,6 +27,7 @@ def __init__(self, config, web_session: ClientSession) -> None: self.skip_count_tracking = config.skip_count_tracking self.web_session = web_session self.num_devices = len(config.devices) + self.minimum_skip_length = config.minimum_skip_length # Not used anymore, maybe it can stay here a little longer @AsyncLRU(maxsize=10) @@ -146,10 +147,10 @@ async def get_segments(self, vid_id): if str(i["videoID"]) == str(vid_id): response_json = i break - return self.process_segments(response_json) + return self.process_segments(self, response_json) @staticmethod - def process_segments(response): + def process_segments(self, response): segments = [] ignore_ttl = True try: @@ -191,7 +192,9 @@ def process_segments(response): segment_dict["start"] = segment_before_start segment_dict["UUID"].extend(segment_before_UUID) segments.pop() - segments.append(segment_dict) + # Only add segments greater than minimum skip length + if segment_dict["end"]-segment_dict["start"] > self.minimum_skip_length: + segments.append(segment_dict) except Exception: pass return segments, ignore_ttl diff --git a/src/iSponsorBlockTV/config_setup.py b/src/iSponsorBlockTV/config_setup.py index 3e3bb95..0a08246 100644 --- a/src/iSponsorBlockTV/config_setup.py +++ b/src/iSponsorBlockTV/config_setup.py @@ -157,6 +157,16 @@ def main(config, debug: bool) -> None: config.channel_whitelist = channel_whitelist + # Ask for minimum skip length. Confirm input is an integer + while True: + try: + minimum_skip_length = int(input('Enter minimum length of segment to skip in seconds: ')) + break + except ValueError: + print('You entered a non integer value, try again.') + continue + config.minimum_skip_length = minimum_skip_length + config.skip_count_tracking = ( not input( "Do you want to report skipped segments to sponsorblock. Only the segment" diff --git a/src/iSponsorBlockTV/helpers.py b/src/iSponsorBlockTV/helpers.py index 0627c29..ddf300c 100644 --- a/src/iSponsorBlockTV/helpers.py +++ b/src/iSponsorBlockTV/helpers.py @@ -41,6 +41,7 @@ def __init__(self, data_dir): self.skip_count_tracking = True self.mute_ads = False self.skip_ads = False + self.minimum_skip_length = 1 self.__load() def validate(self): From 1c4ffe6f0b5ea29adbe2eb9d8cf17a24d871974b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Jun 2024 03:30:30 +0000 Subject: [PATCH 2/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/iSponsorBlockTV/api_helpers.py | 5 ++++- src/iSponsorBlockTV/config_setup.py | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/iSponsorBlockTV/api_helpers.py b/src/iSponsorBlockTV/api_helpers.py index 27c757c..c4bf394 100644 --- a/src/iSponsorBlockTV/api_helpers.py +++ b/src/iSponsorBlockTV/api_helpers.py @@ -193,7 +193,10 @@ def process_segments(self, response): segment_dict["UUID"].extend(segment_before_UUID) segments.pop() # Only add segments greater than minimum skip length - if segment_dict["end"]-segment_dict["start"] > self.minimum_skip_length: + if ( + segment_dict["end"] - segment_dict["start"] + > self.minimum_skip_length + ): segments.append(segment_dict) except Exception: pass diff --git a/src/iSponsorBlockTV/config_setup.py b/src/iSponsorBlockTV/config_setup.py index 0a08246..2152ea4 100644 --- a/src/iSponsorBlockTV/config_setup.py +++ b/src/iSponsorBlockTV/config_setup.py @@ -160,10 +160,12 @@ def main(config, debug: bool) -> None: # Ask for minimum skip length. Confirm input is an integer while True: try: - minimum_skip_length = int(input('Enter minimum length of segment to skip in seconds: ')) + minimum_skip_length = int( + input("Enter minimum length of segment to skip in seconds: ") + ) break except ValueError: - print('You entered a non integer value, try again.') + print("You entered a non integer value, try again.") continue config.minimum_skip_length = minimum_skip_length From 4d4016cdf893475a063731d7bee0b8674cad4e93 Mon Sep 17 00:00:00 2001 From: bourkemcrobbo Date: Tue, 18 Jun 2024 15:03:30 +1000 Subject: [PATCH 3/7] Fixed bad static method argument --- src/iSponsorBlockTV/api_helpers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/iSponsorBlockTV/api_helpers.py b/src/iSponsorBlockTV/api_helpers.py index 27c757c..bb719a0 100644 --- a/src/iSponsorBlockTV/api_helpers.py +++ b/src/iSponsorBlockTV/api_helpers.py @@ -147,10 +147,10 @@ async def get_segments(self, vid_id): if str(i["videoID"]) == str(vid_id): response_json = i break - return self.process_segments(self, response_json) + return self.process_segments(response_json, minimum_skip_length) @staticmethod - def process_segments(self, response): + def process_segments(response, minimum_skip_length): segments = [] ignore_ttl = True try: @@ -193,7 +193,7 @@ def process_segments(self, response): segment_dict["UUID"].extend(segment_before_UUID) segments.pop() # Only add segments greater than minimum skip length - if segment_dict["end"]-segment_dict["start"] > self.minimum_skip_length: + if segment_dict["end"]-segment_dict["start"] > minimum_skip_length: segments.append(segment_dict) except Exception: pass From 6c679f2a67fef889cca77535548525517140f318 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 18 Jun 2024 05:07:23 +0000 Subject: [PATCH 4/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/iSponsorBlockTV/api_helpers.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/iSponsorBlockTV/api_helpers.py b/src/iSponsorBlockTV/api_helpers.py index ec428e2..9555d39 100644 --- a/src/iSponsorBlockTV/api_helpers.py +++ b/src/iSponsorBlockTV/api_helpers.py @@ -193,10 +193,7 @@ def process_segments(response, minimum_skip_length): segment_dict["UUID"].extend(segment_before_UUID) segments.pop() # Only add segments greater than minimum skip length - if ( - segment_dict["end"] - segment_dict["start"] - > minimum_skip_length - ): + if segment_dict["end"] - segment_dict["start"] > minimum_skip_length: segments.append(segment_dict) except Exception: pass From 2b1b0f69a413643d01fd1a19828e3d0b34082ad6 Mon Sep 17 00:00:00 2001 From: bourkemcrobbo Date: Tue, 18 Jun 2024 15:08:40 +1000 Subject: [PATCH 5/7] Fixed bad static method argument --- src/iSponsorBlockTV/api_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/iSponsorBlockTV/api_helpers.py b/src/iSponsorBlockTV/api_helpers.py index ec428e2..cbbcf8a 100644 --- a/src/iSponsorBlockTV/api_helpers.py +++ b/src/iSponsorBlockTV/api_helpers.py @@ -147,7 +147,7 @@ async def get_segments(self, vid_id): if str(i["videoID"]) == str(vid_id): response_json = i break - return self.process_segments(response_json, minimum_skip_length) + return self.process_segments(response_json, self.minimum_skip_length) @staticmethod def process_segments(response, minimum_skip_length): From 0e87da53a1bc14b6a94eb34e595548922ad9ade8 Mon Sep 17 00:00:00 2001 From: bourkemcrobbo Date: Thu, 27 Jun 2024 14:14:05 +1000 Subject: [PATCH 6/7] Updated setup to match new format. Set default value of skip length to 0 so user has to explicitly enable functionality --- config.json.template | 2 +- src/iSponsorBlockTV/config_setup.py | 25 ++++++++++++++++--------- src/iSponsorBlockTV/helpers.py | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/config.json.template b/config.json.template index e536cd7..ba347a5 100644 --- a/config.json.template +++ b/config.json.template @@ -12,7 +12,7 @@ "skip_count_tracking": true, "mute_ads": true, "skip_ads": true, - "minimum_skip_length": 1, + "minimum_skip_length": 0, "autoplay": true, "apikey": "", "channel_whitelist": [ diff --git a/src/iSponsorBlockTV/config_setup.py b/src/iSponsorBlockTV/config_setup.py index 22b90d0..047b866 100644 --- a/src/iSponsorBlockTV/config_setup.py +++ b/src/iSponsorBlockTV/config_setup.py @@ -29,6 +29,8 @@ 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: " +MINIMUM_SKIP_PROMPT = "Do you want to specify a minimum length of segment to skip? (y/N)" +MINIMUM_SKIP_SPECIFICATION_PROMPT = "Enter minimum length of segment to skip in seconds (enter 0 to disable):" REPORT_SKIPPED_SEGMENTS_PROMPT = ( "Do you want to report skipped segments to sponsorblock. Only the segment" " UUID will be sent? (Y/n) " @@ -179,15 +181,20 @@ def main(config, debug: bool) -> None: config.channel_whitelist = channel_whitelist # Ask for minimum skip length. Confirm input is an integer - while True: - try: - minimum_skip_length = int( - input("Enter minimum length of segment to skip in seconds: ") - ) - break - except ValueError: - print("You entered a non integer value, try again.") - continue + minimum_skip_length = config.minimum_skip_length + + choice = get_yn_input(MINIMUM_SKIP_PROMPT) + if choice == "y": + while True: + try: + minimum_skip_length = int( + input(MINIMUM_SKIP_SPECIFICATION_PROMPT) + ) + break + except ValueError: + print("You entered a non integer value, try again.") + continue + config.minimum_skip_length = minimum_skip_length choice = get_yn_input(REPORT_SKIPPED_SEGMENTS_PROMPT) diff --git a/src/iSponsorBlockTV/helpers.py b/src/iSponsorBlockTV/helpers.py index cc68c30..21e6b51 100644 --- a/src/iSponsorBlockTV/helpers.py +++ b/src/iSponsorBlockTV/helpers.py @@ -41,7 +41,7 @@ def __init__(self, data_dir): self.skip_count_tracking = True self.mute_ads = False self.skip_ads = False - self.minimum_skip_length = 1 + self.minimum_skip_length = 0 self.auto_play = True self.__load() From d11bcbade5635bdf4ff4a2632a64c63f4bf3658b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 27 Jun 2024 04:14:49 +0000 Subject: [PATCH 7/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/iSponsorBlockTV/config_setup.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/iSponsorBlockTV/config_setup.py b/src/iSponsorBlockTV/config_setup.py index 047b866..968d6e9 100644 --- a/src/iSponsorBlockTV/config_setup.py +++ b/src/iSponsorBlockTV/config_setup.py @@ -29,8 +29,12 @@ 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: " -MINIMUM_SKIP_PROMPT = "Do you want to specify a minimum length of segment to skip? (y/N)" -MINIMUM_SKIP_SPECIFICATION_PROMPT = "Enter minimum length of segment to skip in seconds (enter 0 to disable):" +MINIMUM_SKIP_PROMPT = ( + "Do you want to specify a minimum length of segment to skip? (y/N)" +) +MINIMUM_SKIP_SPECIFICATION_PROMPT = ( + "Enter minimum length of segment to skip in seconds (enter 0 to disable):" +) REPORT_SKIPPED_SEGMENTS_PROMPT = ( "Do you want to report skipped segments to sponsorblock. Only the segment" " UUID will be sent? (Y/n) " @@ -182,19 +186,17 @@ def main(config, debug: bool) -> None: # Ask for minimum skip length. Confirm input is an integer minimum_skip_length = config.minimum_skip_length - + choice = get_yn_input(MINIMUM_SKIP_PROMPT) if choice == "y": while True: try: - minimum_skip_length = int( - input(MINIMUM_SKIP_SPECIFICATION_PROMPT) - ) + minimum_skip_length = int(input(MINIMUM_SKIP_SPECIFICATION_PROMPT)) break except ValueError: print("You entered a non integer value, try again.") continue - + config.minimum_skip_length = minimum_skip_length choice = get_yn_input(REPORT_SKIPPED_SEGMENTS_PROMPT)