feat: streamable support

This commit is contained in:
Blobadoodle 2023-08-19 17:42:10 +01:00
parent 91a60c1ec2
commit cd1d699886
6 changed files with 75 additions and 1 deletions

View file

@ -18,6 +18,7 @@ import soundcloud from "./services/soundcloud.js";
import instagram from "./services/instagram.js";
import vine from "./services/vine.js";
import pinterest from "./services/pinterest.js";
import streamable from "./services/streamable.js";
export default async function (host, patternMatch, url, lang, obj) {
try {
@ -114,6 +115,13 @@ export default async function (host, patternMatch, url, lang, obj) {
case "pinterest":
r = await pinterest({ id: patternMatch["id"] });
break;
case "streamable":
r = await streamable({
id: patternMatch["id"],
quality: obj.vQuality,
isAudioOnly: isAudioOnly,
});
break;
default:
return apiJSON(0, { t: errorUnsupported(lang) });
}

View file

@ -56,6 +56,7 @@ export default function(r, host, audioFormat, isAudioOnly, lang, isAudioMuted) {
case "tumblr":
case "twitter":
case "pinterest":
case "streamable":
responseType = 1;
break;
}

View file

@ -0,0 +1,21 @@
export default async function(obj) {
const video = await fetch(`https://api.streamable.com/videos/${obj.id}`)
.then((r) => {
if (r.status === 404)
return undefined;
else
return r.json();
}).catch(() => { return false });
if (video === undefined) return { error: 'ErrorEmptyDownload' } ;
else if (!video) return { error: 'ErrorCouldntFetch' }; // not sure if this is the correct error here, should it be this or ErrorCantConnectToServiceAPI
let best;
if (obj.isAudioOnly || obj.quality === "max" || obj.quality >= "720") // audio seems to be compressed on the mp4-mobile version so isAudiOnly only usese the higest quality
best = video.files.mp4 ?? video.files['mp4-mobile'];
else
best = video.files['mp4-mobile'] ?? video.files.mp4;
if (best) return { urls: best.url, filename: `streamable_${obj.id}_${best.width}x${best.height}.mp4`, audioFilename: `streamable_${obj.id}_audio` }; // video filename isnt actually used since its redirected but who cares
else return { error: 'ErrorEmptyDownload' }
}

View file

@ -67,6 +67,11 @@
"alias": "pinterest videos & stories",
"patterns": ["pin/:id"],
"enabled": true
},
"streamable": {
"alias": "streamable videos",
"patterns": [":id", "o/:id"],
"enabled": true
}
}
}

View file

@ -30,5 +30,7 @@ export const testers = {
"vine": (patternMatch) => (patternMatch["id"] && patternMatch["id"].length <= 12),
"pinterest": (patternMatch) => (patternMatch["id"] && patternMatch["id"].length <= 128)
"pinterest": (patternMatch) => (patternMatch["id"] && patternMatch["id"].length <= 128),
"streamable": (patternMatch) => (patternMatch["id"] && patternMatch["id"].length == 6)
}

View file

@ -983,5 +983,42 @@
"code": 200,
"status": "redirect"
}
}],
"streamable": [{
"name": "regular video",
"url": "https://streamable.com/03r3c2",
"params": {},
"expected": {
"code": 200,
"status": "redirect"
}
}, {
"name": "regular video (isAudioOnly)",
"url": "https://streamable.com/03r3c2",
"params": {
"isAudioOnly": true
},
"expected": {
"code": 200,
"status": "stream"
}
}, {
"name": "regular video (isAudioMuted)",
"url": "https://streamable.com/03r3c2",
"params": {
"isAudioMuted": true
},
"expected": {
"code": 200,
"status": "stream"
}
}, {
"name": "inexistent video",
"url": "https://streamable.com/XXXXXX",
"params": {},
"expected": {
"code": 400,
"status": "error"
}
}]
}