used Invidious

This commit is contained in:
2024-10-26 22:28:01 +08:00
parent 11241875b0
commit 6b2b2d4418
8 changed files with 230 additions and 28 deletions
+2 -1
View File
@@ -12,7 +12,8 @@ try {
PRUNING: process.env.PRUNING === "true" ? true : false,
STAY_TIME: parseInt(process.env.STAY_TIME!) || 30,
DEFAULT_VOLUME: parseInt(process.env.DEFAULT_VOLUME!) || 100,
LOCALE: process.env.LOCALE || "en"
LOCALE: process.env.LOCALE || "en",
USE_INVIDIOUS_PROXY: process.env.USE_INVIDIOUS_PROXY === "true" ? true : false
};
}
+37
View File
@@ -0,0 +1,37 @@
import { videoIdPattern, videoPattern } from "../utils/patterns";
export const extractID = (url: string) => {
const url_ = url.trim();
if (url_.startsWith("https")) {
if (url_.indexOf("list=") === -1) {
const video_id = extractVideoId(url_);
if (!video_id) throw new Error("This is not a YouTube url or videoId or PlaylistID");
return video_id;
} else {
return url_.split("list=")[1].split("&")[0];
}
} else return url_;
};
function extractVideoId(urlOrId: string): string | false {
if (urlOrId.startsWith("https://") && urlOrId.match(videoPattern)) {
let id: string;
if (urlOrId.includes("youtu.be/")) {
id = urlOrId.split("youtu.be/")[1].split(/(\?|\/|&)/)[0];
} else if (urlOrId.includes("youtube.com/embed/")) {
id = urlOrId.split("youtube.com/embed/")[1].split(/(\?|\/|&)/)[0];
} else if (urlOrId.includes("youtube.com/shorts/")) {
id = urlOrId.split("youtube.com/shorts/")[1].split(/(\?|\/|&)/)[0];
} else if (urlOrId.includes("youtube.com/live/")) {
id = urlOrId.split("youtube.com/live/")[1].split(/(\?|\/|&)/)[0];
} else {
id = (urlOrId.split("watch?v=")[1] ?? urlOrId.split("&v=")[1]).split(/(\?|\/|&)/)[0];
}
if (id.match(videoIdPattern)) return id;
} else if (urlOrId.match(videoIdPattern)) {
return urlOrId;
}
return false;
}
+1
View File
@@ -4,3 +4,4 @@ export const scRegex = /^https?:\/\/(soundcloud\.com)\/(.*)$/;
export const mobileScRegex = /^https?:\/\/(soundcloud\.app\.goo\.gl)\/(.*)$/;
export const isURL =
/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
export const videoIdPattern = /^[a-zA-Z\d_-]{11,12}$/;