Auto commit: 2026-02-16T20:28:55.842Z

This commit is contained in:
Flatlogic Bot 2026-02-16 20:28:55 +00:00
parent 97f37c8c7e
commit ffe4625436
2 changed files with 77 additions and 2 deletions

27
api/top-songs.php Normal file
View File

@ -0,0 +1,27 @@
<?php
header('Content-Type: application/json');
require_once __DIR__ . '/../db/config.php';
try {
$pdo = db();
// Obtenemos las 5 canciones con más likes que hayan sido actualizadas en los últimos 7 días
$stmt = $pdo->prepare("
SELECT song_title, likes_count
FROM song_likes
WHERE last_liked_at >= DATE_SUB(NOW(), INTERVAL 7 DAY)
ORDER BY likes_count DESC
LIMIT 5
");
$stmt->execute();
$songs = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode([
'success' => true,
'data' => $songs
]);
} catch (Exception $e) {
echo json_encode([
'success' => false,
'error' => $e->getMessage()
]);
}

View File

@ -771,6 +771,15 @@ $facebook_link = "https://www.facebook.com/profile.php?id=61587890927489";
<div id="recent-tracks-list" style="display: flex; flex-direction: column; gap: 0.5rem;"></div>
</div>
<div id="top-songs-container" style="margin-top: 1.5rem; background: rgba(255, 255, 255, 0.03); padding: 1rem; border-radius: 16px; border: 1px solid rgba(255, 255, 255, 0.05);">
<span class="track-label" style="font-size: 0.65rem; margin-bottom: 0.8rem; color: #facc15;">
<i class="bi bi-trophy-fill"></i> TOP CANCIONES DE LA SEMANA
</span>
<div id="top-songs-list" style="display: flex; flex-direction: column; gap: 0.6rem;">
<div style="font-size: 0.8rem; opacity: 0.5; text-align: center;">Cargando ranking...</div>
</div>
</div>
<div class="interaction-form">
<div class="form-row">
<div class="form-group">
@ -1445,11 +1454,17 @@ $facebook_link = "https://www.facebook.com/profile.php?id=61587890927489";
item.style.fontSize = '0.75rem';
item.style.border = '1px solid rgba(255,255,255,0.05)';
const likesCount = track.likes || '0';
item.innerHTML = `
<img src="${track.cover}" style="width: 30px; height: 30px; border-radius: 4px; object-fit: cover;">
<div style="flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; opacity: 0.7;">
${track.title}
</div>
<div style="display: flex; align-items: center; gap: 3px; color: #ff4444; font-weight: bold; opacity: 0.9;">
<i class="bi bi-heart-fill" style="font-size: 0.65rem;"></i>
<span>${likesCount}</span>
</div>
`;
list.appendChild(item);
});
@ -1458,6 +1473,34 @@ $facebook_link = "https://www.facebook.com/profile.php?id=61587890927489";
// Initial render
renderRecentTracks();
async function fetchTopSongs() {
try {
const response = await fetch('api/top-songs.php');
const result = await response.json();
if (result.success && result.data) {
const list = document.getElementById('top-songs-list');
if (result.data.length === 0) {
list.innerHTML = '<div style="font-size: 0.8rem; opacity: 0.5; text-align: center;">Aún no hay votos esta semana.</div>';
return;
}
list.innerHTML = result.data.map((song, index) => `
<div style="display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,0.05); padding: 0.6rem 0.8rem; border-radius: 10px; border: 1px solid rgba(255,255,255,0.05); transition: transform 0.2s; cursor: default;" onmouseover="this.style.transform='translateX(5px)'" onmouseout="this.style.transform='translateX(0)'">
<div style="display: flex; align-items: center; gap: 10px; overflow: hidden;">
<span style="font-weight: 800; color: #facc15; font-size: 0.9rem; min-width: 20px;">#${index + 1}</span>
<span style="font-size: 0.85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">${song.song_title}</span>
</div>
<div style="display: flex; align-items: center; gap: 4px; color: #ff4444; font-weight: bold; font-size: 0.8rem;">
<i class="bi bi-heart-fill"></i>
<span>${song.likes_count}</span>
</div>
</div>
`).join('');
}
} catch (error) {
console.error('Error fetching top songs:', error);
}
}
// Fetch Now Playing Metadata from RadioKing
async function updateMetadata() {
try {
@ -1478,7 +1521,8 @@ $facebook_link = "https://www.facebook.com/profile.php?id=61587890927489";
if (trackTitle.textContent !== "Cargando stream..." && trackTitle.textContent !== "Lili Records Radio - En Vivo") {
const prevTrack = {
title: trackTitle.textContent,
cover: trackCover.src
cover: trackCover.src,
likes: document.getElementById('like-count').innerText || '0'
};
// Avoid duplicates
if (recentTracks.length === 0 || recentTracks[0].title !== prevTrack.title) {
@ -1558,7 +1602,11 @@ $facebook_link = "https://www.facebook.com/profile.php?id=61587890927489";
// Update every 30 seconds
updateMetadata();
setInterval(updateMetadata, 30000);
fetchTopSongs();
setInterval(() => {
updateMetadata();
fetchTopSongs();
}, 30000);
// Handle possible audio interruptions
audio.addEventListener('error', function(e) {