From 7cb8ed2f54372e8cb184c0bcd2bfbfc8030a970c Mon Sep 17 00:00:00 2001 From: Evil0ctal <20760448+Evil0ctal@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:58:38 -0700 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84bool=E5=80=BC=E4=BB=A5=E5=8F=8A=E5=88=A4?= =?UTF-8?q?=E6=96=ADTikTok=E8=A7=86=E9=A2=91=E6=98=AF=E5=90=A6=E5=AD=98?= =?UTF-8?q?=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scraper.py | 8 ++++++-- web_api.py | 16 ++++++++-------- web_app.py | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/scraper.py b/scraper.py index ed8a8b0..8eae660 100644 --- a/scraper.py +++ b/scraper.py @@ -94,9 +94,9 @@ class Scraper: if not self.config['Scraper']['DouYinCookies'] is None: self.douyin_api_headers['Cookie'] = str(self.config['Scraper']['DouYinCookies']) # 判断是否使用代理 - if self.config['Scraper']['Proxy_switch'] == 'True': + if self.config['Scraper']['Proxy_switch']: # 判断是否区别协议选择代理 - if self.config['Scraper']['Use_different_protocols'] == 'False': + if not self.config['Scraper']['Use_different_protocols']: self.proxies = { 'all': self.config['Scraper']['All'] } @@ -492,6 +492,10 @@ class Scraper: response = response.json() # 获取视频数据/Get video data video_data = response["aweme_list"][0] + # 获取video_id判断原视频是否被删除/Get video_id to determine if the original video has been deleted + aweme_id = video_data["aweme_id"] + if video_id != aweme_id: + raise ValueError("Video not found") return video_data except Exception as e: raise ValueError(f"获取TikTok视频数据出错了: {e}") diff --git a/web_api.py b/web_api.py index 0f79904..f96f407 100644 --- a/web_api.py +++ b/web_api.py @@ -186,7 +186,7 @@ class API_Hybrid_Minimal_Response(BaseModel): # 记录API请求日志 async def api_logs(start_time, input_data, endpoint, error_data: dict = None): - if config["Web_API"]["Allow_Logs"] == "True": + if config["Web_API"]["Allow_Logs"]: time_now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) total_time = float(format(time.time() - start_time, '.4f')) file_name = "API_logs.json" @@ -616,9 +616,9 @@ async def download_file_hybrid(request: Request, url: str, prefix: bool = True, - watermark: bool -> [True/False] 是否添加水印/Whether to add a watermark """ # 是否开启此端点/Whether to enable this endpoint - if config["Web_API"]["Download_Switch"] != "True": + if not config["Web_API"]["Download_Switch"]: return ORJSONResponse({"status": "endpoint closed", - "message": "此端点已关闭请在配置文件中开启/This endpoint is closed, please enable it in the configuration file"}) + "message": "下载视频端点已关闭请在配置文件中开启/Download video endpoint is closed, please enable it in the configuration file"}) # 开始时间 start_time = time.time() headers = { @@ -734,7 +734,7 @@ async def download_douyin_video(aweme_id: str, prefix: bool = True, watermark: b - watermark: bool -> [True/False] 是否添加水印/Whether to add a watermark """ # 是否开启此端点/Whether to enable this endpoint - if config["Web_API"]["Download_Switch"] != "True": + if not config["Web_API"]["Download_Switch"]: return ORJSONResponse({"status": "endpoint closed", "message": "此端点已关闭请在配置文件中开启/This endpoint is closed, please enable it in the configuration file"}) video_url = f"https://www.douyin.com/video/{aweme_id}" @@ -759,7 +759,7 @@ async def download_douyin_video(aweme_id: str, prefix: bool = True, watermark: b - watermark: bool -> [True/False] 是否添加水印/Whether to add a watermark """ # 是否开启此端点/Whether to enable this endpoint - if config["Web_API"]["Download_Switch"] != "True": + if not config["Web_API"]["Download_Switch"]: return ORJSONResponse({"status": "endpoint closed", "message": "此端点已关闭请在配置文件中开启/This endpoint is closed, please enable it in the configuration file"}) video_url = f"https://www.douyin.com/video/{aweme_id}" @@ -784,7 +784,7 @@ async def download_douyin_discover(modal_id: str, prefix: bool = True, watermark - watermark: bool -> [True/False] 是否添加水印/Whether to add a watermark """ # 是否开启此端点/Whether to enable this endpoint - if config["Web_API"]["Download_Switch"] != "True": + if not config["Web_API"]["Download_Switch"]: return ORJSONResponse({"status": "endpoint closed", "message": "此端点已关闭请在配置文件中开启/This endpoint is closed, please enable it in the configuration file"}) video_url = f"https://www.douyin.com/discover?modal_id={modal_id}" @@ -810,7 +810,7 @@ async def download_tiktok_video(user_id: str, aweme_id: str, prefix: bool = True - watermark: bool -> [True/False] 是否添加水印/Whether to add a watermark """ # 是否开启此端点/Whether to enable this endpoint - if config["Web_API"]["Download_Switch"] != "True": + if not config["Web_API"]["Download_Switch"]: return ORJSONResponse({"status": "endpoint closed", "message": "此端点已关闭请在配置文件中开启/This endpoint is closed, please enable it in the configuration file"}) video_url = f"https://www.tiktok.com/{user_id}/video/{aweme_id}" @@ -849,7 +849,7 @@ def cleanup_path(): async def startup_event(): # 创建一个清理下载目录定时器线程并启动 # Create a timer thread to clean up the download directory and start it - download_path_clean_switches = True if config["Web_API"]["Download_Path_Clean_Switch"] == "True" else False + download_path_clean_switches = True if config["Web_API"]["Download_Path_Clean_Switch"] else False if download_path_clean_switches: # 启动清理线程/Start cleaning thread thread_1 = threading.Thread(target=cleanup_path) diff --git a/web_app.py b/web_app.py index 8babbea..9c02a71 100644 --- a/web_app.py +++ b/web_app.py @@ -84,7 +84,7 @@ def error_do(reason: str, value: str) -> None: put_markdown('[{}](https://github.com/Evil0ctal/Douyin_TikTok_Download_API/issues)'.format( t('点击此处在GitHub上进行反馈', 'Click here to give feedback on GitHub'))) put_html("