From fad5e14f84573796b3989794c35f34a1f88f03a6 Mon Sep 17 00:00:00 2001
From: Kelvin <kelvin@futo.org>
Date: Mon, 11 Dec 2023 19:03:46 +0100
Subject: [PATCH] Clip chapters

---
 YoutubeConfig.json |  2 +-
 YoutubeScript.js   | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/YoutubeConfig.json b/YoutubeConfig.json
index 108ce17..7c5357c 100644
--- a/YoutubeConfig.json
+++ b/YoutubeConfig.json
@@ -7,7 +7,7 @@
 	"sourceUrl": "https://plugins.grayjay.app/Youtube/YoutubeConfig.json",
 	"repositoryUrl": "https://futo.org",
 	"scriptUrl": "./YoutubeScript.js",
-	"version": 156,
+	"version": 157,
 	"iconUrl": "./youtube.png",
 	"id": "35ae969a-a7db-11ed-afa1-0242ac120002",
 
diff --git a/YoutubeScript.js b/YoutubeScript.js
index b9a67c4..6cfe98e 100644
--- a/YoutubeScript.js
+++ b/YoutubeScript.js
@@ -459,6 +459,44 @@ source.getContentDetails = (url, useAuth) => {
 };
 source.getContentChapters = function(url, initialData) {
     //return [];
+    if(REGEX_VIDEO_URL_CLIP.test(url)) {
+		const videoPage = http.GET(url, getRequestHeaders({}), false);
+
+		if(videoPage.isOk && throwIfCaptcha(videoPage)) {
+		    const initialData = getInitialData(videoPage.body);
+		    const playerData = getInitialPlayerData(videoPage.body);
+
+		    console.log("Clip data", playerData?.clipConfig);
+		    const clipConfig = playerData?.clipConfig;
+		    if(clipConfig?.endTimeMs && clipConfig?.startTimeMs) {
+		        const startTime = parseInt(clipConfig.startTimeMs) / 1000;
+		        const endTime = parseInt(clipConfig.endTimeMs) / 1000;
+		        return [
+		            {
+                        name: "Non-Clip",
+                        timeStart: 0,
+                        timeEnd: startTime,
+                        type: Type.Chapter.SKIPPABLE
+                    },
+		            {
+                        name: "Clip",
+                        timeStart: startTime,
+                        timeEnd: endTime,
+                        type: Type.Chapter.NORMAL
+                    },
+		            {
+                        name: "Non-Clip",
+                        timeStart: endTime,
+                        timeEnd: 99999999,
+                        type: Type.Chapter.SKIPPABLE
+                    },
+		        ];
+		    }
+		    else
+		        return [];
+		}
+		else return [];
+    }
 
     const videoId = extractVideoIDFromUrl(url);
 
-- 
GitLab