mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 12:50:01 +00:00
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:
parent
930faea09a
commit
72246cbc1f
5 changed files with 39 additions and 22 deletions
|
@ -192,7 +192,10 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
|
||||||
|
|
||||||
const streamInfo = getInternalStream(req.query.id);
|
const streamInfo = getInternalStream(req.query.id);
|
||||||
if (!streamInfo) return res.sendStatus(404);
|
if (!streamInfo) return res.sendStatus(404);
|
||||||
streamInfo.headers = req.headers;
|
streamInfo.headers = {
|
||||||
|
...req.headers,
|
||||||
|
...streamInfo.headers
|
||||||
|
};
|
||||||
|
|
||||||
return stream(res, { type: 'internal', ...streamInfo });
|
return stream(res, { type: 'internal', ...streamInfo });
|
||||||
} catch {
|
} catch {
|
||||||
|
|
|
@ -9,6 +9,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
|
||||||
responseType = "stream",
|
responseType = "stream",
|
||||||
defaultParams = {
|
defaultParams = {
|
||||||
u: r.urls,
|
u: r.urls,
|
||||||
|
headers: r.headers,
|
||||||
service: host,
|
service: host,
|
||||||
filename: r.filenameAttributes ?
|
filename: r.filenameAttributes ?
|
||||||
createFilename(r.filenameAttributes, filenamePattern, isAudioOnly, isAudioMuted) : r.filename,
|
createFilename(r.filenameAttributes, filenamePattern, isAudioOnly, isAudioMuted) : r.filename,
|
||||||
|
@ -80,6 +81,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
|
||||||
service: "tiktok",
|
service: "tiktok",
|
||||||
type: audioStreamType,
|
type: audioStreamType,
|
||||||
u: r.urls,
|
u: r.urls,
|
||||||
|
headers: r.headers,
|
||||||
filename: r.audioFilename,
|
filename: r.audioFilename,
|
||||||
isAudioOnly: true,
|
isAudioOnly: true,
|
||||||
audioFormat,
|
audioFormat,
|
||||||
|
|
|
@ -4,9 +4,9 @@ import { extract } from "../url.js";
|
||||||
import Cookie from "../cookie/cookie.js";
|
import Cookie from "../cookie/cookie.js";
|
||||||
|
|
||||||
const shortDomain = "https://vt.tiktok.com/";
|
const shortDomain = "https://vt.tiktok.com/";
|
||||||
export const cookie = new Cookie({});
|
|
||||||
|
|
||||||
export default async function(obj) {
|
export default async function(obj) {
|
||||||
|
const cookie = new Cookie({});
|
||||||
let postId = obj.postId;
|
let postId = obj.postId;
|
||||||
|
|
||||||
if (!postId) {
|
if (!postId) {
|
||||||
|
@ -75,32 +75,46 @@ export default async function(obj) {
|
||||||
if (audio.includes("mime_type=audio_mpeg")) bestAudio = 'mp3';
|
if (audio.includes("mime_type=audio_mpeg")) bestAudio = 'mp3';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (video) return {
|
if (video) {
|
||||||
|
return {
|
||||||
urls: video,
|
urls: video,
|
||||||
filename: videoFilename
|
filename: videoFilename,
|
||||||
|
headers: { cookie }
|
||||||
}
|
}
|
||||||
if (images && obj.isAudioOnly) return {
|
}
|
||||||
|
|
||||||
|
if (images && obj.isAudioOnly) {
|
||||||
|
return {
|
||||||
urls: audio,
|
urls: audio,
|
||||||
audioFilename: audioFilename,
|
audioFilename: audioFilename,
|
||||||
isAudioOnly: true,
|
isAudioOnly: true,
|
||||||
bestAudio
|
bestAudio,
|
||||||
|
headers: { cookie }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (images) {
|
if (images) {
|
||||||
let imageLinks = images
|
let imageLinks = images
|
||||||
.map(i => i.imageURL.urlList.find(p => p.includes(".jpeg?")))
|
.map(i => i.imageURL.urlList.find(p => p.includes(".jpeg?")))
|
||||||
.map(url => ({ url }))
|
.map(url => ({ url }));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
picker: imageLinks,
|
picker: imageLinks,
|
||||||
urls: audio,
|
urls: audio,
|
||||||
audioFilename: audioFilename,
|
audioFilename: audioFilename,
|
||||||
isAudioOnly: true,
|
isAudioOnly: true,
|
||||||
bestAudio
|
bestAudio,
|
||||||
|
headers: { cookie }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (audio) return {
|
|
||||||
|
if (audio) {
|
||||||
|
return {
|
||||||
urls: audio,
|
urls: audio,
|
||||||
audioFilename: audioFilename,
|
audioFilename: audioFilename,
|
||||||
isAudioOnly: true,
|
isAudioOnly: true,
|
||||||
bestAudio
|
bestAudio,
|
||||||
|
headers: { cookie }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ export function createStream(obj) {
|
||||||
filename: obj.filename,
|
filename: obj.filename,
|
||||||
audioFormat: obj.audioFormat,
|
audioFormat: obj.audioFormat,
|
||||||
isAudioOnly: !!obj.isAudioOnly,
|
isAudioOnly: !!obj.isAudioOnly,
|
||||||
|
headers: obj.headers,
|
||||||
copy: !!obj.copy,
|
copy: !!obj.copy,
|
||||||
mute: !!obj.mute,
|
mute: !!obj.mute,
|
||||||
metadata: obj.fileMetadata || false,
|
metadata: obj.fileMetadata || false,
|
||||||
|
@ -82,6 +83,7 @@ export function createInternalStream(url, obj = {}) {
|
||||||
internalStreamCache[streamID] = {
|
internalStreamCache[streamID] = {
|
||||||
url,
|
url,
|
||||||
service: obj.service,
|
service: obj.service,
|
||||||
|
headers: obj.headers,
|
||||||
controller: new AbortController(),
|
controller: new AbortController(),
|
||||||
dispatcher
|
dispatcher
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { genericUserAgent } from "../config.js";
|
import { genericUserAgent } from "../config.js";
|
||||||
import { cookie as tiktokCookie } from "../processing/services/tiktok.js";
|
|
||||||
|
|
||||||
const defaultHeaders = {
|
const defaultHeaders = {
|
||||||
'user-agent': genericUserAgent
|
'user-agent': genericUserAgent
|
||||||
|
@ -14,9 +13,6 @@ const serviceHeaders = {
|
||||||
origin: 'https://www.youtube.com',
|
origin: 'https://www.youtube.com',
|
||||||
referer: 'https://www.youtube.com',
|
referer: 'https://www.youtube.com',
|
||||||
DNT: '?1'
|
DNT: '?1'
|
||||||
},
|
|
||||||
tiktok: {
|
|
||||||
cookie: tiktokCookie
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue