From 9dc180631f3556613752d3c98567f679bdd71925 Mon Sep 17 00:00:00 2001 From: Evil0ctal <20760448+Evil0ctal@users.noreply.github.com> Date: Mon, 6 Mar 2023 19:51:50 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=98=B5=E2=80=8D=F0=9F=92=AB=20Fix=20Douyi?= =?UTF-8?q?n=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scraper.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/scraper.py b/scraper.py index 0f024f5..dd45a42 100644 --- a/scraper.py +++ b/scraper.py @@ -23,7 +23,7 @@ import configparser from typing import Union -import execjs +# import execjs from tenacity import * @@ -196,19 +196,19 @@ class Scraper: # 生成抖音X-Bogus签名/Generate Douyin X-Bogus signature # 暂时不可用,欢迎PR/Temporarily unavailable, welcome PR - def generate_x_bogus(self, url: str) -> str: - """ - 生成抖音X-Bogus签名 - :param url: 视频链接参数 - :return: X-Bogus签名 - """ - # 调用JavaScript函数 - query = urllib.parse.urlparse(url).query - xbogus = execjs.compile(open('./X-Bogus.js').read()).call('sign', query, self.douyin_cookies) - print('生成的X-Bogus签名为: {}'.format(xbogus)) - new_url = url + "&X-Bogus=" + xbogus - print(new_url) - return new_url + # def generate_x_bogus(self, url: str) -> str: + # """ + # 生成抖音X-Bogus签名 + # :param url: 视频链接参数 + # :return: X-Bogus签名 + # """ + # # 调用JavaScript函数 + # query = urllib.parse.urlparse(url).query + # xbogus = execjs.compile(open('./X-Bogus.js').read()).call('sign', query, self.douyin_cookies) + # print('生成的X-Bogus签名为: {}'.format(xbogus)) + # new_url = url + "&X-Bogus=" + xbogus + # print(new_url) + # return new_url # 获取抖音视频ID/Get Douyin video ID 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_url = f"https://api.tikhub.io/douyin_video_data/?video_id={video_id}" + # 访问API/Access API print("正在获取视频数据API: {}".format(api_url)) async with aiohttp.ClientSession() as session: @@ -284,6 +285,7 @@ class Scraper: raise e # 获取单个抖音直播视频数据/Get single Douyin Live video data + # 暂时不可用,待修复。 @retry(stop=stop_after_attempt(4), wait=wait_fixed(7)) async def get_douyin_live_video_data(self, web_rid: str) -> Union[dict, None]: print('正在获取抖音视频数据...') @@ -658,8 +660,8 @@ async def async_test(_douyin_url: str = None, _tiktok_url: str = None) -> None: if __name__ == '__main__': 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" - api.generate_x_bogus(params) + # 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) # douyin_url = 'https://v.douyin.com/rLyrQxA/6.66' # tiktok_url = 'https://vt.tiktok.com/ZSRwWXtdr/' # asyncio.run(async_test(_douyin_url=douyin_url, _tiktok_url=tiktok_url))