tiktok: use new cookie for each request (#514)

* api: allow passing headers from service handler

* tiktok: use new cookie for each request
This commit is contained in:
jj 2024-05-23 18:29:39 +02:00 committed by GitHub
parent 930faea09a
commit 72246cbc1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 39 additions and 22 deletions

View file

@ -192,8 +192,11 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
const streamInfo = getInternalStream(req.query.id);
if (!streamInfo) return res.sendStatus(404);
streamInfo.headers = req.headers;
streamInfo.headers = {
...req.headers,
...streamInfo.headers
};
return stream(res, { type: 'internal', ...streamInfo });
} catch {
return res.destroy();

View file

@ -9,6 +9,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
responseType = "stream",
defaultParams = {
u: r.urls,
headers: r.headers,
service: host,
filename: r.filenameAttributes ?
createFilename(r.filenameAttributes, filenamePattern, isAudioOnly, isAudioMuted) : r.filename,
@ -80,6 +81,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
service: "tiktok",
type: audioStreamType,
u: r.urls,
headers: r.headers,
filename: r.audioFilename,
isAudioOnly: true,
audioFormat,

View file

@ -4,9 +4,9 @@ import { extract } from "../url.js";
import Cookie from "../cookie/cookie.js";
const shortDomain = "https://vt.tiktok.com/";
export const cookie = new Cookie({});
export default async function(obj) {
const cookie = new Cookie({});
let postId = obj.postId;
if (!postId) {
@ -75,32 +75,46 @@ export default async function(obj) {
if (audio.includes("mime_type=audio_mpeg")) bestAudio = 'mp3';
}
if (video) return {
urls: video,
filename: videoFilename
if (video) {
return {
urls: video,
filename: videoFilename,
headers: { cookie }
}
}
if (images && obj.isAudioOnly) return {
urls: audio,
audioFilename: audioFilename,
isAudioOnly: true,
bestAudio
if (images && obj.isAudioOnly) {
return {
urls: audio,
audioFilename: audioFilename,
isAudioOnly: true,
bestAudio,
headers: { cookie }
}
}
if (images) {
let imageLinks = images
.map(i => i.imageURL.urlList.find(p => p.includes(".jpeg?")))
.map(url => ({ url }))
.map(url => ({ url }));
return {
picker: imageLinks,
urls: audio,
audioFilename: audioFilename,
isAudioOnly: true,
bestAudio
bestAudio,
headers: { cookie }
}
}
if (audio) return {
urls: audio,
audioFilename: audioFilename,
isAudioOnly: true,
bestAudio
if (audio) {
return {
urls: audio,
audioFilename: audioFilename,
isAudioOnly: true,
bestAudio,
headers: { cookie }
}
}
}

View file

@ -38,6 +38,7 @@ export function createStream(obj) {
filename: obj.filename,
audioFormat: obj.audioFormat,
isAudioOnly: !!obj.isAudioOnly,
headers: obj.headers,
copy: !!obj.copy,
mute: !!obj.mute,
metadata: obj.fileMetadata || false,
@ -82,6 +83,7 @@ export function createInternalStream(url, obj = {}) {
internalStreamCache[streamID] = {
url,
service: obj.service,
headers: obj.headers,
controller: new AbortController(),
dispatcher
};

View file

@ -1,5 +1,4 @@
import { genericUserAgent } from "../config.js";
import { cookie as tiktokCookie } from "../processing/services/tiktok.js";
const defaultHeaders = {
'user-agent': genericUserAgent
@ -14,9 +13,6 @@ const serviceHeaders = {
origin: 'https://www.youtube.com',
referer: 'https://www.youtube.com',
DNT: '?1'
},
tiktok: {
cookie: tiktokCookie
}
}