mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-18 19:28:29 +00:00
initial newgrounds support
This commit is contained in:
parent
d68ce2f490
commit
5efe51098b
@ -25,7 +25,7 @@ import twitch from "./services/twitch.js";
|
||||
import rutube from "./services/rutube.js";
|
||||
import dailymotion from "./services/dailymotion.js";
|
||||
import loom from "./services/loom.js";
|
||||
|
||||
import newgrounds from "./services/newgrounds.js";
|
||||
let freebind;
|
||||
|
||||
export default async function(host, patternMatch, lang, obj) {
|
||||
@ -193,12 +193,21 @@ export default async function(host, patternMatch, lang, obj) {
|
||||
id: patternMatch.id
|
||||
});
|
||||
break;
|
||||
case "newgrounds":
|
||||
r = await newgrounds({
|
||||
type: patternMatch.type,
|
||||
method: patternMatch.method,
|
||||
id: patternMatch.id,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
return createResponse("error", {
|
||||
t: loc(lang, 'ErrorUnsupported')
|
||||
});
|
||||
}
|
||||
|
||||
console.log(r)
|
||||
|
||||
if (r.isAudioOnly) isAudioOnly = true;
|
||||
let isAudioMuted = isAudioOnly ? false : obj.isAudioMuted;
|
||||
|
||||
|
@ -100,6 +100,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
|
||||
case "video":
|
||||
switch (host) {
|
||||
case "bilibili":
|
||||
case "newgrounds":
|
||||
params = { type: "render" };
|
||||
break;
|
||||
case "youtube":
|
||||
@ -136,7 +137,6 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
|
||||
case "pinterest":
|
||||
case "streamable":
|
||||
case "loom":
|
||||
responseType = "redirect";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
52
src/modules/processing/services/newgrounds.js
Normal file
52
src/modules/processing/services/newgrounds.js
Normal 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
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
@ -118,6 +118,11 @@
|
||||
"alias": "loom videos",
|
||||
"patterns": ["share/:id"],
|
||||
"enabled": true
|
||||
},
|
||||
"newgrounds": {
|
||||
"alias": "newgrounds.com",
|
||||
"patterns": [":type/:method/:id"],
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,4 +58,7 @@ export const testers = {
|
||||
|
||||
"youtube": (patternMatch) =>
|
||||
patternMatch.id?.length <= 11,
|
||||
|
||||
"newgrounds": (patternMatch) =>
|
||||
patternMatch.id?.length <= 6,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user