my-music-list/randomizermodule.py

35 lines
2.6 KiB
Python

import os
import random
import requests
def randomize(listurl):
# Please don't refresh too fast and kill my website and git server...
musiclist = requests.get(listurl).text.split("\n")
musiclist = [music for music in musiclist if music != ""]
html = "<!DOCTYPE html>\n<html lang=\"en\">\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"
html += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n"
html += "<title>Halhadus' Music List</title>\n"
html += "<link rel=\"icon\" type=\"image/png\" href=\"assets/favicon.png\">\n"
html += "<meta name=\"description\" content=\"Halhadus' Music List\">\n"
html += "<meta property=\"og:title\" content=\"Halhadus' Music List\">\n"
html += "<meta property=\"og:description\" content=\"Halhadus' Music List\">\n"
html += "<meta property=\"og:image\" content=\"assets/favicon.png\">\n"
html += "<meta property=\"og:url\" content=\"https://halhadus.rocks/musiclist.html\">\n"
random.shuffle(musiclist)
html += "<h1>Music List</h1><br>\n"
html += "<h2>Click on the music to listen</h2><br>\n"
html += "<button onclick=\"window.location.href = 'https://halhadus.rocks/index.html';\" style=\"background-color: #333333; color: #ffffff; font-family: 'Jetbrains Mono', monospace;\">Back to Main Page</button><br><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")
html += f"Count: {musiccount}\n</body>\n</html>"
return html