From 890b7c8924945fff26f5d7953450a5eebc1f941f Mon Sep 17 00:00:00 2001 From: wukko Date: Sun, 20 Aug 2023 15:18:21 +0600 Subject: [PATCH] streamable: clean up + more patterns --- src/modules/processing/services/streamable.js | 32 +++++++++---------- src/modules/processing/servicesConfig.json | 4 +-- src/test/tests.json | 8 +++++ 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/modules/processing/services/streamable.js b/src/modules/processing/services/streamable.js index 7a70d4b..29b6dec 100644 --- a/src/modules/processing/services/streamable.js +++ b/src/modules/processing/services/streamable.js @@ -1,21 +1,19 @@ 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 }); + let video = await fetch(`https://api.streamable.com/videos/${obj.id}`).then((r) => { return r.status === 200 ? r.json() : false }).catch(() => { return false }); + if (!video) return { error: 'ErrorEmptyDownload' }; - if (video === undefined) return { error: 'ErrorEmptyDownload' } ; - else if (!video) return { error: 'ErrorCouldntFetch' }; + let best = video.files['mp4-mobile']; + if (video.files.mp4 && (obj.isAudioOnly || obj.quality === "max" || obj.quality >= Number("720"))) { + best = video.files.mp4; + } - let best; - if (obj.isAudioOnly || obj.quality === "max" || obj.quality >= "720") // audio seems to be compressed on the mp4-mobile version so isAudioOnly only uses 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` }; - else return { error: 'ErrorEmptyDownload' } + if (best) return { + urls: best.url, + filename: `streamable_${obj.id}_${best.width}x${best.height}.mp4`, + audioFilename: `streamable_${obj.id}_audio`, + metadata: { + title: video.title + } + } + return { error: 'ErrorEmptyDownload' } } diff --git a/src/modules/processing/servicesConfig.json b/src/modules/processing/servicesConfig.json index 69dad6a..aadc392 100644 --- a/src/modules/processing/servicesConfig.json +++ b/src/modules/processing/servicesConfig.json @@ -2,7 +2,7 @@ "audioIgnore": ["vk"], "config": { "bilibili": { - "alias": "bilibili (.com only)", + "alias": "bilibili.com videos", "patterns": ["video/:id"], "enabled": true }, @@ -70,7 +70,7 @@ }, "streamable": { "alias": "streamable videos", - "patterns": [":id", "o/:id"], + "patterns": [":id", "o/:id", "e/:id", "s/:id"], "enabled": true } } diff --git a/src/test/tests.json b/src/test/tests.json index c777f9e..e72421d 100644 --- a/src/test/tests.json +++ b/src/test/tests.json @@ -992,6 +992,14 @@ "code": 200, "status": "redirect" } + }, { + "name": "embedded link", + "url": "https://streamable.com/e/rsmo56", + "params": {}, + "expected": { + "code": 200, + "status": "redirect" + } }, { "name": "regular video (isAudioOnly)", "url": "https://streamable.com/03r3c2",