Skip to content

Commit

Permalink
Return all bitrate urls for tiktok web api
Browse files Browse the repository at this point in the history
  • Loading branch information
qsniyg committed Jan 27, 2024
1 parent 66772b4 commit 77e8123
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 100 deletions.
65 changes: 51 additions & 14 deletions src/userscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46885,11 +46885,9 @@ var $$IMU_EXPORT$$;

try {
var item = data.itemInfo.itemStruct;
var videourl = item.video.bitrateInfo[0].PlayAddr.UrlList[0] || item.video.downloadAddr || item.video.playAddr;
var caption = item.desc;

var obj:BigImageInfoSObject = {
url: videourl,
let baseobj:BigImageInfoSObject = {
extra: {
caption: caption
},
Expand All @@ -46901,20 +46899,47 @@ var $$IMU_EXPORT$$;
"sec-fetch-site": "same-site"
},
cookie_url: "https://www.tiktok.com/",
video: true,
can_head: false,
//can_multiple_request: false
};

if (data.metaParams && data.metaParams.canonicalHref) {
obj.extra.page = data.metaParams.canonicalHref;
baseobj.extra.page = data.metaParams.canonicalHref;
} else {
obj.extra.page = "https://www.tiktok.com/@" + item.author.uniqueId + "/video/" + item.id;
baseobj.extra.page = "https://www.tiktok.com/@" + item.author.uniqueId + "/video/" + item.id;
}

common_functions["set_tiktok_vid_filename"](obj);
//var videourl = item.video.bitrateInfo[0].PlayAddr.UrlList[0] || item.video.downloadAddr || item.video.playAddr;

return obj;
let urls:BigImageInfoMObject = [];
for (let bri of item.video.bitrateInfo) {
let codec = null;
if (bri.CodecType === "h265_hvc1") {
codec = "hevc";
} else if (bri.CodecType !== "h264") {
console_warn("Unknown codec type for", bri);
}

if (!bri.PlayAddr.UrlList.length || !bri.PlayAddr.UrlList[0]) {
console_warn("Skipping", bri);
continue;
}

urls.push({
url: bri.PlayAddr.UrlList[0],
media_info: {
type: "video",
codec
}
});
}

let finalobj = fillobj_urls(urls, baseobj);
for (let obj of finalobj) {
common_functions["set_tiktok_vid_filename"](obj);
}

return finalobj;
} catch (e) {
console_error(e);
return null;
Expand Down Expand Up @@ -47051,17 +47076,25 @@ var $$IMU_EXPORT$$;

var remove_tiktok_watermark = function(obj, cb) {
var page = null;
if (obj.extra && obj.extra.page) page = obj.extra.page;

common_functions["tiktok_remove_watermark"](api_cache, options, obj.url, page, function(newurl) {
let sobj = obj;
if (is_array(obj))
sobj = obj[0];

if (sobj.extra && sobj.extra.page) page = sobj.extra.page;

common_functions["tiktok_remove_watermark"](api_cache, options, sobj.url, page, function(newurl) {
if (newurl) {
obj = fillobj_urls([newurl], obj)[0];
sobj = fillobj_urls([newurl], sobj)[0];
}

if (!common_functions["set_tiktok_vid_filename"](obj)) {
delete obj.filename;
if (!common_functions["set_tiktok_vid_filename"](sobj)) {
delete sobj.filename;
}

if (is_array(obj))
obj[0] = sobj;

return cb(obj);
});
};
Expand Down Expand Up @@ -47101,7 +47134,11 @@ var $$IMU_EXPORT$$;
}
} else {
remove_tiktok_watermark(obj, function(obj) {
return options.cb([obj, page_nullobj]);
if (!is_array(obj))
obj = [obj];

obj.push(page_nullobj);
return options.cb(obj);
});
}
};
Expand Down
Loading

0 comments on commit 77e8123

Please sign in to comment.