2022-08-23 14:43:56 +00:00
|
|
|
import { audioIgnore, services, supportedAudio } from "../config.js"
|
2022-10-09 17:44:00 +00:00
|
|
|
import { apiJSON } from "../sub/utils.js"
|
2022-12-06 19:21:07 +00:00
|
|
|
import loc from "../../localization/manager.js";
|
2022-08-12 13:36:19 +00:00
|
|
|
|
2022-12-17 11:09:49 +00:00
|
|
|
export default function(r, host, ip, audioFormat, isAudioOnly, lang, isAudioMuted) {
|
|
|
|
if (!isAudioOnly && !r.picker && !isAudioMuted) {
|
2022-12-06 19:21:07 +00:00
|
|
|
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":
|
2022-12-17 11:09:49 +00:00
|
|
|
if (Array.isArray(r.urls)) {
|
2022-08-12 13:36:19 +00:00
|
|
|
return apiJSON(2, {
|
|
|
|
type: "render", u: r.urls, service: host, ip: ip,
|
2022-12-06 19:21:07 +00:00
|
|
|
filename: r.filename
|
2022-09-11 15:04:06 +00:00
|
|
|
});
|
2022-12-06 19:21:07 +00:00
|
|
|
} else {
|
2022-09-11 15:04:06 +00:00
|
|
|
return apiJSON(1, { u: r.urls });
|
2022-12-06 19:21:07 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-13 18:34:48 +00:00
|
|
|
} else if (isAudioMuted && !isAudioOnly) {
|
2022-12-17 11:09:49 +00:00
|
|
|
let isSplit = Array.isArray(r.urls);
|
|
|
|
return apiJSON(2, {
|
|
|
|
type: isSplit ? "bridge" : "mute",
|
|
|
|
u: isSplit ? r.urls[0] : r.urls,
|
|
|
|
service: host,
|
|
|
|
ip: ip,
|
|
|
|
filename: r.filename,
|
|
|
|
mute: true,
|
|
|
|
});
|
2022-12-06 19:21:07 +00:00
|
|
|
} else if (r.picker) {
|
|
|
|
switch (host) {
|
|
|
|
case "douyin":
|
|
|
|
case "tiktok":
|
|
|
|
let type = "render";
|
|
|
|
if (audioFormat === "mp3" || audioFormat === "best") {
|
|
|
|
audioFormat = "mp3"
|
2022-08-23 15:05:30 +00:00
|
|
|
type = "bridge"
|
|
|
|
}
|
2022-12-06 19:21:07 +00:00
|
|
|
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
|
|
|
|
})
|
|
|
|
}
|
2023-01-13 18:34:48 +00:00
|
|
|
} else if (isAudioOnly) {
|
2022-12-06 19:21:07 +00:00
|
|
|
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";
|
2023-01-13 18:34:48 +00:00
|
|
|
if ((host == "tiktok" || host == "douyin") && services.tiktok.audioFormats.includes(audioFormat)) {
|
2022-12-06 19:21:07 +00:00
|
|
|
if (r.isMp3) {
|
|
|
|
if (audioFormat === "mp3" || audioFormat === "best") {
|
2022-10-24 13:03:11 +00:00
|
|
|
audioFormat = "mp3"
|
2022-12-06 19:21:07 +00:00
|
|
|
type = "bridge"
|
2022-10-24 13:03:11 +00:00
|
|
|
}
|
2022-12-06 19:21:07 +00:00
|
|
|
} else if (audioFormat === "best") {
|
|
|
|
audioFormat = "m4a"
|
|
|
|
type = "bridge"
|
2022-08-12 13:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-06 19:21:07 +00:00
|
|
|
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
|
|
|
|
})
|
2023-01-13 18:34:48 +00:00
|
|
|
} else {
|
|
|
|
return apiJSON(0, { t: loc(lang, 'ErrorSomethingWentWrong') });
|
2022-08-12 13:36:19 +00:00
|
|
|
}
|
|
|
|
}
|