Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for specifying minimum skip length #169

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions config.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"skip_count_tracking": true,
"mute_ads": true,
"skip_ads": true,
"minimum_skip_length": 0,
"autoplay": true,
"apikey": "",
"channel_whitelist": [
Expand Down
9 changes: 6 additions & 3 deletions src/iSponsorBlockTV/api_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(response_json, self.minimum_skip_length)

@staticmethod
def process_segments(response):
def process_segments(response, minimum_skip_length):
segments = []
ignore_ttl = True
try:
Expand Down Expand Up @@ -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"] > minimum_skip_length:
segments.append(segment_dict)
except Exception:
pass
return segments, ignore_ttl
Expand Down
21 changes: 21 additions & 0 deletions src/iSponsorBlockTV/config_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +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):"
)
REPORT_SKIPPED_SEGMENTS_PROMPT = (
"Do you want to report skipped segments to sponsorblock. Only the segment"
" UUID will be sent? (Y/n) "
Expand Down Expand Up @@ -178,6 +184,21 @@ def main(config, debug: bool) -> None:

config.channel_whitelist = channel_whitelist

# 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))
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)
config.skip_count_tracking = choice != "n"

Expand Down
1 change: 1 addition & 0 deletions src/iSponsorBlockTV/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 0
self.auto_play = True
self.__load()

Expand Down