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 = "\n\n\n\n\n\n\n" random.shuffle(musiclist) html += "

Music List


\n" html += "

Click on the music to listen


\n" html += "

List is randomized. To see history of list and source codes of scripts which I used to generate this list, click here


\n" html += """



\n""" musiccount = 0 for music in musiclist: musiccount += 1 music = music.strip().split(" --- ") if music[2] == "YTM": html += f"{musiccount}.{music[0]}
\n" elif music[2] == "YT": html += f"{musiccount}.{music[0]}
\n" else: print("Invalid provider") exit() html += f"Count: {musiccount}\n\n" with open("musiclist.html", "w") as f: f.write(html) print("Done")