tiktok: use webapp-based downloading method (#503)

Signed-off-by: Damir Modyarov <otomir@yandex.ru>
Co-authored-by: wukko <me@wukko.me>
This commit is contained in:
Damir Modyarov
2024-05-21 23:41:43 +03:00
committed by GitHub
parent b0da5bb893
commit 2534931b60
3 changed files with 68 additions and 52 deletions

View File

@@ -2,6 +2,7 @@ import { audioIgnore, services, supportedAudio } from "../config.js";
import { createResponse } from "../processing/request.js";
import loc from "../../localization/manager.js";
import createFilename from "./createFilename.js";
import { createStream } from "../stream/manage.js";
export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, disableMetadata, filenamePattern, toGif, requestIP) {
let action,
@@ -41,7 +42,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
case "photo":
responseType = "redirect";
break;
case "gif":
params = { type: "gif" }
break;
@@ -68,16 +69,22 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
params = { picker: r.picker };
break;
case "tiktok":
let pickerType = "render";
if (audioFormat === "mp3" || audioFormat === "best") {
let audioStreamType = "render";
if (r.bestAudio === "mp3" && (audioFormat === "mp3" || audioFormat === "best")) {
audioFormat = "mp3";
pickerType = "bridge"
audioStreamType = "bridge"
}
params = {
type: pickerType,
picker: r.picker,
u: Array.isArray(r.urls) ? r.urls[1] : r.urls,
copy: audioFormat === "best" ? true : false
u: createStream({
service: "tiktok",
type: audioStreamType,
u: r.urls,
filename: r.audioFilename,
isAudioOnly: true,
audioFormat,
}),
copy: audioFormat === "best"
}
}
break;
@@ -101,7 +108,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
responseType = "redirect";
}
break;
case "twitter":
if (r.type === "remux") {
params = { type: r.type };
@@ -125,7 +132,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
}
break;
case "audio":
case "audio":
if (audioIgnore.includes(host)
|| (host === "reddit" && r.typeId === "redirect")) {
return createResponse("error", { t: loc(lang, 'ErrorEmptyDownload') })
@@ -133,7 +140,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
let processType = "render",
copy = false;
if (!supportedAudio.includes(audioFormat)) {
audioFormat = "best"
}
@@ -146,11 +153,12 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
const isTumblrAudio = host === "tumblr" && !r.filename;
const isSoundCloud = host === "soundcloud";
const isTiktok = host === "tiktok";
if (isBestAudioDefined || isBestHostAudio) {
audioFormat = serviceBestAudio;
processType = "bridge";
if (isSoundCloud) {
if (isSoundCloud || (isTiktok && audioFormat === "m4a")) {
processType = "render"
copy = true
}