import flask import datetime import random import string import os import re app = flask.Flask(__name__) code = "" history = [] @app.route('/musicstatus.html', methods=['GET', 'POST']) def musicstatus(): global code, history if flask.request.method == 'POST': data = flask.request.get_json() if code != data['verificationcode']: return "Verification failed", 403 entry = ( data['music'], data['time'], data['resetstatus'], data['videoid'] ) if data['resetstatus'].lower() == "true": history.clear() history.append(entry) return "Entry added successfully" elif flask.request.method == 'GET': current_playing = history[-1] if history else None return flask.render_template_string(''' Halhadus' Music Status

🎵 Music Status

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

{{ current_playing[0] }}

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

▶ YouTube ▶ YT Music
{% else %}

No music currently playing

{% endif %}

Play History

{% for entry in history|reverse %} {% endfor %}
Cover Title Time Play
{{ entry[0] }} thumbnail {{ entry[0] }} {{ format_timestamp(entry[1]) }}
''', current_playing=current_playing, history=history, format_timestamp=format_timestamp) def format_timestamp(timestamp): return datetime.datetime.fromtimestamp( int(timestamp), datetime.timezone.utc ).strftime("%Y-%m-%d %H:%M UTC") @app.route('/verifykey', methods=['POST']) def verifycert(): global code data = flask.request.get_json() with open("key.txt", "r") as f: if data.get('key') == f.read(): 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}') @app.route('/') def index(): return flask.redirect('https://halhadus.rocks') if __name__ == '__main__': app.run(host='0.0.0.0', port=int(os.environ.get('PORT')))