Skip to content

Commit

Permalink
Update api_helpers.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bertybuttface committed Jan 28, 2024
1 parent 4d88e46 commit aa3b92d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/iSponsorBlockTV/api_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,18 @@ def process_segments(response):
ignore_ttl = True
for segment in sorted_segments:
ignore_ttl = ignore_ttl and segment.get("locked") == 1
if not merged_segments or segment["segment"][0] > merged_segments[-1]["segment"][1]:
segment["UUID"] = [segment["UUID"]] if not isinstance(segment["UUID"], list) else segment["UUID"]
merged_segments.append(segment)
else:

if not merged_segments:
# First segment, just add it
merged_segments.append(segment)
elif segment["segment"][0] <= merged_segments[-1]["segment"][1]:
# Overlapping segment, merge it
merged_segments[-1]["segment"][1] = max(merged_segments[-1]["segment"][1], segment["segment"][1])
merged_segments[-1]["UUID"].extend([segment["UUID"]])
else:
# Non-overlapping segment, make UUIDs a list and append
segment["UUID"] = [segment["UUID"]]
merged_segments.append(segment)

output_segments = [{"start": seg["segment"][0], "end": seg["segment"][1], "UUID": seg["UUID"]} for seg in merged_segments]
return output_segments, ignore_ttl
Expand Down

0 comments on commit aa3b92d

Please sign in to comment.