49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
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)
|