music update
All checks were successful
Build and push container image / build-and-push-image (push) Successful in 4m39s

This commit is contained in:
2026-02-02 01:24:14 +00:00
parent 067f0e189d
commit 9700a5dc7f
5 changed files with 36 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
# Imports
from flask import Blueprint, render_template, request, abort
from flask import Blueprint, render_template, abort
from os import getenv as env
import logging, os, re
@@ -32,7 +32,6 @@ def catch_all(filename):
except Exception as e:
os_path = os.path.join(bp.template_folder, 'pages', filename)[3:]
print(os_path)
if os.path.isdir(os_path):
if not filename.endswith('/'): filename += '/'
return render_template('bases/directory.html', directory=filename, pages=ListFiles(os_path))

26
src/routes/lastfm.py Normal file
View File

@@ -0,0 +1,26 @@
from flask import Blueprint, jsonify
from os import getenv as env
import logging, requests
# Create blueprint
bp = Blueprint(
'lastfm',
__name__,
template_folder=env('TEMPLATE_FOLDER', default='../templates'),
static_folder=env('STATIC_FOLDER', default='../static')
)
# Create logger
log = logging.getLogger(__name__)
# lastfm info
@bp.route('/info')
def lastfm_info():
url = f"http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user={env('LASTFM_USER')}&api_key={env('LASTFM_API_KEY')}&format=json&limit=1"
response = requests.get(url).json()
data = {
'artist': response['recenttracks']['track'][0]['artist']['#text'],
'track': response['recenttracks']['track'][0]['name'],
'image': response['recenttracks']['track'][0]['image'][3]['#text']
}
return jsonify(data)

View File

@@ -8,6 +8,7 @@ import logging
import src.routes.error_handlers
import src.routes.dynamic_routes
import src.routes.lastfm
# Load env
load_dotenv()
@@ -42,6 +43,7 @@ Session(app)
# Load routes
app.register_blueprint(src.routes.error_handlers.bp, url_prefix='/error')
app.register_blueprint(src.routes.lastfm.bp, url_prefix='/lastfm')
app.register_blueprint(src.routes.dynamic_routes.bp, url_prefix='/')
# Generic routes
@@ -57,7 +59,6 @@ def favicon():
def robots():
return send_file('../static/content/other/robots.txt')
# Route for sitemap.xml
@app.route('/sitemap.xml')
def sitemap():