From 003086953f8b295f55a6c6cb9b7ab582f21b3650 Mon Sep 17 00:00:00 2001
From: apricotjam4 <apricotjam4@cock.li>
Date: Mon, 14 Apr 2025 15:11:44 +0100
Subject: [PATCH] ALL4: More chapters from "Skip Intro" button

removed the generic chapter names as devine sets them automatically
+ this way it doesn't matter what order I add the chapters in
I can just sort them at the end
---
 services/ALL4/__init__.py | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/services/ALL4/__init__.py b/services/ALL4/__init__.py
index bef30ea..59680c3 100644
--- a/services/ALL4/__init__.py
+++ b/services/ALL4/__init__.py
@@ -269,12 +269,28 @@ class ALL4(Service):
 
         chapters = [
             Chapter(
-                name=f"Chapter {i + 1:02}",
                 timestamp=datetime.fromtimestamp((ms / 1000), tz=timezone.utc).strftime("%H:%M:%S.%f")[:-3],
             )
             for i, ms in enumerate(x["breakOffset"] for x in track.data["adverts"]["breaks"])
         ]
 
+        if intro_data := track.data.get("skipIntro"):
+            chapters.append(
+                Chapter(
+                    name="Intro",
+                    timestamp=datetime.fromtimestamp(
+                        (track.data["skipIntro"]["skipStart"] / 1000), tz=timezone.utc
+                    ).strftime("%H:%M:%S.%f")[:-3],
+                )
+            )
+            chapters.append(
+                Chapter(
+                    timestamp=datetime.fromtimestamp(
+                        (track.data["skipIntro"]["skipEnd"] / 1000), tz=timezone.utc
+                    ).strftime("%H:%M:%S.%f")[:-3],
+                )
+            )
+
         if track.data.get("endCredits", {}).get("squeezeIn"):
             chapters.append(
                 Chapter(
@@ -284,8 +300,7 @@ class ALL4(Service):
                     ).strftime("%H:%M:%S.%f")[:-3],
                 )
             )
-
-        return chapters
+        return sorted(chapters, key=lambda x: x.timestamp)
 
     def get_widevine_service_certificate(self, **_: Any) -> str:
         return WidevineCdm.common_privacy_cert