测试新增参数
This commit is contained in:
parent
54347c12a8
commit
5caca00af6
@ -6,7 +6,12 @@ app = Flask(__name__)
|
|||||||
|
|
||||||
endpoint = "https://api.dailymotion.com/videos"
|
endpoint = "https://api.dailymotion.com/videos"
|
||||||
DEFAULT_PAGE = 1
|
DEFAULT_PAGE = 1
|
||||||
FIXED_LIMIT = 100 # ← 现在固定 100
|
FIXED_LIMIT = 100
|
||||||
|
VALID_SORTS = {
|
||||||
|
'recent', 'relevance', 'alpha', 'alphaaz',
|
||||||
|
'alphaza', 'most', 'least', 'changed'
|
||||||
|
}
|
||||||
|
|
||||||
db = DBVidcon()
|
db = DBVidcon()
|
||||||
|
|
||||||
@app.route("/get", methods=["GET"])
|
@app.route("/get", methods=["GET"])
|
||||||
@ -15,9 +20,18 @@ def get_videos():
|
|||||||
if not keyword:
|
if not keyword:
|
||||||
return jsonify({"status": "error", "msg": "keyword 参数不能为空"}), 400
|
return jsonify({"status": "error", "msg": "keyword 参数不能为空"}), 400
|
||||||
|
|
||||||
|
# 页码和国家参数
|
||||||
i = request.args.get("page", DEFAULT_PAGE, type=int)
|
i = request.args.get("page", DEFAULT_PAGE, type=int)
|
||||||
rn = request.args.get("rn", "US")
|
rn = request.args.get("rn", "US").upper()
|
||||||
rn = rn.upper()
|
|
||||||
|
# 排序参数,必须合法
|
||||||
|
sort = request.args.get("sort", "relevance").strip().lower()
|
||||||
|
if sort not in VALID_SORTS:
|
||||||
|
return jsonify({
|
||||||
|
"status": "error",
|
||||||
|
"msg": f"sort 参数非法,可选值: {sorted(VALID_SORTS)}"
|
||||||
|
}), 400
|
||||||
|
|
||||||
proxy_string = db.get_proxy(rn)
|
proxy_string = db.get_proxy(rn)
|
||||||
proxies = {"http": proxy_string, "https": proxy_string} if proxy_string else None
|
proxies = {"http": proxy_string, "https": proxy_string} if proxy_string else None
|
||||||
|
|
||||||
@ -25,9 +39,9 @@ def get_videos():
|
|||||||
"search": keyword,
|
"search": keyword,
|
||||||
"fields": "id,title,created_time,thumbnail_240_url,duration,"
|
"fields": "id,title,created_time,thumbnail_240_url,duration,"
|
||||||
"owner.id,owner.screenname,likes_total,views_total",
|
"owner.id,owner.screenname,likes_total,views_total",
|
||||||
"limit": FIXED_LIMIT, # ← 强制 100
|
"limit": FIXED_LIMIT,
|
||||||
"page": i,
|
"page": i,
|
||||||
"sort": "relevance"
|
"sort": sort
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user