AI 生成: 一个基于 Python Flask 的影视采集站,自动从公开采集接口抓取影视资源,提供现代风格的分类浏览页面和在线播放功能。
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
from flask import Flask, render_template, request, abort
|
||||
import collector
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
@app.route("/category/<int:cat_id>")
|
||||
def index(cat_id=None):
|
||||
keyword = request.args.get("wd", "").strip()
|
||||
page = int(request.args.get("page", 1))
|
||||
|
||||
categories = collector.get_categories_cached()
|
||||
try:
|
||||
movies = collector.fetch_list(category_id=cat_id, page=page, keyword=keyword or None)
|
||||
except Exception as e:
|
||||
print(f"[app] 采集异常: {e}")
|
||||
movies = []
|
||||
|
||||
return render_template(
|
||||
"index.html",
|
||||
categories=categories,
|
||||
movies=movies,
|
||||
current_cat=cat_id,
|
||||
keyword=keyword,
|
||||
page=page,
|
||||
)
|
||||
|
||||
|
||||
@app.route("/detail/<int:vod_id>")
|
||||
def detail(vod_id):
|
||||
try:
|
||||
movie = collector.fetch_detail(vod_id)
|
||||
except Exception as e:
|
||||
print(f"[app] 详情采集异常: {e}")
|
||||
movie = None
|
||||
if not movie:
|
||||
abort(404)
|
||||
return render_template("detail.html", movie=movie, categories=collector.get_categories_cached())
|
||||
|
||||
|
||||
@app.errorhandler(404)
|
||||
def not_found(e):
|
||||
return render_template("404.html") if False else ("页面不存在", 404)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||
Reference in New Issue
Block a user