Updated website module, ypdated musiccombo binary

This commit is contained in:
Halhadus 2025-02-08 01:15:28 +03:00
parent 00be7a6563
commit 359b1507b8
5 changed files with 280 additions and 184 deletions

View file

@ -104,6 +104,7 @@ def get_db_values(url: str = "https://halhadus.rocks/assets/localwrapped/music.d
for row in musicrows:
musicvalues.append({
"listmusicname": row[0],
"listvideoid": row[1],
"fileartistname": row[4],
"filealbumname": row[5],
"filemusictitle": row[6]
@ -167,7 +168,7 @@ while True:
verificationcode = get_verification_code()
if verificationcode == None:
continue
requests.post(os.environ["MSSERVER"] + "/musicstatus.html", json={"music": i["listmusicname"], "time": str(int(time.time())), "verificationcode": verificationcode, "resetstatus": resetstatus})
requests.post(os.environ["MSSERVER"] + "/musicstatus.html", json={"music": i["listmusicname"], "time": str(int(time.time())),"videoid":i["listvideoid"], "verificationcode": verificationcode, "resetstatus": resetstatus})
print("Data sent")
resetstatus = "false"
a += 1

Binary file not shown.

View file

@ -1,119 +0,0 @@
import subprocess
import re
import time
import sqlite3
import os
import requests
def get_working_directory():
# If you see this function, that means you are using the pyinstaller. Use this command to create the executable:
# pyinstaller -s -F musicstatus-pyi.py --runtime-tmpdir /data/local/tmp
if os.path.exists("/sdcard/localwrapped"):
return "/sdcard/localwrapped"
elif os.path.exists("/storage/emulated/0/localwrapped"):
return "/storage/emulated/0/localwrapped"
elif os.path.exists("/data/media/0/localwrapped"):
return "/data/media/0/localwrapped"
elif os.path.exists("/mnt/user/0/emulated/0/localwrapped"):
return "/mnt/user/0/emulated/0/localwrapped"
else:
print("Local Wrapped directory not found.")
if not os.path.exists(f"{get_working_directory()}/key.txt"):
print("Key not exist")
exit()
if not os.path.exists(f"{get_working_directory()}/music.db"):
try:
getmusicdb = requests.get("https://halhadus.rocks/assets/localwrapped/music.db")
with open(f"{get_working_directory()}/music.db", "wb") as f:
f.write(getmusicdb.content)
except:
print("music.db not exist and download failed.")
def get_verification_code():
try:
with open(f'{get_working_directory()/key.txt}')
key = f.read()
try:
verifyrequest = requests.post(os.environ["MSSERVER"] + "/verifykey", json={"key": key})
if verifyrequest.text == "0":
print("Verification failed")
return None
elif len(verifyrequest.text) == 64:
print("Verification success")
return verifyrequest.text
else:
print("Unexpected response")
return None
except:
print("Can't reach the server.")
time.sleep(15)
get_verification_code()
except:
print("Key not exist")
return None
def get_music():
dumpsys_output = subprocess.check_output("dumpsys media_session", shell=True).decode("utf-8").split("\n")
if not [line for line in dumpsys_output if "PLAYING" in line]:
return None
else:
description = [line for line in dumpsys_output if "description=" in line]
try:
return description[0].split("description=")[1]
except:
return None
def get_db_values():
musicconn = sqlite3.connect(f"{get_working_directory()}/music.db")
musicc = musicconn.cursor()
musicc.execute("SELECT * FROM music")
musicrows = musicc.fetchall()
musicconn.close()
musicvalues = []
for row in musicrows:
musicvalues.append({
"listmusicname": row[0],
"fileartistname": row[4],
"filealbumname": row[5],
"filemusictitle": row[6]
})
return musicvalues
a = 0
last_written = None
resetstatus = "true"
while True:
if get_music() == None:
continue
last_music = get_music()
time.sleep(5)
if last_music == get_music():
if last_written == last_music:
continue
a += 1
if a == 1:
for i in get_db_values():
if i["filealbumname"] == None:
full_name = i["filemusictitle"] + ", " + i["fileartistname"] + ", " + "Music"
else:
full_name = i["filemusictitle"] + ", " + i["fileartistname"] + ", " + i["filealbumname"]
if full_name == last_music:
try:
verificationcode = get_verification_code()
if verificationcode == None:
continue
requests.post(os.environ["MSSERVER"] + "/musicstatus.html", json={"music": i["listmusicname"], "time": str(int(time.time())), "verificationcode": verificationcode, "resetstatus": resetstatus})
print("Sent")
resetstatus = "false"
except:
print("Can't reach the server.")
time.sleep(15)
last_written = last_music
a = 0
continue
else:
a = 0
continue

View file

@ -3,9 +3,9 @@ import datetime
import random
import string
import os
import re
app = flask.Flask(__name__)
code = ""
history = []
@ -14,72 +14,201 @@ def musicstatus():
global code, history
if flask.request.method == 'POST':
data = flask.request.get_json()
if code == "":
return "Verification code not generated"
if data['verificationcode'] != code:
return "Verification failed"
else:
musicname = data['music']
time = data['time']
resetstatus = data['resetstatus']
history.append((musicname, time, resetstatus))
return f"{musicname} added to history"
elif flask.request.method == 'GET':
html = '<DOCTYPE html>\n<html>\n'
html += '<head>\n<meta charset="UTF-8">\n<link href="https://fonts.googleapis.com/css2?family=Jetbrains+Mono:wght@400;700&display=swap" rel="stylesheet">\n</head>\n'
html += '<body style="background-color: #1f1f1f; color: #ffffff; font-family: \'Jetbrains Mono\', monospace;">\n<meta name="viewport" content="width=device-width, initial-scale=1.0">\n'
html += '<title>Halhadus\' Music Status</title>\n<link rel="icon" type="image/png" href="assets/favicon.png">\n'
html += '<meta name="description" content="Halhadus\' Music Status">\n<meta property="og:title" content="Halhadus\' Music Status">\n'
html += '<meta property="og:description" content="Halhadus\' Music Status">\n<meta property="og:image" content="assets/favicon.png">\n'
html += '<meta property="og:url" content="https://halhadus.rocks/musicstatus.html">\n'
html += '<h1>Halhadus\' Music Status</h1>\n'
html += '<a href="https://git.halhadus.rocks/Halhadus/localwrappedmusicstatus-combo-allinonerepo" style="color: #ffffff;">Source Code</a>\n'
html += '<h3>Hi guys. I am too lazy to add links to song names. To find which song is it, check <a href="musiclist.html" style="color: #ffffff;">this link</a>.</h3>\n'
html += '<form action="index.html">\n<input type="submit" value="Back to main page" style="background-color: #1f1f1f; color: #ffffff; border: 2px solid #ffffff; border-radius: 5px; padding: 10px 20px; margin: 10px 0px;">\n</form>\n'
if len(history) > 0:
if history[-1][2] == "true":
currentbeforereset = history[-1]
history = []
history.append(currentbeforereset)
html += f'<h2>Currently Playing: {history[-1][0]}</h2>\n'
html += f'<h2>Last Update Time: {datetime.datetime.fromtimestamp(int(history[-1][1]), datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S")} (UTC +0)</h2>\n'
if os.path.exists("lyrics/" + history[-1][0] + ".lrc"):
with open("lyrics/" + history[-1][0] + ".lrc", "r") as f:
lyrics = f.read().split("\n")
lyrics = [lyric.split("]")[1] for lyric in lyrics if "]" in lyric]
lyrics = [lyric for lyric in lyrics if not lyric == ""]
html += '<h3>Lyrics:</h3>\n'
html += '<div style="border: 1px solid #ffffff; padding: 10px; text-align: center;">\n'
for lyric in lyrics:
html += f'<p>{lyric}</p>\n'
html += '</div>\n'
html += '<table style="width: 100%; border-collapse: collapse;">\n<tr>\n<th style="border: 1px solid #ffffff; padding: 10px;">Music Name</th>\n<th style="border: 1px solid #ffffff; padding: 10px;">Time</th>\n</tr>\n'
for music in history[::-1]:
html += '<tr>\n<td style="border: 1px solid #ffffff; padding: 10px;">' + music[0] + '</td>\n<td style="border: 1px solid #ffffff; padding: 10px;">' + datetime.datetime.fromtimestamp(int(music[1]), datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S") + '</td>\n</tr>\n'
html += '</table>\n</body>\n</html>'
return html
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"
@app.route('/verifykey', methods=['GET', 'POST'])
elif flask.request.method == 'GET':
current_playing = history[-1] if history else None
return flask.render_template_string('''
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<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">
<title>Halhadus' Music Status</title>
<style>
:root {
--bg-color: #1f1f1f;
--card-bg: #2a2a2a;
--border-color: #333;
--text-color: #ffffff;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 1rem;
}
.music-card {
background: var(--card-bg);
border-radius: 8px;
margin: 1rem 0;
padding: 1rem;
display: grid;
grid-template-columns: 1fr;
gap: 1rem;
}
.thumbnail-container {
order: 2;
}
.thumbnail {
width: 100%;
border-radius: 6px;
aspect-ratio: 16/9;
object-fit: cover;
border: 2px solid var(--border-color);
}
.play-button {
background: #333;
border: 1px solid #444;
color: var(--text-color);
padding: 0.6rem 1rem;
margin: 0.3rem;
border-radius: 5px;
text-decoration: none;
display: inline-block;
text-align: center;
font-family: 'JetBrains Mono', monospace;
font-size: 0.9rem;
}
.history-table {
width: 100%;
border-collapse: collapse;
margin-top: 2rem;
overflow-x: auto;
display: block;
}
.history-table th,
.history-table td {
border: 1px solid var(--border-color);
padding: 0.8rem;
min-width: 120px;
}
.history-table img {
width: 80px;
border-radius: 4px;
}
@media (min-width: 768px) {
.music-card {
grid-template-columns: 200px 1fr;
gap: 2rem;
padding: 2rem;
}
.thumbnail-container {
order: 0;
}
.play-button {
padding: 0.8rem 1.5rem;
font-size: 1rem;
}
}
</style>
</head>
<body style="background-color: var(--bg-color); color: var(--text-color); font-family: 'JetBrains Mono', monospace;">
<div class="container">
<h1>🎵 Music Status</h1>
<a href="/index.html" class="play-button"> Main Page</a>
{% if current_playing %}
<div class="music-card">
<div class="thumbnail-container">
<img src="https://img.youtube.com/vi/{{ current_playing[3] }}/hqdefault.jpg"
class="thumbnail"
alt="{{ current_playing[0] }} cover">
</div>
<div>
<h2>{{ current_playing[0] }}</h2>
<p>🕒 Last Updated: {{ format_timestamp(current_playing[1]) }}</p>
<div>
<a href="https://www.youtube.com/watch?v={{ current_playing[3] }}"
class="play-button"
target="_blank">
YouTube
</a>
<a href="https://music.youtube.com/watch?v={{ current_playing[3] }}"
class="play-button"
target="_blank">
YT Music
</a>
</div>
</div>
</div>
{% else %}
<div class="music-card">
<p>No music currently playing</p>
</div>
{% endif %}
<h2>Play History</h2>
<table class="history-table">
<thead>
<tr>
<th>Cover</th>
<th>Title</th>
<th>Time</th>
<th>Play</th>
</tr>
</thead>
<tbody>
{% for entry in history|reverse %}
<tr>
<td>
<img src="https://img.youtube.com/vi/{{ entry[3] }}/hqdefault.jpg"
alt="{{ entry[0] }} thumbnail">
</td>
<td>{{ entry[0] }}</td>
<td>{{ format_timestamp(entry[1]) }}</td>
<td>
<a href="https://www.youtube.com/watch?v={{ entry[3] }}"
class="play-button"
target="_blank">
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</body>
</html>
''', 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
if flask.request.method == 'POST':
data = flask.request.get_json()
key = data['key']
with open("key.txt", "r") as f:
if key == f.read():
code = ''.join(random.choices(string.ascii_uppercase + string.digits, k=64))
return code
else:
return "0"
elif flask.request.method == 'GET':
return "GET method not allowed"
@app.route('/<path:path>')
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}')
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"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=int(os.environ.get('PORT')))

85
websitepart.py.old Normal file
View file

@ -0,0 +1,85 @@
import flask
import datetime
import random
import string
import os
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 == "":
return "Verification code not generated"
if data['verificationcode'] != code:
return "Verification failed"
else:
musicname = data['music']
time = data['time']
resetstatus = data['resetstatus']
history.append((musicname, time, resetstatus))
return f"{musicname} added to history"
elif flask.request.method == 'GET':
html = '<DOCTYPE html>\n<html>\n'
html += '<head>\n<meta charset="UTF-8">\n<link href="https://fonts.googleapis.com/css2?family=Jetbrains+Mono:wght@400;700&display=swap" rel="stylesheet">\n</head>\n'
html += '<body style="background-color: #1f1f1f; color: #ffffff; font-family: \'Jetbrains Mono\', monospace;">\n<meta name="viewport" content="width=device-width, initial-scale=1.0">\n'
html += '<title>Halhadus\' Music Status</title>\n<link rel="icon" type="image/png" href="assets/favicon.png">\n'
html += '<meta name="description" content="Halhadus\' Music Status">\n<meta property="og:title" content="Halhadus\' Music Status">\n'
html += '<meta property="og:description" content="Halhadus\' Music Status">\n<meta property="og:image" content="assets/favicon.png">\n'
html += '<meta property="og:url" content="https://halhadus.rocks/musicstatus.html">\n'
html += '<h1>Halhadus\' Music Status</h1>\n'
html += '<a href="https://git.halhadus.rocks/Halhadus/localwrappedmusicstatus-combo-allinonerepo" style="color: #ffffff;">Source Code</a>\n'
html += '<h3>Hi guys. I am too lazy to add links to song names. To find which song is it, check <a href="musiclist.html" style="color: #ffffff;">this link</a>.</h3>\n'
html += '<form action="index.html">\n<input type="submit" value="Back to main page" style="background-color: #1f1f1f; color: #ffffff; border: 2px solid #ffffff; border-radius: 5px; padding: 10px 20px; margin: 10px 0px;">\n</form>\n'
if len(history) > 0:
if history[-1][2] == "true":
currentbeforereset = history[-1]
history = []
history.append(currentbeforereset)
html += f'<h2>Currently Playing: {history[-1][0]}</h2>\n'
html += f'<h2>Last Update Time: {datetime.datetime.fromtimestamp(int(history[-1][1]), datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S")} (UTC +0)</h2>\n'
if os.path.exists("lyrics/" + history[-1][0] + ".lrc"):
with open("lyrics/" + history[-1][0] + ".lrc", "r") as f:
lyrics = f.read().split("\n")
lyrics = [lyric.split("]")[1] for lyric in lyrics if "]" in lyric]
lyrics = [lyric for lyric in lyrics if not lyric == ""]
html += '<h3>Lyrics:</h3>\n'
html += '<div style="border: 1px solid #ffffff; padding: 10px; text-align: center;">\n'
for lyric in lyrics:
html += f'<p>{lyric}</p>\n'
html += '</div>\n'
html += '<table style="width: 100%; border-collapse: collapse;">\n<tr>\n<th style="border: 1px solid #ffffff; padding: 10px;">Music Name</th>\n<th style="border: 1px solid #ffffff; padding: 10px;">Time</th>\n</tr>\n'
for music in history[::-1]:
html += '<tr>\n<td style="border: 1px solid #ffffff; padding: 10px;">' + music[0] + '</td>\n<td style="border: 1px solid #ffffff; padding: 10px;">' + datetime.datetime.fromtimestamp(int(music[1]), datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S") + '</td>\n</tr>\n'
html += '</table>\n</body>\n</html>'
return html
@app.route('/verifykey', methods=['GET', 'POST'])
def verifycert():
global code
if flask.request.method == 'POST':
data = flask.request.get_json()
key = data['key']
with open("key.txt", "r") as f:
if key == f.read():
code = ''.join(random.choices(string.ascii_uppercase + string.digits, k=64))
return code
else:
return "0"
elif flask.request.method == 'GET':
return "GET method not allowed"
@app.route('/<path:path>')
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}')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=int(os.environ.get('PORT')))