2026-01-17 18:55:25 +03:00
|
|
|
import os
|
2026-01-22 23:55:58 +03:00
|
|
|
import magic
|
2026-01-17 18:55:25 +03:00
|
|
|
from pathlib import Path
|
|
|
|
|
from htmlmin import minify
|
2026-01-22 23:55:58 +03:00
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
from musicbrainzngs import get_image_front
|
|
|
|
|
from flask import (
|
|
|
|
|
Blueprint,
|
|
|
|
|
render_template,
|
|
|
|
|
send_file,
|
|
|
|
|
send_from_directory,
|
|
|
|
|
make_response,
|
|
|
|
|
abort,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
from .modules.api.lb import listens, listening
|
2026-01-17 18:55:25 +03:00
|
|
|
|
|
|
|
|
bp = Blueprint(
|
|
|
|
|
"risdeveau",
|
|
|
|
|
__name__,
|
|
|
|
|
subdomain="risdeveau",
|
|
|
|
|
template_folder="..",
|
|
|
|
|
static_folder=None
|
|
|
|
|
)
|
|
|
|
|
|
2026-01-22 23:55:58 +03:00
|
|
|
def render_tmpl(filename: str, **kwargs) -> str:
|
2026-01-17 18:55:25 +03:00
|
|
|
template_path = os.path.join("risdeveau/templates", filename)
|
|
|
|
|
return minify(
|
2026-01-22 23:55:58 +03:00
|
|
|
render_template(template_path, **kwargs),
|
2026-01-17 18:55:25 +03:00
|
|
|
remove_empty_space=True
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@bp.route("/static/<path:filename>")
|
|
|
|
|
def static(filename: str):
|
|
|
|
|
static_folders = ("static", "../root/static")
|
|
|
|
|
for dir in static_folders:
|
|
|
|
|
if os.path.exists(path := os.path.join("blueprints/risdeveau", dir, filename)):
|
|
|
|
|
return send_file(path)
|
|
|
|
|
return abort(404)
|
|
|
|
|
|
2026-01-22 23:55:58 +03:00
|
|
|
@bp.route("/asset/mb/<mbid>")
|
|
|
|
|
def mb_cover(mbid):
|
|
|
|
|
r = make_response(image := get_image_front(mbid, "250"))
|
|
|
|
|
r.headers['Content-Type'] = magic.from_buffer(image[:2048], mime=True)
|
|
|
|
|
r.headers['Cache-Control'] = 'public, max-age=86400'
|
|
|
|
|
r.headers['Expires'] = (datetime.now() + timedelta(days=1)) \
|
|
|
|
|
.strftime('%a, %d %b %Y %H:%M:%S GMT')
|
|
|
|
|
return r
|
|
|
|
|
|
2026-01-17 18:55:25 +03:00
|
|
|
@bp.route("/")
|
|
|
|
|
def index():
|
2026-01-22 23:55:58 +03:00
|
|
|
return render_tmpl('index.html', lb=listens, lb_now=listening)
|