2024-11-24 19:27:09 -05:00
import os
import random
2024-11-24 19:37:43 -05:00
import requests
2024-11-24 19:27:09 -05:00
2024-11-24 19:37:43 -05:00
def randomize ( listurl ) :
# Please don't refresh too fast and kill my website and git server...
musiclist = requests . get ( listurl ) . text . split ( " \n " )
2024-11-24 19:45:06 -05:00
musiclist = [ music for music in musiclist if music != " " ]
2024-11-24 19:27:09 -05:00
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