89 lines
3.3 KiB
Python
89 lines
3.3 KiB
Python
from fastapi import FastAPI, Query
|
|
import uvicorn
|
|
import requests
|
|
from utils.response import success_response, error_400_response, error_503_response
|
|
|
|
app = FastAPI(title="douyin文档", swagger_ui_parameters={
|
|
"defaultModelsExpandDepth": -1
|
|
})
|
|
|
|
DEFAULT_PC_VIDEO_URL = 'https://v.douyin.com/-NvlqBdIJo4/'
|
|
DEFAULT_mobile_VIDEO_URL = 'https://v.douyin.com/BCfMrTFPYGQ/'
|
|
|
|
|
|
@app.get('/douyin_content', tags=["抖音"], summary="手机和pc获取文案")
|
|
def douyin_content(video_url: str = Query(DEFAULT_mobile_VIDEO_URL, min_length=10)):
|
|
print(video_url)
|
|
if not video_url:
|
|
return {"code": 400, "message": "An error occurred.", "data": "请指定video_url"}
|
|
|
|
# 获取get请求参数
|
|
url = "http://douyin_tiktok_download_api:80/api/hybrid/video_data"
|
|
|
|
querystring = {"url": video_url, "minimal": "false"}
|
|
response = requests.request("GET", url, params=querystring)
|
|
print(response.text)
|
|
try:
|
|
if response.json()['code'] == 200:
|
|
return success_response({"content": response.json()['data']['seo_info']['ocr_content'],
|
|
})
|
|
|
|
except Exception as e:
|
|
print(e)
|
|
return error_400_response({"data": "解析字段失败."})
|
|
|
|
return error_503_response({"data": "抖音风控稍后请求."})
|
|
|
|
|
|
@app.get('/douyin_pc', tags=["抖音"], summary="返回pc文案和视频")
|
|
def douyin_pc(video_url: str = Query(DEFAULT_PC_VIDEO_URL, min_length=10)):
|
|
print(video_url)
|
|
if not video_url:
|
|
return {"code": 400, "message": "An error occurred.", "data": "请指定video_url"}
|
|
|
|
# 获取get请求参数
|
|
url = "http://douyin_tiktok_download_api:80/api/hybrid/video_data"
|
|
|
|
querystring = {"url": video_url, "minimal": "false"}
|
|
response = requests.request("GET", url, params=querystring)
|
|
print(response.text)
|
|
try:
|
|
if response.json()['code'] == 200:
|
|
return success_response({"content": response.json()['data']['seo_info']['ocr_content'],
|
|
"pc_url": response.json()['data']['video']['bit_rate'][0]['play_addr']['url_list']
|
|
})
|
|
|
|
except Exception as e:
|
|
print(e)
|
|
return error_400_response({"data": "解析字段失败."})
|
|
|
|
return error_503_response({"data": "抖音风控稍后请求."})
|
|
|
|
|
|
@app.get('/douyin_phone', tags=["抖音"], summary="返回手机视屏地址")
|
|
def douyin_phone(video_url: str = Query(DEFAULT_mobile_VIDEO_URL, min_length=10)):
|
|
print(video_url)
|
|
if not video_url:
|
|
return {"code": 400, "message": "An error occurred.", "data": "请指定video_url"}
|
|
|
|
# 获取get请求参数
|
|
url = "http://douyin_tiktok_download_api:80/api/hybrid/video_data"
|
|
|
|
querystring = {"url": video_url, "minimal": "true"}
|
|
response = requests.request("GET", url, params=querystring)
|
|
print(response.json()['data']['author']['avatar_thumb'])
|
|
try:
|
|
if response.json()['code'] == 200:
|
|
return success_response({"phone_url": response.json()['data']['author']['avatar_thumb']['url_list']
|
|
})
|
|
|
|
except Exception as e:
|
|
print(e)
|
|
return error_400_response({"data": "解析字段失败."})
|
|
|
|
return error_503_response({"data": "抖音风控稍后请求."})
|
|
|
|
|
|
if __name__ == '__main__':
|
|
uvicorn.run(app='main:app', host='0.0.0.0', port=1314, reload=True)
|