2022-08-23 14:43:56 +00:00
|
|
|
import { audioIgnore, services, supportedAudio } from "../config.js"
|
2022-08-12 13:36:19 +00:00
|
|
|
import { apiJSON } from "./utils.js"
|
|
|
|
|
|
|
|
export default function(r, host, ip, audioFormat, isAudioOnly) {
|
|
|
|
if (!r.error) {
|
|
|
|
if (!isAudioOnly) {
|
|
|
|
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, salt: process.env.streamSalt
|
|
|
|
})
|
|
|
|
case "bilibili":
|
|
|
|
return apiJSON(2, {
|
|
|
|
type: "render", u: r.urls, service: host, ip: ip,
|
|
|
|
filename: r.filename, salt: process.env.streamSalt,
|
|
|
|
time: r.time
|
|
|
|
})
|
|
|
|
case "youtube":
|
|
|
|
return apiJSON(2, {
|
|
|
|
type: r.type, u: r.urls, service: host, ip: ip,
|
|
|
|
filename: r.filename, salt: process.env.streamSalt,
|
|
|
|
time: r.time,
|
|
|
|
})
|
|
|
|
case "reddit":
|
|
|
|
return apiJSON(r.typeId, {
|
|
|
|
type: r.type, u: r.urls, service: host, ip: ip,
|
|
|
|
filename: r.filename, salt: process.env.streamSalt
|
|
|
|
})
|
|
|
|
case "tiktok":
|
|
|
|
return apiJSON(2, {
|
|
|
|
type: "bridge", u: r.urls, service: host, ip: ip,
|
|
|
|
filename: r.filename, salt: process.env.streamSalt
|
|
|
|
})
|
|
|
|
case "douyin":
|
|
|
|
return apiJSON(2, {
|
|
|
|
type: "bridge", u: r.urls, service: host, ip: ip,
|
|
|
|
filename: r.filename, salt: process.env.streamSalt
|
|
|
|
})
|
|
|
|
case "tumblr":
|
2022-08-16 07:14:19 +00:00
|
|
|
return apiJSON(1, { u: r.urls })
|
2022-08-13 11:14:09 +00:00
|
|
|
case "vimeo":
|
2022-08-16 07:14:19 +00:00
|
|
|
return apiJSON(1, { u: r.urls })
|
2022-08-12 13:36:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let type = "render"
|
|
|
|
let copy = false
|
|
|
|
if (!supportedAudio.includes(audioFormat)) audioFormat = "best";
|
2022-08-22 14:10:54 +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
|
2022-08-12 13:36:19 +00:00
|
|
|
}
|
2022-08-23 14:47:08 +00:00
|
|
|
if ((host == "tiktok" || host == "douyin") && r.isAudio && audioFormat == "best") {
|
2022-08-23 14:43:56 +00:00
|
|
|
if (r.isMp3) {
|
|
|
|
audioFormat = "mp3"
|
|
|
|
type = "bridge"
|
|
|
|
copy = false
|
|
|
|
} else {
|
|
|
|
type = "bridge"
|
|
|
|
copy = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (host == "reddit" && r.typeId == 1 || audioIgnore.includes(host)) return apiJSON(0, { t: r.audioFilename });
|
2022-08-12 13:36:19 +00:00
|
|
|
return apiJSON(2, {
|
|
|
|
type: type,
|
|
|
|
u: Array.isArray(r.urls) ? r.urls[1] : r.urls, service: host, ip: ip,
|
|
|
|
filename: r.audioFilename, salt: process.env.streamSalt, isAudioOnly: true, audioFormat: audioFormat, copy: copy
|
|
|
|
})
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return apiJSON(0, { t: r.error });
|
|
|
|
}
|
|
|
|
}
|