mirror of
https://github.com/Evil0ctal/Douyin_TikTok_Download_API.git
synced 2025-04-20 09:00:00 +08:00
修复配置文件的bool值以及判断TikTok视频是否存在
This commit is contained in:
parent
cacf7b4c11
commit
7cb8ed2f54
@ -94,9 +94,9 @@ class Scraper:
|
|||||||
if not self.config['Scraper']['DouYinCookies'] is None:
|
if not self.config['Scraper']['DouYinCookies'] is None:
|
||||||
self.douyin_api_headers['Cookie'] = str(self.config['Scraper']['DouYinCookies'])
|
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 = {
|
self.proxies = {
|
||||||
'all': self.config['Scraper']['All']
|
'all': self.config['Scraper']['All']
|
||||||
}
|
}
|
||||||
@ -492,6 +492,10 @@ class Scraper:
|
|||||||
response = response.json()
|
response = response.json()
|
||||||
# 获取视频数据/Get video data
|
# 获取视频数据/Get video data
|
||||||
video_data = response["aweme_list"][0]
|
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
|
return video_data
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError(f"获取TikTok视频数据出错了: {e}")
|
raise ValueError(f"获取TikTok视频数据出错了: {e}")
|
||||||
|
16
web_api.py
16
web_api.py
@ -186,7 +186,7 @@ class API_Hybrid_Minimal_Response(BaseModel):
|
|||||||
|
|
||||||
# 记录API请求日志
|
# 记录API请求日志
|
||||||
async def api_logs(start_time, input_data, endpoint, error_data: dict = None):
|
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())
|
time_now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
||||||
total_time = float(format(time.time() - start_time, '.4f'))
|
total_time = float(format(time.time() - start_time, '.4f'))
|
||||||
file_name = "API_logs.json"
|
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
|
- watermark: bool -> [True/False] 是否添加水印/Whether to add a watermark
|
||||||
"""
|
"""
|
||||||
# 是否开启此端点/Whether to enable this endpoint
|
# 是否开启此端点/Whether to enable this endpoint
|
||||||
if config["Web_API"]["Download_Switch"] != "True":
|
if not config["Web_API"]["Download_Switch"]:
|
||||||
return ORJSONResponse({"status": "endpoint closed",
|
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()
|
start_time = time.time()
|
||||||
headers = {
|
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
|
- watermark: bool -> [True/False] 是否添加水印/Whether to add a watermark
|
||||||
"""
|
"""
|
||||||
# 是否开启此端点/Whether to enable this endpoint
|
# 是否开启此端点/Whether to enable this endpoint
|
||||||
if config["Web_API"]["Download_Switch"] != "True":
|
if not config["Web_API"]["Download_Switch"]:
|
||||||
return ORJSONResponse({"status": "endpoint closed",
|
return ORJSONResponse({"status": "endpoint closed",
|
||||||
"message": "此端点已关闭请在配置文件中开启/This endpoint is closed, please enable it in the configuration file"})
|
"message": "此端点已关闭请在配置文件中开启/This endpoint is closed, please enable it in the configuration file"})
|
||||||
video_url = f"https://www.douyin.com/video/{aweme_id}"
|
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
|
- watermark: bool -> [True/False] 是否添加水印/Whether to add a watermark
|
||||||
"""
|
"""
|
||||||
# 是否开启此端点/Whether to enable this endpoint
|
# 是否开启此端点/Whether to enable this endpoint
|
||||||
if config["Web_API"]["Download_Switch"] != "True":
|
if not config["Web_API"]["Download_Switch"]:
|
||||||
return ORJSONResponse({"status": "endpoint closed",
|
return ORJSONResponse({"status": "endpoint closed",
|
||||||
"message": "此端点已关闭请在配置文件中开启/This endpoint is closed, please enable it in the configuration file"})
|
"message": "此端点已关闭请在配置文件中开启/This endpoint is closed, please enable it in the configuration file"})
|
||||||
video_url = f"https://www.douyin.com/video/{aweme_id}"
|
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
|
- watermark: bool -> [True/False] 是否添加水印/Whether to add a watermark
|
||||||
"""
|
"""
|
||||||
# 是否开启此端点/Whether to enable this endpoint
|
# 是否开启此端点/Whether to enable this endpoint
|
||||||
if config["Web_API"]["Download_Switch"] != "True":
|
if not config["Web_API"]["Download_Switch"]:
|
||||||
return ORJSONResponse({"status": "endpoint closed",
|
return ORJSONResponse({"status": "endpoint closed",
|
||||||
"message": "此端点已关闭请在配置文件中开启/This endpoint is closed, please enable it in the configuration file"})
|
"message": "此端点已关闭请在配置文件中开启/This endpoint is closed, please enable it in the configuration file"})
|
||||||
video_url = f"https://www.douyin.com/discover?modal_id={modal_id}"
|
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
|
- watermark: bool -> [True/False] 是否添加水印/Whether to add a watermark
|
||||||
"""
|
"""
|
||||||
# 是否开启此端点/Whether to enable this endpoint
|
# 是否开启此端点/Whether to enable this endpoint
|
||||||
if config["Web_API"]["Download_Switch"] != "True":
|
if not config["Web_API"]["Download_Switch"]:
|
||||||
return ORJSONResponse({"status": "endpoint closed",
|
return ORJSONResponse({"status": "endpoint closed",
|
||||||
"message": "此端点已关闭请在配置文件中开启/This endpoint is closed, please enable it in the configuration file"})
|
"message": "此端点已关闭请在配置文件中开启/This endpoint is closed, please enable it in the configuration file"})
|
||||||
video_url = f"https://www.tiktok.com/{user_id}/video/{aweme_id}"
|
video_url = f"https://www.tiktok.com/{user_id}/video/{aweme_id}"
|
||||||
@ -849,7 +849,7 @@ def cleanup_path():
|
|||||||
async def startup_event():
|
async def startup_event():
|
||||||
# 创建一个清理下载目录定时器线程并启动
|
# 创建一个清理下载目录定时器线程并启动
|
||||||
# Create a timer thread to clean up the download directory and start it
|
# 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:
|
if download_path_clean_switches:
|
||||||
# 启动清理线程/Start cleaning thread
|
# 启动清理线程/Start cleaning thread
|
||||||
thread_1 = threading.Thread(target=cleanup_path)
|
thread_1 = threading.Thread(target=cleanup_path)
|
||||||
|
@ -84,7 +84,7 @@ def error_do(reason: str, value: str) -> None:
|
|||||||
put_markdown('[{}](https://github.com/Evil0ctal/Douyin_TikTok_Download_API/issues)'.format(
|
put_markdown('[{}](https://github.com/Evil0ctal/Douyin_TikTok_Download_API/issues)'.format(
|
||||||
t('点击此处在GitHub上进行反馈', 'Click here to give feedback on GitHub')))
|
t('点击此处在GitHub上进行反馈', 'Click here to give feedback on GitHub')))
|
||||||
put_html("<hr>")
|
put_html("<hr>")
|
||||||
if config['Web_APP']['Allow_Logs'] == 'True':
|
if config['Web_APP']['Allow_Logs']:
|
||||||
# 如果douyin或tiktok在输入值中,则记录到日志文件/If douyin or tiktok is in the input value, record it to the log file
|
# 如果douyin或tiktok在输入值中,则记录到日志文件/If douyin or tiktok is in the input value, record it to the log file
|
||||||
if 'douyin' in value or 'tiktok' in value:
|
if 'douyin' in value or 'tiktok' in value:
|
||||||
# 将错误记录在logs.txt中
|
# 将错误记录在logs.txt中
|
||||||
|
Loading…
x
Reference in New Issue
Block a user