From 3eb50cf2705919a3fd5525853d0b4f8378d04309 Mon Sep 17 00:00:00 2001 From: Franklin-F Date: Tue, 15 Jul 2025 21:32:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=85=B3=E9=94=AE=E8=AF=8D=E6=90=9C=E7=B4=A2=E5=B9=B6=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=9B=B8=E5=85=B3=E8=A7=86=E9=A2=91=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flask_test.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 flask_test.py diff --git a/flask_test.py b/flask_test.py new file mode 100644 index 0000000..bd9d907 --- /dev/null +++ b/flask_test.py @@ -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)