mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
fix: include manual external mappings in fallback playlist stats and add live UI refresh
This commit is contained in:
@@ -469,9 +469,31 @@ public class AdminController : ControllerBase
|
|||||||
foreach (var track in spotifyTracks)
|
foreach (var track in spotifyTracks)
|
||||||
{
|
{
|
||||||
var isLocal = false;
|
var isLocal = false;
|
||||||
|
var hasExternalMapping = false;
|
||||||
|
|
||||||
if (localTracks.Count > 0)
|
// FIRST: Check for manual Jellyfin mapping
|
||||||
|
var manualMappingKey = $"spotify:manual-map:{config.Name}:{track.SpotifyId}";
|
||||||
|
var manualJellyfinId = await _cache.GetAsync<string>(manualMappingKey);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(manualJellyfinId))
|
||||||
{
|
{
|
||||||
|
// Manual Jellyfin mapping exists - this track is definitely local
|
||||||
|
isLocal = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Check for external manual mapping
|
||||||
|
var externalMappingKey = $"spotify:external-map:{config.Name}:{track.SpotifyId}";
|
||||||
|
var externalMappingJson = await _cache.GetStringAsync(externalMappingKey);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(externalMappingJson))
|
||||||
|
{
|
||||||
|
// External manual mapping exists
|
||||||
|
hasExternalMapping = true;
|
||||||
|
}
|
||||||
|
else if (localTracks.Count > 0)
|
||||||
|
{
|
||||||
|
// SECOND: No manual mapping, try fuzzy matching with local tracks
|
||||||
var bestMatch = localTracks
|
var bestMatch = localTracks
|
||||||
.Select(local => new
|
.Select(local => new
|
||||||
{
|
{
|
||||||
@@ -495,6 +517,7 @@ public class AdminController : ControllerBase
|
|||||||
isLocal = true;
|
isLocal = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isLocal)
|
if (isLocal)
|
||||||
{
|
{
|
||||||
@@ -502,8 +525,8 @@ public class AdminController : ControllerBase
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Check if external track is matched
|
// Check if external track is matched (either manual mapping or auto-matched)
|
||||||
if (matchedSpotifyIds.Contains(track.SpotifyId))
|
if (hasExternalMapping || matchedSpotifyIds.Contains(track.SpotifyId))
|
||||||
{
|
{
|
||||||
externalMatchedCount++;
|
externalMatchedCount++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1202,8 +1202,37 @@
|
|||||||
if (hash) {
|
if (hash) {
|
||||||
switchTab(hash);
|
switchTab(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start auto-refresh for playlists tab (every 5 seconds)
|
||||||
|
startPlaylistAutoRefresh();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Auto-refresh functionality for playlists
|
||||||
|
let playlistAutoRefreshInterval = null;
|
||||||
|
|
||||||
|
function startPlaylistAutoRefresh() {
|
||||||
|
// Clear any existing interval
|
||||||
|
if (playlistAutoRefreshInterval) {
|
||||||
|
clearInterval(playlistAutoRefreshInterval);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refresh every 5 seconds when on playlists tab
|
||||||
|
playlistAutoRefreshInterval = setInterval(() => {
|
||||||
|
const playlistsTab = document.getElementById('tab-playlists');
|
||||||
|
if (playlistsTab && playlistsTab.classList.contains('active')) {
|
||||||
|
// Silently refresh without showing loading state
|
||||||
|
fetchPlaylists(true);
|
||||||
|
}
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopPlaylistAutoRefresh() {
|
||||||
|
if (playlistAutoRefreshInterval) {
|
||||||
|
clearInterval(playlistAutoRefreshInterval);
|
||||||
|
playlistAutoRefreshInterval = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Toast notification
|
// Toast notification
|
||||||
function showToast(message, type = 'success', duration = 3000) {
|
function showToast(message, type = 'success', duration = 3000) {
|
||||||
const toast = document.createElement('div');
|
const toast = document.createElement('div');
|
||||||
@@ -1343,7 +1372,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchPlaylists() {
|
async function fetchPlaylists(silent = false) {
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/admin/playlists');
|
const res = await fetch('/api/admin/playlists');
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -1351,7 +1380,9 @@
|
|||||||
const tbody = document.getElementById('playlist-table-body');
|
const tbody = document.getElementById('playlist-table-body');
|
||||||
|
|
||||||
if (data.playlists.length === 0) {
|
if (data.playlists.length === 0) {
|
||||||
|
if (!silent) {
|
||||||
tbody.innerHTML = '<tr><td colspan="7" style="text-align:center;color:var(--text-secondary);padding:40px;">No playlists configured. Link playlists from the Jellyfin Playlists tab.</td></tr>';
|
tbody.innerHTML = '<tr><td colspan="7" style="text-align:center;color:var(--text-secondary);padding:40px;">No playlists configured. Link playlists from the Jellyfin Playlists tab.</td></tr>';
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user