my-music-list/websitemodule.py

142 lines
4.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import random
import requests
# Ana kod Halhadus tarafından yazılmış ve DeepSeek-R1 tarafından optimize ve stilize edilmiştir.
def randomize(listurl):
# Veri çekme ve temizleme
musiclist = requests.get(listurl).text.split("\n")
musiclist = [m.strip() for m in musiclist if m.strip() != ""]
# HTML başlangıç template'i
html = """<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&display=swap" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Halhadus' Music List</title>
<link rel="icon" type="image/png" href="assets/favicon.png">
<meta name="description" content="Halhadus' Music List">
<meta property="og:title" content="Halhadus' Music List">
<meta property="og:description" content="Halhadus' Music List">
<meta property="og:image" content="assets/favicon.png">
<meta property="og:url" content="https://halhadus.rocks/musiclist.html">
<style>
.music-card {
background: #2a2a2a;
border-radius: 8px;
padding: 15px;
margin: 15px 0;
transition: transform 0.2s;
border: 1px solid #333333;
}
.music-card:hover {
transform: translateY(-2px);
}
.play-button {
background: #333333;
border: 1px solid #444444;
border-radius: 5px;
color: #ffffff;
padding: 6px 12px;
cursor: pointer;
margin-left: 15px;
font-family: 'JetBrains Mono', monospace;
font-size: 0.9em;
}
.play-button:hover {
background: #3a3a3a;
}
.thumbnail {
border-radius: 5px;
margin-top: 12px;
max-width: 280px;
border: 1px solid #333333;
}
.source-banner {
background: #2a2a2a;
padding: 12px;
border-radius: 8px;
margin: 20px 0;
text-align: center;
border: 1px solid #333333;
}
</style>
</head>
<body style="background-color: #1f1f1f; color: #ffffff; font-family: 'JetBrains Mono', monospace;">
<div style="max-width: 800px; margin: 0 auto; padding: 20px;">
<!-- Source Banner -->
<div class="source-banner">
<a href="https://git.halhadus.rocks/Halhadus/my-music-list"
style="color: #ffffff; text-decoration: none;">
[ 📜 Source Code & History ]
</a>
</div>
<h1>Music List</h1>
<!-- Kontrol Butonları -->
<div style="margin-bottom: 30px; display: flex; gap: 10px;">
<button onclick="window.location.href = 'https://halhadus.rocks/index.html'"
class="play-button">
← Main Page
</button>
<button onclick="window.open(document.links[Math.floor(Math.random() * document.links.length)].href)"
class="play-button">
Random Track →
</button>
</div>"""
random.shuffle(musiclist)
musiccount = 0
# Müzik kartları oluşturma
for music in musiclist:
try:
parts = music.split(" --- ")
if len(parts) != 3:
continue
title, vid, platform = parts
musiccount += 1
# Thumbnail URL'si
thumbnail_url = f"https://img.youtube.com/vi/{vid}/hqdefault.jpg"
# Platforma göre URL belirleme
base_url = "music.youtube.com" if platform == "YTM" else "www.youtube.com"
yt_url = f"https://{base_url}/watch?v={vid}"
# HTML blok
html += f"""
<div class="music-card">
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="color: #888; margin-right: 10px;">#{musiccount}</span>
<span style="flex-grow: 1;">{title}</span>
<button onclick="window.open('{yt_url}')" class="play-button">
{platform}
</button>
</div>
<img src="{thumbnail_url}"
class="thumbnail"
alt="{title} Cover Art"
onerror="this.style.display='none'">
</div>"""
except Exception as e:
print(f"Error processing: {music} - {str(e)}")
# Footer kısmı
html += f"""
<div style="margin-top: 40px; text-align: center; color: #666;">
<div style="margin-bottom: 15px;">
Total Tracks: {musiccount}
</div>
</div>
</div>
</body>
</html>"""
return html