newgrounds: return proper error codes
This commit is contained in:
parent
985bedf5fb
commit
38d5d02938
1 changed files with 7 additions and 7 deletions
|
@ -71,19 +71,19 @@ async function getVideo(obj) {
|
||||||
.then(request => request.text())
|
.then(request => request.text())
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
|
|
||||||
if (!req) return { error: 'ErrorCouldntFetch' };
|
if (!req) return { error: 'fetch.fail' };
|
||||||
|
|
||||||
let json;
|
let json;
|
||||||
try {
|
try {
|
||||||
json = JSON.parse(req);
|
json = JSON.parse(req);
|
||||||
} catch { return { error: 'ErrorEmptyDownload' }; }
|
} catch { return { error: 'fetch.empty' }; }
|
||||||
|
|
||||||
const videoData = getQuality(json.sources, obj.quality);
|
const videoData = getQuality(json.sources, obj.quality);
|
||||||
if (videoData == null) {
|
if (videoData == null) {
|
||||||
return { error: 'ErrorCouldntFetch' };
|
return { error: 'fetch.empty' };
|
||||||
}
|
}
|
||||||
if (!videoData.type.includes('mp4')) {
|
if (!videoData.type.includes('mp4')) {
|
||||||
return { error: 'ErrorCouldntFetch' };
|
return { error: 'fetch.empty' };
|
||||||
}
|
}
|
||||||
|
|
||||||
let fileMetadata = {
|
let fileMetadata = {
|
||||||
|
@ -115,14 +115,14 @@ async function getMusic(obj) {
|
||||||
.then(request => request.text())
|
.then(request => request.text())
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
|
|
||||||
if (!req) return { error: 'ErrorCouldntFetch' };
|
if (!req) return { error: 'fetch.fail' };
|
||||||
|
|
||||||
const titleMatch = req.match(/"name"\s*:\s*"([^"]+)"/);
|
const titleMatch = req.match(/"name"\s*:\s*"([^"]+)"/);
|
||||||
const artistMatch = req.match(/"artist"\s*:\s*"([^"]+)"/);
|
const artistMatch = req.match(/"artist"\s*:\s*"([^"]+)"/);
|
||||||
const urlMatch = req.match(/"filename"\s*:\s*"([^"]+)"/);
|
const urlMatch = req.match(/"filename"\s*:\s*"([^"]+)"/);
|
||||||
|
|
||||||
if (!titleMatch || !artistMatch || !urlMatch) {
|
if (!titleMatch || !artistMatch || !urlMatch) {
|
||||||
return { error: 'ErrorCouldntFetch' };
|
return { error: 'fetch.empty' };
|
||||||
}
|
}
|
||||||
|
|
||||||
const title = titleMatch[1];
|
const title = titleMatch[1];
|
||||||
|
@ -153,5 +153,5 @@ export default function(obj) {
|
||||||
if (obj.type == 'audio') {
|
if (obj.type == 'audio') {
|
||||||
return getMusic(obj);
|
return getMusic(obj);
|
||||||
}
|
}
|
||||||
return { error: 'ErrorUnsupported' };
|
return { error: 'link.unsupported' };
|
||||||
}
|
}
|
Loading…
Reference in a new issue