import os
import random
import requests
def randomize(base_url):
# Fetch both lists
yt_list = requests.get(f"{base_url}musiclist.txt").text.split("\n")
other_list = requests.get(f"{base_url}other-providers.txt").text.split("\n")
# HTML template
html = """
Music List
← Main Page
Random Track →
"""
total_count = 0
sections = [
("YouTube Music", yt_list, True),
("Other Providers", other_list, False)
]
# Process both sections
for section_name, musiclist, show_thumb in sections:
html += f"\n
{section_name} "
section_count = 0
random.shuffle(musiclist)
for music in musiclist:
try:
music = music.strip()
if not music:
continue
# Parse entry
if section_name == "YouTube Music":
title, vid, platform = music.split(" --- ")
yt_url = f"https://{'music.youtube.com' if platform == 'YTM' else 'www.youtube.com'}/watch?v={vid}"
btn_text = platform
else:
display_name, url, _ = music.split(" --- ")
yt_url = url
btn_text = "Other"
# Generate HTML
html += f"""
#{total_count+1}
{display_name if section_name == "Other Providers" else title}
{btn_text} →
"""
if show_thumb and section_name == "YouTube Music":
html += f"""
"""
html += "\n
"
total_count += 1
section_count += 1
except Exception as e:
print(f"Error processing: {music} - {str(e)}")
# Footer
html += f"""
Total Tracks: {total_count}
"""
return html