Readded forgoten Lyrics section
This commit is contained in:
parent
e76b53fb58
commit
af1ed888cc
1 changed files with 57 additions and 28 deletions
|
@ -6,29 +6,51 @@ import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
app = flask.Flask(__name__)
|
app = flask.Flask(__name__)
|
||||||
|
app.config['LYRICS_DIR'] = 'lyrics'
|
||||||
|
|
||||||
code = ""
|
code = ""
|
||||||
history = []
|
history = []
|
||||||
|
|
||||||
@app.route('/musicstatus.html', methods=['GET', 'POST'])
|
@app.route('/musicstatus.html', methods=['GET', 'POST'])
|
||||||
def musicstatus():
|
def musicstatus():
|
||||||
global code, history
|
global code, history
|
||||||
|
|
||||||
|
# POST Request Handling
|
||||||
if flask.request.method == 'POST':
|
if flask.request.method == 'POST':
|
||||||
data = flask.request.get_json()
|
data = flask.request.get_json()
|
||||||
if code != data['verificationcode']:
|
|
||||||
|
# Validate verification code
|
||||||
|
if code != data.get('verificationcode'):
|
||||||
return "Verification failed", 403
|
return "Verification failed", 403
|
||||||
|
|
||||||
|
# Create new entry
|
||||||
entry = (
|
entry = (
|
||||||
data['music'],
|
data['music'],
|
||||||
data['time'],
|
data['time'],
|
||||||
data['resetstatus'],
|
data['resetstatus'],
|
||||||
data['videoid']
|
data['videoid']
|
||||||
)
|
)
|
||||||
if data['resetstatus'].lower() == "true":
|
|
||||||
|
# Handle history reset
|
||||||
|
if data.get('resetstatus', '').lower() == "true":
|
||||||
history.clear()
|
history.clear()
|
||||||
|
|
||||||
history.append(entry)
|
history.append(entry)
|
||||||
return "Entry added successfully"
|
return "Entry added successfully"
|
||||||
|
|
||||||
|
# GET Request Handling
|
||||||
elif flask.request.method == 'GET':
|
elif flask.request.method == 'GET':
|
||||||
current_playing = history[-1] if history else None
|
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('''
|
return flask.render_template_string('''
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
@ -36,7 +58,7 @@ def musicstatus():
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&display=swap" rel="stylesheet">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Halhadus' Music Status</title>
|
<title>Music Status</title>
|
||||||
<link rel="icon" type="image/png" href="assets/favicon.png">
|
<link rel="icon" type="image/png" href="assets/favicon.png">
|
||||||
<meta name="description" content="Halhadus' Music Status">
|
<meta name="description" content="Halhadus' Music Status">
|
||||||
<meta name="author" content="Halhadus">
|
<meta name="author" content="Halhadus">
|
||||||
|
@ -67,10 +89,6 @@ def musicstatus():
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.thumbnail-container {
|
|
||||||
order: 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.thumbnail {
|
.thumbnail {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
|
@ -90,7 +108,6 @@ def musicstatus():
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-family: 'JetBrains Mono', monospace;
|
font-family: 'JetBrains Mono', monospace;
|
||||||
font-size: 0.9rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.history-table {
|
.history-table {
|
||||||
|
@ -98,7 +115,6 @@ def musicstatus():
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
margin-top: 2rem;
|
margin-top: 2rem;
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
display: block;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.history-table th,
|
.history-table th,
|
||||||
|
@ -108,9 +124,17 @@ def musicstatus():
|
||||||
min-width: 120px;
|
min-width: 120px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.history-table img {
|
.lyrics-container {
|
||||||
width: 80px;
|
background: #333;
|
||||||
border-radius: 4px;
|
border-radius: 8px;
|
||||||
|
padding: 1rem;
|
||||||
|
margin-top: 1rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lyrics-line {
|
||||||
|
margin: 0.5rem 0;
|
||||||
|
color: #ccc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: 768px) {
|
@media (min-width: 768px) {
|
||||||
|
@ -119,28 +143,22 @@ def musicstatus():
|
||||||
gap: 2rem;
|
gap: 2rem;
|
||||||
padding: 2rem;
|
padding: 2rem;
|
||||||
}
|
}
|
||||||
.thumbnail-container {
|
|
||||||
order: 0;
|
|
||||||
}
|
|
||||||
.play-button {
|
.play-button {
|
||||||
padding: 0.8rem 1.5rem;
|
padding: 0.8rem 1.5rem;
|
||||||
font-size: 1rem;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body style="background-color: var(--bg-color); color: var(--text-color); font-family: 'JetBrains Mono', monospace;">
|
<body style="background-color: var(--bg-color); color: var(--text-color);">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1>🎵 Music Status</h1>
|
<h1>🎵 Music Status</h1>
|
||||||
<a href="/index.html" class="play-button">← Main Page</a>
|
<a href="/index.html" class="play-button">← Main Page</a>
|
||||||
|
|
||||||
{% if current_playing %}
|
{% if current_playing %}
|
||||||
<div class="music-card">
|
<div class="music-card">
|
||||||
<div class="thumbnail-container">
|
<img src="https://img.youtube.com/vi/{{ current_playing[3] }}/hqdefault.jpg"
|
||||||
<img src="https://img.youtube.com/vi/{{ current_playing[3] }}/hqdefault.jpg"
|
class="thumbnail"
|
||||||
class="thumbnail"
|
alt="{{ current_playing[0] }} cover">
|
||||||
alt="{{ current_playing[0] }} cover">
|
|
||||||
</div>
|
|
||||||
<div>
|
<div>
|
||||||
<h2>{{ current_playing[0] }}</h2>
|
<h2>{{ current_playing[0] }}</h2>
|
||||||
<p>🕒 Last Updated: {{ format_timestamp(current_playing[1]) }}</p>
|
<p>🕒 Last Updated: {{ format_timestamp(current_playing[1]) }}</p>
|
||||||
|
@ -156,6 +174,14 @@ def musicstatus():
|
||||||
▶ YT Music
|
▶ YT Music
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
{% if lyrics_content %}
|
||||||
|
<div class="lyrics-container">
|
||||||
|
<h3>Lyrics</h3>
|
||||||
|
{% for line in lyrics_content %}
|
||||||
|
<p class="lyrics-line">{{ line }}</p>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@ -179,6 +205,7 @@ def musicstatus():
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<img src="https://img.youtube.com/vi/{{ entry[3] }}/hqdefault.jpg"
|
<img src="https://img.youtube.com/vi/{{ entry[3] }}/hqdefault.jpg"
|
||||||
|
style="width: 80px; border-radius: 4px;"
|
||||||
alt="{{ entry[0] }} thumbnail">
|
alt="{{ entry[0] }} thumbnail">
|
||||||
</td>
|
</td>
|
||||||
<td>{{ entry[0] }}</td>
|
<td>{{ entry[0] }}</td>
|
||||||
|
@ -197,7 +224,10 @@ def musicstatus():
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
''', 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):
|
def format_timestamp(timestamp):
|
||||||
return datetime.datetime.fromtimestamp(
|
return datetime.datetime.fromtimestamp(
|
||||||
|
@ -210,21 +240,20 @@ def verifycert():
|
||||||
global code
|
global code
|
||||||
data = flask.request.get_json()
|
data = flask.request.get_json()
|
||||||
with open("key.txt", "r") as f:
|
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))
|
code = ''.join(random.choices(string.ascii_uppercase + string.digits, k=64))
|
||||||
return code
|
return code
|
||||||
return "0"
|
return "0"
|
||||||
|
|
||||||
@app.route('/<path:path>')
|
@app.route('/<path:path>')
|
||||||
def catch_all(path):
|
def catch_all(path):
|
||||||
if path == None:
|
return flask.redirect(f'https://halhadus.rocks/{path}')
|
||||||
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('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
return flask.redirect('https://halhadus.rocks')
|
return flask.redirect('https://halhadus.rocks')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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')))
|
app.run(host='0.0.0.0', port=int(os.environ.get('PORT')))
|
||||||
|
|
Loading…
Add table
Reference in a new issue