mirror of
https://github.com/imputnet/cobalt.git
synced 2026-03-12 01:45:57 -05:00
- new localization system: fast, dynamic, way more organized - localization strings are WAY more descriptive - it's now easier to add support for other languages (just one loc file instead of five) - localization now falls back to english if localized string isnt available - got rid of all static language selectors (probably) - slightly updated english and russian strings - miscellaneous settings items have been bundled together and moved to the bottom, cause they're used the least - bottom links should no longer touch the popup border on overflow - rearranged popup order in the rendered page - bumped version up to 2.2.5 if you see strings that are like this: !!EXAMPLE!! or withoutspace please file an issue on github
28 lines
1.4 KiB
JavaScript
28 lines
1.4 KiB
JavaScript
import got from "got";
|
|
import loc from "../../localization/manager.js";
|
|
import { genericUserAgent, maxVideoDuration } from "../config.js";
|
|
|
|
export default async function(obj) {
|
|
try {
|
|
let req = await got.get(`https://www.reddit.com/r/${obj.sub}/comments/${obj.id}/${obj.name}.json`, { headers: { "user-agent": genericUserAgent } });
|
|
let data = (JSON.parse(req.body))[0]["data"]["children"][0]["data"];
|
|
if ("reddit_video" in data["secure_media"] && data["secure_media"]["reddit_video"]["duration"] * 1000 < maxVideoDuration) {
|
|
let video = data["secure_media"]["reddit_video"]["fallback_url"].split('?')[0],
|
|
audio = video.match('.mp4') ? `${video.split('_')[0]}_audio.mp4` : `${data["secure_media"]["reddit_video"]["fallback_url"].split('DASH')[0]}audio`;
|
|
try {
|
|
await got.head(audio, { headers: { "user-agent": genericUserAgent } });
|
|
} catch (err) {
|
|
audio = ''
|
|
}
|
|
if (audio.length > 0) {
|
|
return { typeId: 2, type: "render", urls: [video, audio], filename: `reddit_${data["secure_media"]["reddit_video"]["fallback_url"].split('/')[3]}.mp4` };
|
|
} else {
|
|
return { typeId: 1, urls: video};
|
|
}
|
|
} else {
|
|
return { error: loc(obj.lang, 'ErrorEmptyDownload') };
|
|
}
|
|
} catch (err) {
|
|
return { error: loc(obj.lang, 'ErrorBadFetch') };
|
|
}
|
|
} |