From 59dc8e7ec9aee697498be3b94664a74e02af7d05 Mon Sep 17 00:00:00 2001 From: apricotjam4 Date: Mon, 14 Apr 2025 16:41:58 +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..b22fd21 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( + (intro_data["skipStart"] / 1000), tz=timezone.utc + ).strftime("%H:%M:%S.%f")[:-3], + ) + ) + chapters.append( + Chapter( + timestamp=datetime.fromtimestamp( + (intro_data["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