5.0-dev1
- rewrote and/or optimized all service modules - rewrote matching and processing modules to optimize readability and performance - added support for reddit gifs - fixed various issues with twitter error explanations - code optimizations and enhancements (such as finally getting rid of ==, prettier and more readable formatting, etc) - added branch information - all functions in currentCommit submodule run only once and cache received data - added a test script. only twitter and soundcloud are 100% covered and tested atm, will add tests (and probably fixes) for the rest of services in next commits - changed some localization strings for russian - added more clarity to rate limit message - moved services folder into processing folder
This commit is contained in:
@@ -1,121 +1,137 @@
|
||||
import { audioIgnore, services, supportedAudio } from "../config.js"
|
||||
import { apiJSON } from "../sub/utils.js"
|
||||
import { audioIgnore, services, supportedAudio } from "../config.js";
|
||||
import { apiJSON } from "../sub/utils.js";
|
||||
import loc from "../../localization/manager.js";
|
||||
|
||||
export default function(r, host, ip, audioFormat, isAudioOnly, lang, isAudioMuted) {
|
||||
if (!isAudioOnly && !r.picker && !isAudioMuted) {
|
||||
switch (host) {
|
||||
case "twitter":
|
||||
return apiJSON(1, { u: r.urls });
|
||||
case "vk":
|
||||
return apiJSON(2, {
|
||||
type: "bridge", u: r.urls, service: host, ip: ip,
|
||||
filename: r.filename,
|
||||
});
|
||||
case "bilibili":
|
||||
return apiJSON(2, {
|
||||
type: "render", u: r.urls, service: host, ip: ip,
|
||||
filename: r.filename,
|
||||
time: r.time
|
||||
});
|
||||
case "youtube":
|
||||
return apiJSON(2, {
|
||||
type: r.type, u: r.urls, service: host, ip: ip,
|
||||
filename: r.filename,
|
||||
time: r.time,
|
||||
});
|
||||
case "reddit":
|
||||
return apiJSON(r.typeId, {
|
||||
type: r.type, u: r.urls, service: host, ip: ip,
|
||||
filename: r.filename,
|
||||
});
|
||||
case "tiktok":
|
||||
return apiJSON(2, {
|
||||
type: "bridge", u: r.urls, service: host, ip: ip,
|
||||
filename: r.filename,
|
||||
});
|
||||
case "douyin":
|
||||
return apiJSON(2, {
|
||||
type: "bridge", u: r.urls, service: host, ip: ip,
|
||||
filename: r.filename,
|
||||
});
|
||||
case "tumblr":
|
||||
return apiJSON(1, { u: r.urls });
|
||||
case "vimeo":
|
||||
if (Array.isArray(r.urls)) {
|
||||
return apiJSON(2, {
|
||||
type: "render", u: r.urls, service: host, ip: ip,
|
||||
filename: r.filename
|
||||
});
|
||||
} else {
|
||||
return apiJSON(1, { u: r.urls });
|
||||
}
|
||||
}
|
||||
} else if (isAudioMuted && !isAudioOnly) {
|
||||
let isSplit = Array.isArray(r.urls);
|
||||
return apiJSON(2, {
|
||||
type: isSplit ? "bridge" : "mute",
|
||||
u: isSplit ? r.urls[0] : r.urls,
|
||||
let action,
|
||||
responseType = 2,
|
||||
defaultParams = {
|
||||
u: r.urls,
|
||||
service: host,
|
||||
ip: ip,
|
||||
filename: r.filename,
|
||||
mute: true,
|
||||
});
|
||||
} else if (r.picker) {
|
||||
switch (host) {
|
||||
case "douyin":
|
||||
case "tiktok":
|
||||
let type = "render";
|
||||
if (audioFormat === "mp3" || audioFormat === "best") {
|
||||
audioFormat = "mp3"
|
||||
type = "bridge"
|
||||
}
|
||||
return apiJSON(5, {
|
||||
type: type,
|
||||
picker: r.picker,
|
||||
u: Array.isArray(r.urls) ? r.urls[1] : r.urls, service: host, ip: ip,
|
||||
filename: r.audioFilename, isAudioOnly: true, audioFormat: audioFormat, copy: audioFormat === "best" ? true : false,
|
||||
})
|
||||
case "twitter":
|
||||
return apiJSON(5, {
|
||||
picker: r.picker, service: host
|
||||
})
|
||||
}
|
||||
} else if (isAudioOnly) {
|
||||
if ((host === "reddit" && r.typeId === 1) || (host === "vimeo" && !r.filename) || audioIgnore.includes(host)) return apiJSON(0, { t: loc(lang, 'ErrorEmptyDownload') });
|
||||
let type = "render";
|
||||
let copy = false;
|
||||
|
||||
if (!supportedAudio.includes(audioFormat)) audioFormat = "best";
|
||||
if ((host == "tiktok" || host == "douyin") && services.tiktok.audioFormats.includes(audioFormat)) {
|
||||
if (r.isMp3) {
|
||||
if (audioFormat === "mp3" || audioFormat === "best") {
|
||||
audioFormat = "mp3"
|
||||
type = "bridge"
|
||||
}
|
||||
} else if (audioFormat === "best") {
|
||||
audioFormat = "m4a"
|
||||
type = "bridge"
|
||||
}
|
||||
}
|
||||
if ((audioFormat === "best" && services[host]["bestAudio"]) || services[host]["bestAudio"] && (audioFormat === services[host]["bestAudio"])) {
|
||||
audioFormat = services[host]["bestAudio"]
|
||||
type = "bridge"
|
||||
} else if (audioFormat === "best") {
|
||||
audioFormat = "m4a"
|
||||
copy = true
|
||||
if (r.audioFilename.includes("twitterspaces")) {
|
||||
audioFormat = "mp3"
|
||||
copy = false
|
||||
}
|
||||
}
|
||||
return apiJSON(2, {
|
||||
type: type,
|
||||
u: Array.isArray(r.urls) ? r.urls[1] : r.urls, service: host, ip: ip,
|
||||
filename: r.audioFilename, isAudioOnly: true,
|
||||
audioFormat: audioFormat, copy: copy, fileMetadata: r.fileMetadata ? r.fileMetadata : false
|
||||
})
|
||||
} else {
|
||||
return apiJSON(0, { t: loc(lang, 'ErrorSomethingWentWrong') });
|
||||
},
|
||||
params = {}
|
||||
|
||||
if (isAudioMuted) action = "muteVideo";
|
||||
if (!isAudioOnly && !r.picker && !isAudioMuted) action = "video";
|
||||
if (r.picker) action = "picker";
|
||||
if (isAudioOnly) action = "audio";
|
||||
|
||||
if (action === "picker" || action === "audio") {
|
||||
defaultParams.filename = r.audioFilename;
|
||||
defaultParams.isAudioOnly = true;
|
||||
defaultParams.audioFormat = audioFormat;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case "video":
|
||||
switch (host) {
|
||||
case "bilibili":
|
||||
params = { type: "render", time: r.time };
|
||||
break;
|
||||
case "youtube":
|
||||
params = { type: r.type, time: r.time };
|
||||
break;
|
||||
case "reddit":
|
||||
responseType = r.typeId;
|
||||
params = { type: r.type };
|
||||
break;
|
||||
case "vimeo":
|
||||
if (Array.isArray(r.urls)) {
|
||||
params = { type: "render" }
|
||||
} else {
|
||||
responseType = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case "vk":
|
||||
case "douyin":
|
||||
case "tiktok":
|
||||
params = { type: "bridge" };
|
||||
break;
|
||||
|
||||
case "tumblr":
|
||||
case "twitter":
|
||||
responseType = 1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case "muteVideo":
|
||||
params = {
|
||||
type: Array.isArray(r.urls) ? "bridge" : "mute",
|
||||
u: Array.isArray(r.urls) ? r.urls[0] : r.urls,
|
||||
mute: true
|
||||
}
|
||||
break;
|
||||
|
||||
case "picker":
|
||||
responseType = 5;
|
||||
switch (host) {
|
||||
case "twitter":
|
||||
params = { picker: r.picker };
|
||||
break;
|
||||
case "douyin":
|
||||
case "tiktok":
|
||||
let pickerType = "render";
|
||||
if (audioFormat === "mp3" || audioFormat === "best") {
|
||||
audioFormat = "mp3";
|
||||
pickerType = "bridge"
|
||||
}
|
||||
params = {
|
||||
type: pickerType,
|
||||
picker: r.picker,
|
||||
u: Array.isArray(r.urls) ? r.urls[1] : r.urls,
|
||||
copy: audioFormat === "best" ? true : false
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "audio":
|
||||
if ((host === "reddit" && r.typeId === 1) || (host === "vimeo" && !r.filename) || audioIgnore.includes(host)) return apiJSON(0, { t: loc(lang, 'ErrorEmptyDownload') });
|
||||
|
||||
let processType = "render";
|
||||
let copy = false;
|
||||
|
||||
if (!supportedAudio.includes(audioFormat)) audioFormat = "best";
|
||||
|
||||
if ((host === "tiktok" || host === "douyin") && services.tiktok.audioFormats.includes(audioFormat)) {
|
||||
if (r.isMp3) {
|
||||
if (audioFormat === "mp3" || audioFormat === "best") {
|
||||
audioFormat = "mp3";
|
||||
processType = "bridge"
|
||||
}
|
||||
} else if (audioFormat === "best") {
|
||||
audioFormat = "m4a";
|
||||
processType = "bridge"
|
||||
}
|
||||
}
|
||||
|
||||
if ((audioFormat === "best" && services[host]["bestAudio"])
|
||||
|| services[host]["bestAudio"] && (audioFormat === services[host]["bestAudio"])) {
|
||||
audioFormat = services[host]["bestAudio"];
|
||||
processType = "bridge"
|
||||
} else if (audioFormat === "best") {
|
||||
audioFormat = "m4a";
|
||||
copy = true;
|
||||
if (r.audioFilename.includes("twitterspaces")) {
|
||||
audioFormat = "mp3"
|
||||
copy = false
|
||||
}
|
||||
}
|
||||
|
||||
params = {
|
||||
type: processType,
|
||||
u: Array.isArray(r.urls) ? r.urls[1] : r.urls,
|
||||
audioFormat: audioFormat,
|
||||
copy: copy,
|
||||
fileMetadata: r.fileMetadata ? r.fileMetadata : false
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return apiJSON(0, { t: loc(lang, 'ErrorEmptyDownload') });
|
||||
}
|
||||
|
||||
return apiJSON(responseType, {...defaultParams, ...params})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user