mirror of
https://github.com/Evil0ctal/Douyin_TikTok_Download_API.git
synced 2025-04-21 05:50:12 +08:00
😵💫 Fix Douyin API
This commit is contained in:
parent
786b8fd406
commit
9dc180631f
34
scraper.py
34
scraper.py
@ -23,7 +23,7 @@ import configparser
|
|||||||
|
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
import execjs
|
# import execjs
|
||||||
from tenacity import *
|
from tenacity import *
|
||||||
|
|
||||||
|
|
||||||
@ -196,19 +196,19 @@ class Scraper:
|
|||||||
|
|
||||||
# 生成抖音X-Bogus签名/Generate Douyin X-Bogus signature
|
# 生成抖音X-Bogus签名/Generate Douyin X-Bogus signature
|
||||||
# 暂时不可用,欢迎PR/Temporarily unavailable, welcome PR
|
# 暂时不可用,欢迎PR/Temporarily unavailable, welcome PR
|
||||||
def generate_x_bogus(self, url: str) -> str:
|
# def generate_x_bogus(self, url: str) -> str:
|
||||||
"""
|
# """
|
||||||
生成抖音X-Bogus签名
|
# 生成抖音X-Bogus签名
|
||||||
:param url: 视频链接参数
|
# :param url: 视频链接参数
|
||||||
:return: X-Bogus签名
|
# :return: X-Bogus签名
|
||||||
"""
|
# """
|
||||||
# 调用JavaScript函数
|
# # 调用JavaScript函数
|
||||||
query = urllib.parse.urlparse(url).query
|
# query = urllib.parse.urlparse(url).query
|
||||||
xbogus = execjs.compile(open('./X-Bogus.js').read()).call('sign', query, self.douyin_cookies)
|
# xbogus = execjs.compile(open('./X-Bogus.js').read()).call('sign', query, self.douyin_cookies)
|
||||||
print('生成的X-Bogus签名为: {}'.format(xbogus))
|
# print('生成的X-Bogus签名为: {}'.format(xbogus))
|
||||||
new_url = url + "&X-Bogus=" + xbogus
|
# new_url = url + "&X-Bogus=" + xbogus
|
||||||
print(new_url)
|
# print(new_url)
|
||||||
return new_url
|
# return new_url
|
||||||
|
|
||||||
# 获取抖音视频ID/Get Douyin video ID
|
# 获取抖音视频ID/Get Douyin video ID
|
||||||
async def get_douyin_video_id(self, original_url: str) -> Union[str, None]:
|
async def get_douyin_video_id(self, original_url: str) -> Union[str, None]:
|
||||||
@ -268,6 +268,7 @@ class Scraper:
|
|||||||
|
|
||||||
# 先暂时使用这个API,后续会开源web端的API,我有可能会很忙来不及更新,欢迎大家PR(2023年3月6日)
|
# 先暂时使用这个API,后续会开源web端的API,我有可能会很忙来不及更新,欢迎大家PR(2023年3月6日)
|
||||||
api_url = f"https://api.tikhub.io/douyin_video_data/?video_id={video_id}"
|
api_url = f"https://api.tikhub.io/douyin_video_data/?video_id={video_id}"
|
||||||
|
|
||||||
# 访问API/Access API
|
# 访问API/Access API
|
||||||
print("正在获取视频数据API: {}".format(api_url))
|
print("正在获取视频数据API: {}".format(api_url))
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
@ -284,6 +285,7 @@ class Scraper:
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
# 获取单个抖音直播视频数据/Get single Douyin Live video data
|
# 获取单个抖音直播视频数据/Get single Douyin Live video data
|
||||||
|
# 暂时不可用,待修复。
|
||||||
@retry(stop=stop_after_attempt(4), wait=wait_fixed(7))
|
@retry(stop=stop_after_attempt(4), wait=wait_fixed(7))
|
||||||
async def get_douyin_live_video_data(self, web_rid: str) -> Union[dict, None]:
|
async def get_douyin_live_video_data(self, web_rid: str) -> Union[dict, None]:
|
||||||
print('正在获取抖音视频数据...')
|
print('正在获取抖音视频数据...')
|
||||||
@ -658,8 +660,8 @@ async def async_test(_douyin_url: str = None, _tiktok_url: str = None) -> None:
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
api = Scraper()
|
api = Scraper()
|
||||||
# 运行测试
|
# 运行测试
|
||||||
params = "device_platform=webapp&aid=6383&channel=channel_pc_web&aweme_id=7153585499477757192&pc_client_type=1&version_code=190500&version_name=19.5.0&cookie_enabled=true&screen_width=1344&screen_height=756&browser_language=zh-CN&browser_platform=Win32&browser_name=Firefox&browser_version=110.0&browser_online=true&engine_name=Gecko&engine_version=109.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=&platform=PC&webid=7158288523463362079"
|
# params = "device_platform=webapp&aid=6383&channel=channel_pc_web&aweme_id=7153585499477757192&pc_client_type=1&version_code=190500&version_name=19.5.0&cookie_enabled=true&screen_width=1344&screen_height=756&browser_language=zh-CN&browser_platform=Win32&browser_name=Firefox&browser_version=110.0&browser_online=true&engine_name=Gecko&engine_version=109.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=&platform=PC&webid=7158288523463362079"
|
||||||
api.generate_x_bogus(params)
|
# api.generate_x_bogus(params)
|
||||||
# douyin_url = 'https://v.douyin.com/rLyrQxA/6.66'
|
# douyin_url = 'https://v.douyin.com/rLyrQxA/6.66'
|
||||||
# tiktok_url = 'https://vt.tiktok.com/ZSRwWXtdr/'
|
# tiktok_url = 'https://vt.tiktok.com/ZSRwWXtdr/'
|
||||||
# asyncio.run(async_test(_douyin_url=douyin_url, _tiktok_url=tiktok_url))
|
# asyncio.run(async_test(_douyin_url=douyin_url, _tiktok_url=tiktok_url))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user