mirror of
https://github.com/Evil0ctal/Douyin_TikTok_Download_API.git
synced 2025-04-20 17:55:05 +08:00
Use AIOHTTP instead of HTTPX
This commit is contained in:
parent
474cf9e2a9
commit
d4b69a9e7f
31
web_api.py
31
web_api.py
@ -12,7 +12,8 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
import httpx
|
|
||||||
|
import aiohttp
|
||||||
import uvicorn
|
import uvicorn
|
||||||
import zipfile
|
import zipfile
|
||||||
import threading
|
import threading
|
||||||
@ -39,9 +40,9 @@ domain = config["Web_API"]["Domain"]
|
|||||||
Rate_Limit = config["Web_API"]["Rate_Limit"]
|
Rate_Limit = config["Web_API"]["Rate_Limit"]
|
||||||
|
|
||||||
# 创建FastAPI实例
|
# 创建FastAPI实例
|
||||||
title = "Douyin TikTok Download API(api.douyin.wtf)"
|
title = "Douyin TikTok Download/Scraper API-V1"
|
||||||
version = '3.1.0'
|
version = '3.1.0'
|
||||||
update_time = "2022/11/09"
|
update_time = "2022/11/13"
|
||||||
description = """
|
description = """
|
||||||
#### Description/说明
|
#### Description/说明
|
||||||
<details>
|
<details>
|
||||||
@ -516,16 +517,16 @@ async def download_file_hybrid(request: Request, url: str, prefix: bool = True,
|
|||||||
return FileResponse(path=file_path, media_type='video/mp4', filename=file_name)
|
return FileResponse(path=file_path, media_type='video/mp4', filename=file_name)
|
||||||
else:
|
else:
|
||||||
if platform == 'douyin':
|
if platform == 'douyin':
|
||||||
async with httpx.AsyncClient() as client:
|
async with aiohttp.ClientSession() as session:
|
||||||
r = await client.get(url=url, headers=headers, follow_redirects=False)
|
async with session.get(url=url, headers=headers, allow_redirects=False) as response:
|
||||||
r = r.headers
|
r = response.headers
|
||||||
cdn_url = r.get('location')
|
cdn_url = r.get('location')
|
||||||
r = await client.get(cdn_url)
|
async with session.get(url=cdn_url) as res:
|
||||||
r = r.content
|
r = await res.content.read()
|
||||||
elif platform == 'tiktok':
|
elif platform == 'tiktok':
|
||||||
async with httpx.AsyncClient() as client:
|
async with aiohttp.ClientSession() as session:
|
||||||
r = await client.get(url=url, headers=headers)
|
async with session.get(url=url, headers=headers) as res:
|
||||||
r = r.content
|
r = await res.content.read()
|
||||||
with open(file_path, 'wb') as f:
|
with open(file_path, 'wb') as f:
|
||||||
f.write(r)
|
f.write(r)
|
||||||
return FileResponse(path=file_path, media_type='video/mp4', filename=file_name)
|
return FileResponse(path=file_path, media_type='video/mp4', filename=file_name)
|
||||||
@ -543,11 +544,11 @@ async def download_file_hybrid(request: Request, url: str, prefix: bool = True,
|
|||||||
return FileResponse(path=zip_file_path, media_type='zip', filename=zip_file_name)
|
return FileResponse(path=zip_file_path, media_type='zip', filename=zip_file_name)
|
||||||
file_path_list = []
|
file_path_list = []
|
||||||
for i in url:
|
for i in url:
|
||||||
async with httpx.AsyncClient() as client:
|
async with aiohttp.ClientSession() as session:
|
||||||
r = await client.get(url=i, headers=headers)
|
async with session.get(url=i, headers=headers) as res:
|
||||||
content_type = r.headers.get('content-type')
|
content_type = res.headers.get('content-type')
|
||||||
file_format = content_type.split('/')[1]
|
file_format = content_type.split('/')[1]
|
||||||
r = r.content
|
r = await res.content.read()
|
||||||
index = int(url.index(i))
|
index = int(url.index(i))
|
||||||
file_name = file_name_prefix + platform + '_' + aweme_id + '_' + str(
|
file_name = file_name_prefix + platform + '_' + aweme_id + '_' + str(
|
||||||
index + 1) + '.' + file_format if not watermark else \
|
index + 1) + '.' + file_format if not watermark else \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user