mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-18 19:28:29 +00:00
added video parsing
This commit is contained in:
parent
5efe51098b
commit
5723239f10
@ -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,13 +39,12 @@ 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,
|
||||||
filenameAttributes: {
|
filenameAttributes: {
|
||||||
|
Loading…
Reference in New Issue
Block a user