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 # Imports
from flask import Blueprint, render_template, request, abort from flask import Blueprint, render_template, abort
from os import getenv as env from os import getenv as env
import logging, os, re import logging, os, re
@@ -32,7 +32,6 @@ def catch_all(filename):
except Exception as e: except Exception as e:
os_path = os.path.join(bp.template_folder, 'pages', filename)[3:] os_path = os.path.join(bp.template_folder, 'pages', filename)[3:]
print(os_path)
if os.path.isdir(os_path): if os.path.isdir(os_path):
if not filename.endswith('/'): filename += '/' if not filename.endswith('/'): filename += '/'
return render_template('bases/directory.html', directory=filename, pages=ListFiles(os_path)) 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.error_handlers
import src.routes.dynamic_routes import src.routes.dynamic_routes
import src.routes.lastfm
# Load env # Load env
load_dotenv() load_dotenv()
@@ -42,6 +43,7 @@ Session(app)
# Load routes # Load routes
app.register_blueprint(src.routes.error_handlers.bp, url_prefix='/error') 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='/') app.register_blueprint(src.routes.dynamic_routes.bp, url_prefix='/')
# Generic routes # Generic routes
@@ -57,7 +59,6 @@ def favicon():
def robots(): def robots():
return send_file('../static/content/other/robots.txt') return send_file('../static/content/other/robots.txt')
# Route for sitemap.xml # Route for sitemap.xml
@app.route('/sitemap.xml') @app.route('/sitemap.xml')
def sitemap(): def sitemap():

View File

@@ -90,29 +90,21 @@ document.addEventListener('keydown', function(event) {
} }
}); });
// Spotify API // Spotify API (now lastfm)
function getSpotify() { function getSpotify() {
fetch('https://api.alfieking.dev/spotify/nowplaying/xz02oolstlvwxqu1pfcua9exz').then(response => { fetch('/lastfm/info').then(response => {
return response.json(); return response.json();
}).then(data => { }).then(data => {
if (data.item == null) { document.getElementById('spotify').style.backgroundImage = "url(" + data.image + ")";
document.getElementById('spotify').style.backgroundImage = "none"; document.getElementById('spotify-title').innerHTML = data.track;
document.getElementById('spotify-title').innerHTML = "Spotify is not playing anything"; document.getElementById('spotify-artist').innerHTML = data.artist;
document.getElementById('spotify-artist').innerHTML = ":(";
document.getElementById('spotify-link').href = "https://open.spotify.com/";
return;
}
document.getElementById('spotify').style.backgroundImage = "url(" + data.item.album.images[0].url + ")";
document.getElementById('spotify-title').innerHTML = data.item.name;
document.getElementById('spotify-artist').innerHTML = data.item.artists[0].name;
document.getElementById('spotify-link').href = data.item.external_urls.spotify;
}); });
} }
if (document.getElementById('spotify')) { if (document.getElementById('spotify')) {
getSpotify(); getSpotify();
setInterval(getSpotify, 15000); setInterval(getSpotify, 60000);
} }
// load buttons // load buttons

View File

@@ -37,7 +37,7 @@
<img src="https://s1nez.nekoweb.org/img/7dcd20d4.gif" alt=""> <img src="https://s1nez.nekoweb.org/img/7dcd20d4.gif" alt="">
</section> </section>
<div class="flex-row"> <div class="flex-row">
<a href="" id="spotify-link"> <a href="https://www.last.fm/user/acetheking987" id="spotify-link">
<div id="spotify"> <div id="spotify">
<h1 id="spotify-title"></h1> <h1 id="spotify-title"></h1>
<h2 id="spotify-artist"></h2> <h2 id="spotify-artist"></h2>