42 lines
1.9 KiB
Python
42 lines
1.9 KiB
Python
import os
|
|
import random
|
|
|
|
if not os.path.exists("musiclist.txt"):
|
|
print("musiclist.txt not found")
|
|
exit()
|
|
if os.path.exists("musiclist.html"):
|
|
if os.path.exists("musiclist.html.old"):
|
|
input("musiclist.html and musiclist.html.old already exists. Press Enter to overwrite musiclist.html.old or Ctrl+C to exit")
|
|
os.remove("musiclist.html.old")
|
|
os.rename("musiclist.html", "musiclist.html.old")
|
|
|
|
with open("musiclist.txt", "r") as f:
|
|
musiclist = f.readlines()
|
|
|
|
html = "<!DOCTYPE html>\n<html>\n<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<body style=\"background-color: #1f1f1f; color: #ffffff; font-family: 'Jetbrains Mono', monospace;\">\n"
|
|
|
|
random.shuffle(musiclist)
|
|
|
|
html += "<h1>Music List</h1><br>\n"
|
|
html += "<h2>Click on the music to listen</h2><br>\n"
|
|
html += "<h2><a href=\"https://git.halhadus.rocks/Halhadus/my-music-list\">List is randomized. To see history of list and source codes of scripts which I used to generate this list, click here</a></h2><br>\n"
|
|
html += """<br><br><button onclick="window.location.href = document.links[Math.floor(Math.random() * document.links.length)].href;" style="background-color: #333333; color: #ffffff; font-family: 'Jetbrains Mono', monospace;">Select Random Music</button><br><br>\n"""
|
|
|
|
musiccount = 0
|
|
for music in musiclist:
|
|
musiccount += 1
|
|
music = music.strip().split(" --- ")
|
|
if music[2] == "YTM":
|
|
html += f"<a href=\"https://music.youtube.com/watch?v={music[1]}\" style=\"color: #ffffff;\">{musiccount}.{music[0]}</a><br>\n"
|
|
elif music[2] == "YT":
|
|
html += f"<a href=\"https://www.youtube.com/watch?v={music[1]}\" style=\"color: #ffffff;\">{musiccount}.{music[0]}</a><br>\n"
|
|
else:
|
|
print("Invalid provider")
|
|
exit()
|
|
|
|
html += f"Count: {musiccount}\n</body>\n</html>"
|
|
|
|
with open("musiclist.html", "w") as f:
|
|
f.write(html)
|
|
|
|
print("Done")
|