Skip to content

Commit

Permalink
rutube: add support for private video links
Browse files Browse the repository at this point in the history
  • Loading branch information
wukko committed May 29, 2024
1 parent 490bbf8 commit 2a2183a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/modules/processing/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export default async function(host, patternMatch, lang, obj) {
r = await rutube({
id: patternMatch.id,
yappyId: patternMatch.yappyId,
key: patternMatch.key,
quality: obj.vQuality,
isAudioOnly: isAudioOnly
});
Expand Down
15 changes: 8 additions & 7 deletions src/modules/processing/services/rutube.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ async function requestJSON(url) {

export default async function(obj) {
if (obj.yappyId) {
let yappy = await requestJSON(
const yappy = await requestJSON(
`https://rutube.ru/pangolin/api/web/yappy/yappypage/?client=wdp&videoId=${obj.yappyId}&page=1&page_size=15`
)
let yappyURL = yappy?.results?.find(r => r.id === obj.yappyId)?.link;
const yappyURL = yappy?.results?.find(r => r.id === obj.yappyId)?.link;
if (!yappyURL) return { error: 'ErrorEmptyDownload' };

return {
Expand All @@ -25,11 +25,12 @@ export default async function(obj) {
}
}

let quality = obj.quality === "max" ? "9000" : obj.quality;
const quality = obj.quality === "max" ? "9000" : obj.quality;

let play = await requestJSON(
`https://rutube.ru/api/play/options/${obj.id}/?no_404=true&referer&pver=v2`
)
const requestURL = new URL(`https://rutube.ru/api/play/options/${obj.id}/?no_404=true&referer&pver=v2`);
if (obj.key) requestURL.searchParams.set('p', obj.key);

const play = await requestJSON(requestURL);
if (!play) return { error: 'ErrorCouldntFetch' };

if (play.detail || !play.video_balancer) return { error: 'ErrorEmptyDownload' };
Expand All @@ -51,7 +52,7 @@ export default async function(obj) {
bestQuality = m3u8.find((i) => (Number(quality) === i.resolution.height));
}

let fileMetadata = {
const fileMetadata = {
title: cleanString(play.title.trim()),
artist: cleanString(play.author.name.trim()),
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/processing/servicesConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"rutube": {
"alias": "rutube videos",
"tld": "ru",
"patterns": ["video/:id", "play/embed/:id", "shorts/:id", "yappy/:yappyId"],
"patterns": ["video/:id", "play/embed/:id", "shorts/:id", "yappy/:yappyId", "video/private/:id?p=:key", "video/private/:id"],
"enabled": true
},
"dailymotion": {
Expand Down
1 change: 1 addition & 0 deletions src/modules/processing/servicesPatternTesters.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const testers = {
|| (patternMatch.user?.length <= 22 && patternMatch.id?.length <= 10),

"rutube": (patternMatch) =>
(patternMatch.id?.length === 32 && patternMatch.key?.length <= 32) ||
patternMatch.id?.length === 32 || patternMatch.yappyId?.length === 32,

"soundcloud": (patternMatch) =>
Expand Down
5 changes: 5 additions & 0 deletions src/modules/processing/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ function cleanURL(url) {
limitQuery('v')
}
break;
case "rutube":
if (url.searchParams.get('p')) {
limitQuery('p')
}
break;
}

if (stripQuery) {
Expand Down
8 changes: 8 additions & 0 deletions src/test/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,14 @@
"code": 200,
"status": "stream"
}
}, {
"name": "private video",
"url": "https://rutube.ru/video/private/1161415be0e686214bb2a498165cab3e/?p=_IL1G8RSnKutunnTYwhZ5A",
"params": {},
"expected": {
"code": 200,
"status": "stream"
}
}],
"ok": [{
"name": "regular video",
Expand Down

0 comments on commit 2a2183a

Please sign in to comment.