feat: 添加视频获取接口,支持关键词搜索并返回相关视频信息
This commit is contained in:
parent
0e7804451b
commit
3eb50cf270
47
flask_test.py
Normal file
47
flask_test.py
Normal file
@ -0,0 +1,47 @@
|
||||
import requests
|
||||
from flask import Flask, request, jsonify
|
||||
from DB import DBVidcon
|
||||
|
||||
app = Flask(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
endpoint = "https://api.dailymotion.com/videos"
|
||||
DEFAULT_PAGE = 1
|
||||
FIXED_LIMIT = 100 # ← 现在固定 100
|
||||
db = DBVidcon()
|
||||
|
||||
@app.route("/get", methods=["GET"])
|
||||
def get_videos():
|
||||
keyword = request.args.get("keyword", "").strip()
|
||||
if not keyword:
|
||||
return jsonify({"status": "error", "msg": "keyword 参数不能为空"}), 400
|
||||
|
||||
i = request.args.get("page", DEFAULT_PAGE, type=int)
|
||||
rn = request.args.get("rn", "US")
|
||||
rn = rn.upper()
|
||||
proxy_string = db.get_proxy(rn)
|
||||
proxies = {"http": proxy_string, "https": proxy_string} if proxy_string else None
|
||||
|
||||
params = {
|
||||
"search": keyword,
|
||||
"fields": "id,title,created_time,thumbnail_240_url,duration,"
|
||||
"owner.id,owner.screenname,likes_total,views_total",
|
||||
"limit": FIXED_LIMIT, # ← 强制 100
|
||||
"page": i,
|
||||
"sort": "relevance"
|
||||
}
|
||||
|
||||
try:
|
||||
logger.info("DM 请求 params=%s proxies=%s", params, proxy_string)
|
||||
resp = requests.get(endpoint, params=params, proxies=proxies, timeout=10)
|
||||
resp.raise_for_status()
|
||||
jd = resp.json()
|
||||
return jsonify(jd), 200
|
||||
except requests.exceptions.RequestException as e:
|
||||
logger.error("DM 请求失败: %s", e)
|
||||
return jsonify({"status": "error", "msg": str(e)}), 502
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=8000, debug=False)
|
Loading…
x
Reference in New Issue
Block a user