2023-02-12 07:40:49 +00:00
|
|
|
import { audioIgnore, services, supportedAudio } from "../config.js";
|
|
|
|
import { apiJSON } from "../sub/utils.js";
|
2022-12-06 19:21:07 +00:00
|
|
|
import loc from "../../localization/manager.js";
|
2023-10-12 18:14:54 +01:00
|
|
|
import createFilename from "./createFilename.js";
|
2022-08-12 14:36:19 +01:00
|
|
|
|
2023-10-12 18:14:54 +01:00
|
|
|
export default function(r, host, audioFormat, isAudioOnly, lang, isAudioMuted, disableMetadata, filenamePattern) {
|
2023-02-12 07:40:49 +00:00
|
|
|
let action,
|
|
|
|
responseType = 2,
|
|
|
|
defaultParams = {
|
|
|
|
u: r.urls,
|
2022-12-17 11:09:49 +00:00
|
|
|
service: host,
|
2023-10-12 18:14:54 +01:00
|
|
|
filename: r.filenameAttributes ?
|
|
|
|
createFilename(r.filenameAttributes, filenamePattern, isAudioOnly, isAudioMuted) : r.filename,
|
2023-08-24 09:31:39 +01:00
|
|
|
fileMetadata: !disableMetadata ? r.fileMetadata : false
|
2023-02-12 07:40:49 +00:00
|
|
|
},
|
|
|
|
params = {}
|
2023-08-24 09:31:39 +01:00
|
|
|
|
2023-08-20 17:30:26 +01:00
|
|
|
if (r.isPhoto) action = "photo";
|
|
|
|
else if (r.picker) action = "picker"
|
2023-08-20 17:11:42 +01:00
|
|
|
else if (isAudioMuted) action = "muteVideo";
|
2023-08-20 17:30:26 +01:00
|
|
|
else if (isAudioOnly) action = "audio";
|
|
|
|
else if (r.isM3U8) action = "singleM3U8";
|
2023-08-20 17:11:42 +01:00
|
|
|
else action = "video";
|
2023-02-12 07:40:49 +00:00
|
|
|
|
|
|
|
if (action === "picker" || action === "audio") {
|
2023-10-12 18:14:54 +01:00
|
|
|
if (!r.filenameAttributes) defaultParams.filename = r.audioFilename;
|
2023-02-12 07:40:49 +00:00
|
|
|
defaultParams.isAudioOnly = true;
|
|
|
|
defaultParams.audioFormat = audioFormat;
|
|
|
|
}
|
2023-10-12 18:14:54 +01:00
|
|
|
if (isAudioMuted && !r.filenameAttributes) {
|
|
|
|
defaultParams.filename = r.filename.replace('.', '_mute.')
|
|
|
|
}
|
2023-02-12 07:40:49 +00:00
|
|
|
|
|
|
|
switch (action) {
|
2023-08-20 14:36:56 +01:00
|
|
|
case "photo":
|
|
|
|
responseType = 1;
|
|
|
|
break;
|
2023-02-12 07:40:49 +00:00
|
|
|
case "video":
|
|
|
|
switch (host) {
|
|
|
|
case "bilibili":
|
2023-08-20 13:14:15 +01:00
|
|
|
params = { type: "render" };
|
2023-02-12 07:40:49 +00:00
|
|
|
break;
|
|
|
|
case "youtube":
|
2023-08-20 13:14:15 +01:00
|
|
|
params = { type: r.type };
|
2023-02-12 07:40:49 +00:00
|
|
|
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;
|
2023-09-16 11:27:53 +01:00
|
|
|
|
2023-04-29 17:26:49 +01:00
|
|
|
case "vine":
|
2023-04-24 20:01:25 +01:00
|
|
|
case "instagram":
|
2023-02-12 07:40:49 +00:00
|
|
|
case "tumblr":
|
|
|
|
case "twitter":
|
2023-05-24 18:32:41 +01:00
|
|
|
case "pinterest":
|
2023-08-19 17:42:10 +01:00
|
|
|
case "streamable":
|
2023-02-12 07:40:49 +00:00
|
|
|
responseType = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2023-03-15 16:18:31 +00:00
|
|
|
case "singleM3U8":
|
|
|
|
params = { type: "videoM3U8" }
|
|
|
|
break;
|
2023-02-12 07:40:49 +00:00
|
|
|
case "muteVideo":
|
|
|
|
params = {
|
|
|
|
type: Array.isArray(r.urls) ? "bridge" : "mute",
|
|
|
|
u: Array.isArray(r.urls) ? r.urls[0] : r.urls,
|
|
|
|
mute: true
|
|
|
|
}
|
2023-08-04 19:43:12 +01:00
|
|
|
if (host === "reddit" && r.typeId === 1) responseType = 1;
|
2023-02-12 07:40:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "picker":
|
|
|
|
responseType = 5;
|
|
|
|
switch (host) {
|
2023-04-24 20:01:25 +01:00
|
|
|
case "instagram":
|
2023-02-12 07:40:49 +00:00
|
|
|
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":
|
2023-03-15 16:18:31 +00:00
|
|
|
if ((host === "reddit" && r.typeId === 1) || audioIgnore.includes(host)) return apiJSON(0, { t: loc(lang, 'ErrorEmptyDownload') });
|
2023-02-12 07:40:49 +00:00
|
|
|
|
|
|
|
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"
|
2022-08-23 16:05:30 +01:00
|
|
|
}
|
2023-02-12 07:40:49 +00:00
|
|
|
}
|
2023-06-05 07:43:04 +01:00
|
|
|
if (host === "tumblr" && !r.filename && (audioFormat === "best" || audioFormat === "mp3")) {
|
|
|
|
audioFormat = "mp3";
|
|
|
|
processType = "bridge"
|
|
|
|
}
|
|
|
|
if ((audioFormat === "best" && services[host]["bestAudio"]) || (services[host]["bestAudio"] && (audioFormat === services[host]["bestAudio"]))) {
|
2023-02-12 07:40:49 +00:00
|
|
|
audioFormat = services[host]["bestAudio"];
|
2023-09-16 22:25:36 +01:00
|
|
|
if (host === "soundcloud") {
|
|
|
|
processType = "render"
|
|
|
|
copy = true
|
|
|
|
} else {
|
|
|
|
processType = "bridge"
|
|
|
|
}
|
2023-02-12 07:40:49 +00:00
|
|
|
} else if (audioFormat === "best") {
|
|
|
|
audioFormat = "m4a";
|
|
|
|
copy = true;
|
2023-10-12 18:14:54 +01:00
|
|
|
if (!r.filenameAttributes && r.audioFilename.includes("twitterspaces")) {
|
2022-10-24 14:03:11 +01:00
|
|
|
audioFormat = "mp3"
|
2023-02-12 07:40:49 +00:00
|
|
|
copy = false
|
2022-10-24 14:03:11 +01:00
|
|
|
}
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
2023-03-15 16:18:31 +00:00
|
|
|
if (r.isM3U8 || host === "vimeo") {
|
|
|
|
copy = false;
|
|
|
|
processType = "render"
|
|
|
|
}
|
2023-02-12 07:40:49 +00:00
|
|
|
|
|
|
|
params = {
|
|
|
|
type: processType,
|
|
|
|
u: Array.isArray(r.urls) ? r.urls[1] : r.urls,
|
|
|
|
audioFormat: audioFormat,
|
2023-08-20 13:14:15 +01:00
|
|
|
copy: copy
|
2022-12-06 19:21:07 +00:00
|
|
|
}
|
2023-02-12 07:40:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return apiJSON(0, { t: loc(lang, 'ErrorEmptyDownload') });
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
2023-02-12 07:40:49 +00:00
|
|
|
|
|
|
|
return apiJSON(responseType, {...defaultParams, ...params})
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|