initial newgrounds support

This commit is contained in:
hyperdefined 2024-07-11 20:20:23 -04:00
parent d68ce2f490
commit 5efe51098b
No known key found for this signature in database
GPG Key ID: EB0B55B31E88AB03
5 changed files with 71 additions and 2 deletions

View File

@ -25,7 +25,7 @@ import twitch from "./services/twitch.js";
import rutube from "./services/rutube.js"; import rutube from "./services/rutube.js";
import dailymotion from "./services/dailymotion.js"; import dailymotion from "./services/dailymotion.js";
import loom from "./services/loom.js"; import loom from "./services/loom.js";
import newgrounds from "./services/newgrounds.js";
let freebind; let freebind;
export default async function(host, patternMatch, lang, obj) { export default async function(host, patternMatch, lang, obj) {
@ -193,12 +193,21 @@ export default async function(host, patternMatch, lang, obj) {
id: patternMatch.id id: patternMatch.id
}); });
break; break;
case "newgrounds":
r = await newgrounds({
type: patternMatch.type,
method: patternMatch.method,
id: patternMatch.id,
});
break;
default: default:
return createResponse("error", { return createResponse("error", {
t: loc(lang, 'ErrorUnsupported') t: loc(lang, 'ErrorUnsupported')
}); });
} }
console.log(r)
if (r.isAudioOnly) isAudioOnly = true; if (r.isAudioOnly) isAudioOnly = true;
let isAudioMuted = isAudioOnly ? false : obj.isAudioMuted; let isAudioMuted = isAudioOnly ? false : obj.isAudioMuted;

View File

@ -100,6 +100,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
case "video": case "video":
switch (host) { switch (host) {
case "bilibili": case "bilibili":
case "newgrounds":
params = { type: "render" }; params = { type: "render" };
break; break;
case "youtube": case "youtube":
@ -136,7 +137,6 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
case "pinterest": case "pinterest":
case "streamable": case "streamable":
case "loom": case "loom":
responseType = "redirect";
break; break;
} }
break; break;

View File

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

View File

@ -118,6 +118,11 @@
"alias": "loom videos", "alias": "loom videos",
"patterns": ["share/:id"], "patterns": ["share/:id"],
"enabled": true "enabled": true
},
"newgrounds": {
"alias": "newgrounds.com",
"patterns": [":type/:method/:id"],
"enabled": true
} }
} }
} }

View File

@ -58,4 +58,7 @@ export const testers = {
"youtube": (patternMatch) => "youtube": (patternMatch) =>
patternMatch.id?.length <= 11, patternMatch.id?.length <= 11,
"newgrounds": (patternMatch) =>
patternMatch.id?.length <= 6,
} }