added video parsing

This commit is contained in:
hyperdefined 2024-07-11 20:41:51 -04:00
parent 5efe51098b
commit 5723239f10
No known key found for this signature in database
GPG Key ID: EB0B55B31E88AB03

View File

@ -2,25 +2,32 @@ import { genericUserAgent } from "../../config.js";
import { cleanString } from "../../sub/utils.js"; import { cleanString } from "../../sub/utils.js";
export default async function(obj) { export default async function(obj) {
let req; console.log(obj.type)
// handle video downloads // handle video downloads
if (obj.type == 'portal') { if (obj.type == 'portal') {
req = await fetch(`https://www.newgrounds.com/${obj.type}/video/${obj.id}`, { let req = await fetch(`https://www.newgrounds.com/${obj.type}/video/${obj.id}`, {
headers: { headers: {
'User-Agent': genericUserAgent, 'User-Agent': genericUserAgent,
'X-Requested-With': 'XMLHttpRequest', 'X-Requested-With': 'XMLHttpRequest',
Accept: 'application/json, text/javascript, */*; q=0.01'
} }
}) })
.then(request => request.text()) .then(request => request.text())
.catch(() => {}); .catch(() => {});
if (!req) return { error: 'ErrorEmptyDownload' }; if (!req) return { error: 'ErrorEmptyDownload' };
const json = JSON.parse(req);
const highestQuality = Object.keys(json.sources)[0];
const video = json.sources[highestQuality][0].src
return {
urls: video
}
} }
// handle audio downloads // handle audio downloads
if (obj.type == 'audio') { if (obj.type == 'audio') {
req = await fetch(`https://www.newgrounds.com/audio/listen/${obj.id}`, { let req = await fetch(`https://www.newgrounds.com/audio/listen/${obj.id}`, {
headers: { headers: {
'User-Agent': genericUserAgent, 'User-Agent': genericUserAgent,
} }
@ -32,12 +39,11 @@ export default async function(obj) {
const title = req.match(/"name"\s*:\s*"([^"]+)"/)?.[1]; const title = req.match(/"name"\s*:\s*"([^"]+)"/)?.[1];
const artist = req.match(/"artist"\s*:\s*"([^"]+)"/)?.[1]; const artist = req.match(/"artist"\s*:\s*"([^"]+)"/)?.[1];
const url = req.match(/"filename"\s*:\s*"([^"]+)"/)?.[1]?.replace(/\\\//g, '/');
let fileMetadata = { let fileMetadata = {
title: cleanString(decodeURIComponent(title.trim())), title: cleanString(decodeURIComponent(title.trim())),
artist: cleanString(decodeURIComponent(artist.trim())), artist: cleanString(decodeURIComponent(artist.trim())),
} }
const url = req.match(/"filename"\s*:\s*"([^"]+)"/)?.[1]?.replace(/\\\//g, '/');
return { return {
urls: url, urls: url,