From d67aed6f2b54f70f6d31efcd82b498e6791267fa Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 15 Feb 2025 10:00:10 +0000 Subject: [PATCH 1/5] docs: Added README."en".md translation via https://github.com/dephraiim/translate-readme --- README.en.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.en.md b/README.en.md index 6035c3d..bd50047 100644 --- a/README.en.md +++ b/README.en.md @@ -115,7 +115,7 @@ Some of the source code of TikHub will be open sourced on Github and will sponso > **_/app/api_** -- Obtain the request parameters and use`Crawlers`After processing data, the related classes return in JSON form, download videos, and implement fast calls with iOS shortcuts, and support asynchronous. +- Obtain the request parameters and use`Crawlers`After processing data, the related classes return in JSON form, download videos, and implement quick calls with iOS shortcuts, and support asynchronous. > **_/app/web_** @@ -149,7 +149,7 @@ Some of the source code of TikHub will be open sourced on Github and will sponso - Batch analysis on the web side (supports Douyin/TikTok hybrid analysis) - Download videos or albums online. - Production[pip package](https://pypi.org/project/douyin-tiktok-scraper/)Easy and quick import of your project -- [iOS shortcuts to quickly call API](https://apps.apple.com/cn/app/%E5%BF%AB%E6%8D%B7%E6%8C%87%E4%BB%A4/id915249334)Implement watermark-free video/picture collection in-app download +- [iOS shortcuts to quickly call API](https://apps.apple.com/cn/app/%E5%BF%AB%E6%8D%B7%E6%8C%87%E4%BB%A4/id915249334)Implement in-app download of watermark videos/pictures - Complete API documentation ([Demo/Demo](https://api.douyin.wtf/docs)) - Rich API interfaces: - TikTok web version API @@ -185,7 +185,7 @@ Some of the source code of TikHub will be open sourced on Github and will sponso - [x] Get the user's homepage fan data - [x] Get user's homepage follow data - [x] Obtain data on the collection of works by users on the homepage - - [x] Get user home page search data + - [x] Get search data for users' homepage - [x] Get user homepage playlist data - [x] Get individual video comment data - [x] Get comments and response data for specified videos From 8ae46f7ad70edcab536bd6814cff20e262e44525 Mon Sep 17 00:00:00 2001 From: hadwinfu Date: Sat, 1 Mar 2025 17:10:18 +0800 Subject: [PATCH 2/5] =?UTF-8?q?Fix:=20=E4=BF=AE=E6=94=B9=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=96=B9=E6=B3=95=E4=B8=BA=E6=B5=81=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/endpoints/download.py | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/app/api/endpoints/download.py b/app/api/endpoints/download.py index 53f7249..a07ee9a 100644 --- a/app/api/endpoints/download.py +++ b/app/api/endpoints/download.py @@ -4,7 +4,7 @@ import zipfile import aiofiles import httpx import yaml -from fastapi import APIRouter, Request, Query # 导入FastAPI组件 +from fastapi import APIRouter, Request, Query, HTTPException # 导入FastAPI组件 from starlette.responses import FileResponse from app.api.models.APIResponseModel import ErrorResponseModel # 导入响应模型 @@ -18,7 +18,6 @@ config_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.pa with open(config_path, 'r', encoding='utf-8') as file: config = yaml.safe_load(file) - async def fetch_data(url: str, headers: dict = None): headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' @@ -28,6 +27,23 @@ async def fetch_data(url: str, headers: dict = None): response.raise_for_status() # 确保响应是成功的 return response +# 下载视频专用 +async def fetch_data_stream(url: str, headers: dict = None, file_path: str = None): + headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' + } if headers is None else headers.get('headers') + + async with httpx.AsyncClient() as client: + # 启用流式请求 + async with client.stream("GET", url, headers=headers) as response: + response.raise_for_status() + + # 流式保存文件 + async with aiofiles.open(file_path, 'wb') as out_file: + async for chunk in response.aiter_bytes(): + await out_file.write(chunk) + + return True @router.get("/download", summary="在线下载抖音|TikTok视频/图片/Online download Douyin|TikTok video/image") async def download_file_hybrid(request: Request, @@ -104,11 +120,18 @@ async def download_file_hybrid(request: Request, # 获取视频文件 __headers = await HybridCrawler.TikTokWebCrawler.get_tiktok_headers() if platform == 'tiktok' else await HybridCrawler.DouyinWebCrawler.get_douyin_headers() - response = await fetch_data(url, headers=__headers) + # response = await fetch_data(url, headers=__headers) - # 保存文件 - async with aiofiles.open(file_path, 'wb') as out_file: - await out_file.write(response.content) + is_successful = await fetch_data_stream(url, headers=__headers, file_path=file_path) + if not is_successful: + raise HTTPException( + status_code=400, + detail="An error occurred while fetching data" + ) + + # # 保存文件 + # async with aiofiles.open(file_path, 'wb') as out_file: + # await out_file.write(response.content) # 返回文件内容 return FileResponse(path=file_path, filename=file_name, media_type="video/mp4") From 16ed4eba5ef76ed225ae871348b05e0844a75352 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 1 Mar 2025 21:59:12 +0000 Subject: [PATCH 3/5] docs: Added README."en".md translation via https://github.com/dephraiim/translate-readme --- README.en.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.en.md b/README.en.md index bd50047..989130b 100644 --- a/README.en.md +++ b/README.en.md @@ -50,8 +50,8 @@ _Download videos that are prohibited from being downloaded, perform data analysi ## 🔊 V4 version notes -- If you are interested in writing this project, please add WeChat.`Evil0ctal`Note: Github project reconstruction, everyone can communicate and learn from each other in the group, and do not allow advertisements or illegal things to be made purely friends and technical communication. -- This project uses`X-Bogus`Algorithm and`A_Bogus`The algorithm requests the web APIs of TikTok and TikTok. +- If you are interested in writing this project, please add WeChat`Evil0ctal`Note: Github project reconstruction, everyone can communicate and learn from each other in the group, and do not allow advertisements or illegal things to be made purely friends and technical communication. +- This project uses`X-Bogus`Algorithm and`A_Bogus`The algorithm requests TikTok and TikTok's Web API. - Due to Douyin's risk control, please go to**Get the Douyin website cookies in the browser and replace them in config.yaml.** - Please read the document below before asking for an issue, and most solutions to the problem will be included in the document. - This project is completely free, but please follow it when using it:[Apache-2.0 license](https://github.com/Evil0ctal/Douyin_TikTok_Download_API?tab=Apache-2.0-1-ov-file#readme) @@ -64,11 +64,11 @@ _Download videos that are prohibited from being downloaded, perform data analysi > 📦 Out of the box -Simplify the usage process and quickly carry out development work using the encapsulated SDK. All API interfaces are designed according to the RESTful architecture and are described and documented using the OpenAPI specification, with example parameters to ensure that calls are easier. +Simplify the usage process and quickly carry out development work using the encapsulated SDK. All API interfaces are designed according to the RESTful architecture and are described and documented using the OpenAPI specification, accompanied by example parameters to ensure that calls are easier. > 💰 Cost Advantage -There is no preset package limit, no monthly usage threshold, all consumption is billed instantly based on the actual usage, and the user's daily request volume is charged step by step. At the same time, you can check in in the user's background by checking in every day. , and these free amounts will not expire. +There is no preset package limit, no monthly usage threshold, all consumption is billed instantly based on the actual usage, and is billed step by step based on the user's daily request volume. At the same time, you can check in in the user's background through daily check-in, and these free amounts will not expire. > ⚡️ Quick support @@ -101,7 +101,7 @@ Some of the source code of TikHub will be open sourced on Github and will sponso - [Johnserf-Seed/Tiktokdownload](https://github.com/Johnserf-Seed/TikTokDownload) - [HFrost0/bilix](https://github.com/HFrost0/bilix) -- [Tairraos/TikDown - \[Updated required\]](https://github.com/Tairraos/TikDown/) +- [Tairraos/TikDown - \[Updated to be\]](https://github.com/Tairraos/TikDown/) ## ⚗️Technology Stack @@ -115,7 +115,7 @@ Some of the source code of TikHub will be open sourced on Github and will sponso > **_/app/api_** -- Obtain the request parameters and use`Crawlers`After processing data, the related classes return in JSON form, download videos, and implement quick calls with iOS shortcuts, and support asynchronous. +- Obtain the request parameters and use`Crawlers`After processing data, the related classes return in JSON form, download videos, and implement fast calls with iOS shortcuts, and support asynchronous. > **_/app/web_** @@ -149,7 +149,7 @@ Some of the source code of TikHub will be open sourced on Github and will sponso - Batch analysis on the web side (supports Douyin/TikTok hybrid analysis) - Download videos or albums online. - Production[pip package](https://pypi.org/project/douyin-tiktok-scraper/)Easy and quick import of your project -- [iOS shortcuts to quickly call API](https://apps.apple.com/cn/app/%E5%BF%AB%E6%8D%B7%E6%8C%87%E4%BB%A4/id915249334)Implement in-app download of watermark videos/pictures +- [iOS shortcuts to quickly call API](https://apps.apple.com/cn/app/%E5%BF%AB%E6%8D%B7%E6%8C%87%E4%BB%A4/id915249334)Implement watermark-free videos/pictures in-app download - Complete API documentation ([Demo/Demo](https://api.douyin.wtf/docs)) - Rich API interfaces: - TikTok web version API @@ -157,7 +157,7 @@ Some of the source code of TikHub will be open sourced on Github and will sponso - [x] Video data analysis - [x] Obtain user's homepage work data - [x] Obtain data on the user's homepage liked works - - [x] Obtain data on the user's homepage collection of works + - [x] 获取用户主页收藏作品数据 - [x] Get user homepage information - [x] Obtain user compiled works data - [x] Obtain user live streaming data @@ -314,7 +314,7 @@ Online: - - I turned off the online download function of the demonstration site. Someone downloaded a huge video and it crashed directly on my server. You can right-click to save the video on the web parsing result page... - The cookies on the demo site are my own and are not guaranteed to be valid for a long time. They only serve as a demonstration. If you deploy it yourself, please get the cookies yourself. -- HTTP 403 error occurs if you need to access the video link returned by TikTok Web API. Please use the API in this project`/api/download`The interface downloads TikTok videos. This interface has been manually closed in the demonstration site, and you need to deploy this project yourself. +- HTTP 403 error will occur if you need to access the video link returned by TikTok Web API. Please use the API in this project`/api/download`The interface downloads TikTok videos. This interface has been manually closed in the demonstration site, and you need to deploy this project yourself. - There is one here**Video tutorial**You can refer to:**__** ## 💻Deployment (Method 1 Linux) From 32755dd86b774e0971a103c8bab95734f16c27e8 Mon Sep 17 00:00:00 2001 From: hadwinfu Date: Sun, 2 Mar 2025 23:18:35 +0800 Subject: [PATCH 4/5] =?UTF-8?q?Fix:=20=E8=87=AA=E5=8A=A8=E6=B8=85=E7=90=86?= =?UTF-8?q?=E6=9C=AA=E5=AE=8C=E6=88=90=E7=9A=84=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/endpoints/download.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/api/endpoints/download.py b/app/api/endpoints/download.py index a07ee9a..740ee43 100644 --- a/app/api/endpoints/download.py +++ b/app/api/endpoints/download.py @@ -28,11 +28,10 @@ async def fetch_data(url: str, headers: dict = None): return response # 下载视频专用 -async def fetch_data_stream(url: str, headers: dict = None, file_path: str = None): +async def fetch_data_stream(url: str, request:Request , headers: dict = None, file_path: str = None): headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' } if headers is None else headers.get('headers') - async with httpx.AsyncClient() as client: # 启用流式请求 async with client.stream("GET", url, headers=headers) as response: @@ -41,8 +40,12 @@ async def fetch_data_stream(url: str, headers: dict = None, file_path: str = Non # 流式保存文件 async with aiofiles.open(file_path, 'wb') as out_file: async for chunk in response.aiter_bytes(): + if await request.is_disconnected(): + print("客户端断开连接,清理未完成的文件") + await out_file.close() + os.remove(file_path) + return False await out_file.write(chunk) - return True @router.get("/download", summary="在线下载抖音|TikTok视频/图片/Online download Douyin|TikTok video/image") @@ -122,10 +125,10 @@ async def download_file_hybrid(request: Request, __headers = await HybridCrawler.TikTokWebCrawler.get_tiktok_headers() if platform == 'tiktok' else await HybridCrawler.DouyinWebCrawler.get_douyin_headers() # response = await fetch_data(url, headers=__headers) - is_successful = await fetch_data_stream(url, headers=__headers, file_path=file_path) - if not is_successful: + success = await fetch_data_stream(url, request, headers=__headers, file_path=file_path) + if not success: raise HTTPException( - status_code=400, + status_code=500, detail="An error occurred while fetching data" ) From c1cd8b8863613a51548d3e70ab518f3ce7240158 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 4 Mar 2025 06:01:57 +0000 Subject: [PATCH 5/5] docs: Added README."en".md translation via https://github.com/dephraiim/translate-readme --- README.en.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.en.md b/README.en.md index 989130b..fe52856 100644 --- a/README.en.md +++ b/README.en.md @@ -157,7 +157,7 @@ Some of the source code of TikHub will be open sourced on Github and will sponso - [x] Video data analysis - [x] Obtain user's homepage work data - [x] Obtain data on the user's homepage liked works - - [x] 获取用户主页收藏作品数据 + - [x] Obtain data on the user's homepage collection of works - [x] Get user homepage information - [x] Obtain user compiled works data - [x] Obtain user live streaming data