api/twitch: check for twitch vods & prompt

This commit is contained in:
hyperdefined 2025-05-30 16:21:34 -04:00
parent ea3223e0b0
commit f63063ac92
No known key found for this signature in database
GPG Key ID: 38C93C4835071D4A
6 changed files with 27 additions and 8 deletions

View File

@ -191,11 +191,19 @@ export default async function({ host, patternMatch, params, isSession }) {
break; break;
case "twitch": case "twitch":
if (url.pathname.includes('/videos/')) {
r = await twitch({
clipId: false,
type: 'vod'
});
}
if (url.pathname.includes('/clip/')) {
r = await twitch({ r = await twitch({
clipId: patternMatch.clip || false, clipId: patternMatch.clip || false,
quality: params.videoQuality, quality: params.videoQuality,
isAudioOnly, isAudioOnly,
}); });
}
break; break;
case "rutube": case "rutube":

View File

@ -157,7 +157,10 @@ export const services = {
subdomains: "*", subdomains: "*",
}, },
twitch: { twitch: {
patterns: [":channel/clip/:clip"], patterns: [
":channel/clip/:clip",
":type/:videoId"
],
tld: "tv", tld: "tv",
}, },
twitter: { twitter: {

View File

@ -50,7 +50,8 @@ export const testers = {
|| (pattern.id?.length < 21 && pattern.user?.length <= 32), || (pattern.id?.length < 21 && pattern.user?.length <= 32),
"twitch": pattern => "twitch": pattern =>
pattern.channel && pattern.clip?.length <= 100, pattern.channel && pattern.clip?.length <= 100
|| pattern.type === 'videos' && pattern.videoId?.length >= 1,
"twitter": pattern => "twitter": pattern =>
pattern.id?.length < 20, pattern.id?.length < 20,

View File

@ -4,6 +4,8 @@ const gqlURL = "https://gql.twitch.tv/gql";
const clientIdHead = { "client-id": "kimne78kx3ncx6brgo4mv6wki5h1ko" }; const clientIdHead = { "client-id": "kimne78kx3ncx6brgo4mv6wki5h1ko" };
export default async function (obj) { export default async function (obj) {
if (obj.type === 'vod') return { error: "twitch.vod_not_supported" };
const req_metadata = await fetch(gqlURL, { const req_metadata = await fetch(gqlURL, {
method: "POST", method: "POST",
headers: clientIdHead, headers: clientIdHead,

View File

@ -51,6 +51,9 @@ function aliasURL(url) {
if (url.hostname === 'clips.twitch.tv' && parts.length >= 2) { if (url.hostname === 'clips.twitch.tv' && parts.length >= 2) {
url = new URL(`https://twitch.tv/_/clip/${parts[1]}`); url = new URL(`https://twitch.tv/_/clip/${parts[1]}`);
} }
if ((url.hostname === 'www.twitch.tv' && url.pathname.includes('/videos/')) && parts.length === 3) {
url = new URL(`https://twitch.tv/videos/${parts[2]}`);
}
break; break;
case "bilibili": case "bilibili":

View File

@ -58,5 +58,7 @@
"youtube.api_error": "youtube updated something about its api and i couldn't get any info about this video. try again in a few seconds, but if this issue sticks, please report it!", "youtube.api_error": "youtube updated something about its api and i couldn't get any info about this video. try again in a few seconds, but if this issue sticks, please report it!",
"youtube.temporary_disabled": "youtube downloading is temporarily disabled due to restrictions from youtube's side. we're already looking for ways to go around them.\n\nwe apologize for the inconvenience and are doing our best to restore this functionality. check cobalt's socials or github for timely updates!", "youtube.temporary_disabled": "youtube downloading is temporarily disabled due to restrictions from youtube's side. we're already looking for ways to go around them.\n\nwe apologize for the inconvenience and are doing our best to restore this functionality. check cobalt's socials or github for timely updates!",
"youtube.drm": "this youtube video is protected by widevine DRM, so i can't download it. try a different link!", "youtube.drm": "this youtube video is protected by widevine DRM, so i can't download it. try a different link!",
"youtube.no_session_tokens": "couldn't get required session tokens for youtube. this may be caused by a restriction on youtube's side. try again in a few seconds, but if this issue sticks, please report it!" "youtube.no_session_tokens": "couldn't get required session tokens for youtube. this may be caused by a restriction on youtube's side. try again in a few seconds, but if this issue sticks, please report it!",
"twitch.vod_not_supported": "the link you provided is a twitch vod, which is not supported! only twitch clips are supported."
} }