Skip to content

api/twitch: check for twitch vods & prompt #1300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions api/src/processing/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,19 @@ export default async function({ host, patternMatch, params, isSession }) {
break;

case "twitch":
r = await twitch({
clipId: patternMatch.clip || false,
quality: params.videoQuality,
isAudioOnly,
});
if (url.pathname.includes('/videos/')) {
r = await twitch({
clipId: false,
type: 'vod'
});
}
if (url.pathname.includes('/clip/')) {
r = await twitch({
clipId: patternMatch.clip || false,
quality: params.videoQuality,
isAudioOnly,
});
}
break;

case "rutube":
Expand Down
5 changes: 4 additions & 1 deletion api/src/processing/service-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ export const services = {
subdomains: "*",
},
twitch: {
patterns: [":channel/clip/:clip"],
patterns: [
":channel/clip/:clip",
":type/:videoId"
],
tld: "tv",
},
twitter: {
Expand Down
3 changes: 2 additions & 1 deletion api/src/processing/service-patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export const testers = {
|| (pattern.id?.length < 21 && pattern.user?.length <= 32),

"twitch": pattern =>
pattern.channel && pattern.clip?.length <= 100,
pattern.channel && pattern.clip?.length <= 100
|| pattern.type === 'videos' && pattern.videoId?.length >= 1,

"twitter": pattern =>
pattern.id?.length < 20,
Expand Down
2 changes: 2 additions & 0 deletions api/src/processing/services/twitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const gqlURL = "https://gql.twitch.tv/gql";
const clientIdHead = { "client-id": "kimne78kx3ncx6brgo4mv6wki5h1ko" };

export default async function (obj) {
if (obj.type === 'vod') return { error: "twitch.vod_not_supported" };

const req_metadata = await fetch(gqlURL, {
method: "POST",
headers: clientIdHead,
Expand Down
3 changes: 3 additions & 0 deletions api/src/processing/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ function aliasURL(url) {
if (url.hostname === 'clips.twitch.tv' && parts.length >= 2) {
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;

case "bilibili":
Expand Down
4 changes: 3 additions & 1 deletion web/i18n/en/error/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.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.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."
}
Loading