Fixed urls

This commit is contained in:
Halhadus 2025-02-15 15:41:12 +03:00
parent 0ff466649a
commit 6ddc5a99ec

View file

@ -10,25 +10,8 @@ app.config['LYRICS_DIR'] = 'lyrics'
code = ""
history = []
def is_youtube_url(url):
yt_patterns = [
r'youtube\.com/watch\?v=',
r'music\.youtube\.com/watch\?v=',
r'youtu\.be/'
]
return any(re.search(pattern, url) for pattern in yt_patterns)
def extract_yt_id(url):
patterns = [
r'v=([a-zA-Z0-9_-]{11})',
r'youtu\.be/([a-zA-Z0-9_-]{11})',
r'/([a-zA-Z0-9_-]{11})$'
]
for pattern in patterns:
match = re.search(pattern, url)
if match:
return match.group(1)
return None
def is_youtube_id(a):
return re.match(r'^[a-zA-Z0-9_-]{11}$', a) is not None
@app.route('/musicstatus.html', methods=['GET', 'POST'])
def musicstatus():
@ -44,7 +27,7 @@ def musicstatus():
data['music'],
data['time'],
data['resetstatus'],
data['videoid']
data['videoid'] # Tam URL saklanıyor
)
if data.get('resetstatus', '').lower() == "true":
@ -76,7 +59,8 @@ def musicstatus():
<meta name="author" content="Halhadus">
<meta property="og:title" content="Halhadus' Music Status">
<meta property="og:description" content="Halhadus' Music Status">
<meta property="og:url" content="https://halhadus.rocks/musicstatus.html">
<meta property="og:url" content="https://music.halhadus.rocks">
<meta property="og:image" content="https://music.halhadus.rocks/assets/favicon.png">
<style>
:root {
--bg-color: #1f1f1f;
@ -161,7 +145,7 @@ def musicstatus():
{% if current_playing %}
<div class="music-card">
{% if is_youtube(current_playing[3]) %}
<img src="https://img.youtube.com/vi/{{ extract_yt_id(current_playing[3]) }}/hqdefault.jpg"
<img src="https://img.youtube.com/vi/{{ current_playing[3] }}/hqdefault.jpg"
class="thumbnail"
alt="{{ current_playing[0] }} cover">
{% else %}
@ -175,18 +159,18 @@ def musicstatus():
<p>🕒 Last Updated: {{ format_timestamp(current_playing[1]) }}</p>
<div>
{% if is_youtube(current_playing[3]) %}
<a href="https://www.youtube.com/watch?v={{ extract_yt_id(current_playing[3]) }}"
<a href="https://www.youtube.com/watch?v={{ current_playing[3] }}"
class="play-button"
target="_blank">
YouTube
</a>
<a href="https://music.youtube.com/watch?v={{ extract_yt_id(current_playing[3]) }}"
<a href="https://music.youtube.com/watch?v={{ current_playing[3] }}"
class="play-button"
target="_blank">
YT Music
</a>
{% else %}
<a href="{{ current_playing[3] }}"
<a href="https://{{ current_playing[3] }}"
class="play-button"
target="_blank">
Play Source
@ -224,7 +208,7 @@ def musicstatus():
<tr>
<td>
{% if is_youtube(entry[3]) %}
<img src="https://img.youtube.com/vi/{{ extract_yt_id(entry[3]) }}/hqdefault.jpg"
<img src="https://img.youtube.com/vi/{{ entry[3] }}/hqdefault.jpg"
style="width: 80px; border-radius: 4px;"
alt="{{ entry[0] }} thumbnail">
{% else %}
@ -236,7 +220,11 @@ def musicstatus():
<td>{{ entry[0] }}</td>
<td>{{ format_timestamp(entry[1]) }}</td>
<td>
<a href="{{ entry[3] }}"
{% if is_youtube(entry[3]) %}
<a href="https://music.youtube.com/watch?v={{ entry[3] }}"
{% else %}
<a href="https://{{ entry[3] }}"
{% endif %}
class="play-button"
target="_blank">
@ -252,8 +240,7 @@ def musicstatus():
''', current_playing=current_playing,
history=history,
format_timestamp=lambda ts: datetime.datetime.fromtimestamp(int(ts), datetime.timezone.utc).strftime("%Y-%m-%d %H:%M UTC"),
is_youtube=is_youtube_url,
extract_yt_id=extract_yt_id,
is_youtube=is_youtube_id,
lyrics_content=lyrics_content)
@app.route('/verifykey', methods=['POST'])