From aa3b92dbe75a6234cf8aca2cd402c252b529e29d Mon Sep 17 00:00:00 2001 From: bertybuttface <110790513+bertybuttface@users.noreply.github.com> Date: Sun, 28 Jan 2024 14:57:16 +0000 Subject: [PATCH] Update api_helpers.py --- src/iSponsorBlockTV/api_helpers.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/iSponsorBlockTV/api_helpers.py b/src/iSponsorBlockTV/api_helpers.py index f354c0c..2bf041d 100644 --- a/src/iSponsorBlockTV/api_helpers.py +++ b/src/iSponsorBlockTV/api_helpers.py @@ -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