mirror of
https://github.com/Evil0ctal/Douyin_TikTok_Download_API.git
synced 2025-04-21 23:55:23 +08:00
🐱添加了TikTok APP内短链接的支持
This commit is contained in:
parent
9429be924f
commit
4df161a27d
20
TikTok_ZH.py
20
TikTok_ZH.py
@ -97,6 +97,22 @@ def loading(url_lists):
|
|||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
|
def get_tiktok_url(tiktok_link):
|
||||||
|
# 校验TikTok链接
|
||||||
|
if tiktok_link[:12] == "https://www.":
|
||||||
|
return tiktok_link
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
# 从请求头中获取原始链接
|
||||||
|
response = requests.get(url=tiktok_link, headers=headers, allow_redirects=False)
|
||||||
|
new_link = response.headers['Location']
|
||||||
|
response = requests.get(url=new_link, headers=headers, allow_redirects=False)
|
||||||
|
true_link = response.headers['Location'].split("?")[0]
|
||||||
|
return true_link
|
||||||
|
except Exception as e:
|
||||||
|
error_do(e, get_tiktok_url)
|
||||||
|
|
||||||
|
|
||||||
@retry(stop_max_attempt_number=3)
|
@retry(stop_max_attempt_number=3)
|
||||||
def get_video_info(original_url):
|
def get_video_info(original_url):
|
||||||
# 利用官方接口解析链接信息
|
# 利用官方接口解析链接信息
|
||||||
@ -172,6 +188,7 @@ def get_video_info(original_url):
|
|||||||
@retry(stop_max_attempt_number=3)
|
@retry(stop_max_attempt_number=3)
|
||||||
def get_video_info_tiktok(tiktok_url):
|
def get_video_info_tiktok(tiktok_url):
|
||||||
# 对TikTok视频进行解析
|
# 对TikTok视频进行解析
|
||||||
|
tiktok_url = get_tiktok_url(tiktok_url)
|
||||||
try:
|
try:
|
||||||
tiktok_headers = {
|
tiktok_headers = {
|
||||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
|
||||||
@ -189,7 +206,7 @@ def get_video_info_tiktok(tiktok_url):
|
|||||||
video_info = result["ItemModule"][author_id]
|
video_info = result["ItemModule"][author_id]
|
||||||
# print("The author_id is: ", author_id)
|
# print("The author_id is: ", author_id)
|
||||||
# print(video_info)
|
# print(video_info)
|
||||||
# 格式很乱 要忍一下
|
# 从网页中获得的视频JSON 格式很乱 要忍一下
|
||||||
return video_info
|
return video_info
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# 异常捕获
|
# 异常捕获
|
||||||
@ -200,6 +217,7 @@ def get_video_info_tiktok(tiktok_url):
|
|||||||
def tiktok_nwm(tiktok_url):
|
def tiktok_nwm(tiktok_url):
|
||||||
# 使用第三方API获取无水印视频链接(不保证稳定)
|
# 使用第三方API获取无水印视频链接(不保证稳定)
|
||||||
try:
|
try:
|
||||||
|
tiktok_url = get_tiktok_url(tiktok_url)
|
||||||
s = requests.Session()
|
s = requests.Session()
|
||||||
api_url = "https://ttdownloader.com/req/"
|
api_url = "https://ttdownloader.com/req/"
|
||||||
source = s.get("https://ttdownloader.com/")
|
source = s.get("https://ttdownloader.com/")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user