Merge remote-tracking branch 'origin/main'

This commit is contained in:
Evil0ctal 2025-03-16 01:03:35 -07:00
commit a1cc2b6056
2 changed files with 40 additions and 14 deletions

View File

@ -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
@ -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 watermark-free videos/pictures in-app download
- 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
@ -314,7 +314,7 @@ Online:<https://api.douyin.wtf/docs>
- <https://github.com/Evil0ctal/Douyin_TikTok_Download_API/blob/30e56e5a7f97f87d60b1045befb1f6db147f8590/crawlers/tiktok/web/config.yaml#L6>
- 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:**_<https://www.bilibili.com/video/BV1vE421j7NR/>_**
## 💻Deployment (Method 1 Linux)

View File

@ -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,26 @@ async def fetch_data(url: str, headers: dict = None):
response.raise_for_status() # 确保响应是成功的
return response
# 下载视频专用
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:
response.raise_for_status()
# 流式保存文件
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")
async def download_file_hybrid(request: Request,
@ -104,11 +123,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)
success = await fetch_data_stream(url, request, headers=__headers, file_path=file_path)
if not success:
raise HTTPException(
status_code=500,
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")