From af1ed888cc3cede0858103ea19e2c4417fc35a6c Mon Sep 17 00:00:00 2001 From: Halhadus Date: Sat, 8 Feb 2025 01:51:06 +0300 Subject: [PATCH] Readded forgoten Lyrics section --- websitepart.py | 85 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 28 deletions(-) diff --git a/websitepart.py b/websitepart.py index a6ea8f4..2873486 100644 --- a/websitepart.py +++ b/websitepart.py @@ -6,29 +6,51 @@ import os import re app = flask.Flask(__name__) +app.config['LYRICS_DIR'] = 'lyrics' + code = "" history = [] @app.route('/musicstatus.html', methods=['GET', 'POST']) def musicstatus(): global code, history + + # POST Request Handling if flask.request.method == 'POST': data = flask.request.get_json() - if code != data['verificationcode']: + + # Validate verification code + if code != data.get('verificationcode'): return "Verification failed", 403 + + # Create new entry entry = ( data['music'], data['time'], data['resetstatus'], data['videoid'] ) - if data['resetstatus'].lower() == "true": + + # Handle history reset + if data.get('resetstatus', '').lower() == "true": history.clear() + history.append(entry) return "Entry added successfully" + # GET Request Handling elif flask.request.method == 'GET': current_playing = history[-1] if history else None + lyrics_content = [] + + # Load lyrics if available + if current_playing: + lrc_path = os.path.join(app.config['LYRICS_DIR'], f"{current_playing[0]}.lrc") + if os.path.exists(lrc_path): + with open(lrc_path, 'r') as f: + lyrics = [line.split("]")[-1].strip() for line in f if "]" in line] + lyrics_content = [line for line in lyrics if line] + return flask.render_template_string(''' @@ -36,7 +58,7 @@ def musicstatus(): - Halhadus' Music Status + Music Status @@ -67,10 +89,6 @@ def musicstatus(): gap: 1rem; } - .thumbnail-container { - order: 2; - } - .thumbnail { width: 100%; border-radius: 6px; @@ -90,7 +108,6 @@ def musicstatus(): display: inline-block; text-align: center; font-family: 'JetBrains Mono', monospace; - font-size: 0.9rem; } .history-table { @@ -98,7 +115,6 @@ def musicstatus(): border-collapse: collapse; margin-top: 2rem; overflow-x: auto; - display: block; } .history-table th, @@ -108,9 +124,17 @@ def musicstatus(): min-width: 120px; } - .history-table img { - width: 80px; - border-radius: 4px; + .lyrics-container { + background: #333; + border-radius: 8px; + padding: 1rem; + margin-top: 1rem; + text-align: center; + } + + .lyrics-line { + margin: 0.5rem 0; + color: #ccc; } @media (min-width: 768px) { @@ -119,28 +143,22 @@ def musicstatus(): gap: 2rem; padding: 2rem; } - .thumbnail-container { - order: 0; - } .play-button { padding: 0.8rem 1.5rem; - font-size: 1rem; } } - +

🎵 Music Status

← Main Page {% if current_playing %}
-
- {{ current_playing[0] }} cover -
+ {{ current_playing[0] }} cover

{{ current_playing[0] }}

🕒 Last Updated: {{ format_timestamp(current_playing[1]) }}

@@ -156,6 +174,14 @@ def musicstatus(): ▶ YT Music
+ {% if lyrics_content %} +
+

Lyrics

+ {% for line in lyrics_content %} +

{{ line }}

+ {% endfor %} +
+ {% endif %}
{% else %} @@ -179,6 +205,7 @@ def musicstatus(): {{ entry[0] }} thumbnail {{ entry[0] }} @@ -197,7 +224,10 @@ def musicstatus(): - ''', current_playing=current_playing, history=history, format_timestamp=format_timestamp) + ''', current_playing=current_playing, + history=history, + format_timestamp=format_timestamp, + lyrics_content=lyrics_content) def format_timestamp(timestamp): return datetime.datetime.fromtimestamp( @@ -210,21 +240,20 @@ def verifycert(): global code data = flask.request.get_json() with open("key.txt", "r") as f: - if data.get('key') == f.read(): + if data.get('key') == f.read().strip(): code = ''.join(random.choices(string.ascii_uppercase + string.digits, k=64)) return code return "0" @app.route('/') def catch_all(path): - if path == None: - return flask.redirect('https://halhadus.rocks') - if not path == 'musicstatus.html' or not path == 'verifykey': - return flask.redirect(f'https://halhadus.rocks/{path}') + return flask.redirect(f'https://halhadus.rocks/{path}') @app.route('/') def index(): return flask.redirect('https://halhadus.rocks') if __name__ == '__main__': + if not os.path.exists(app.config['LYRICS_DIR']): + os.makedirs(app.config['LYRICS_DIR']) app.run(host='0.0.0.0', port=int(os.environ.get('PORT')))