diff --git a/allstarr/Controllers/AdminController.cs b/allstarr/Controllers/AdminController.cs index 6343cac..1cbf8b9 100644 --- a/allstarr/Controllers/AdminController.cs +++ b/allstarr/Controllers/AdminController.cs @@ -2891,6 +2891,72 @@ public class AdminController : ControllerBase } } + /// + /// Get all manual track mappings (both Jellyfin and external) for all playlists + /// + [HttpGet("mappings/tracks")] + public async Task GetAllTrackMappings() + { + try + { + var mappingsDir = "/app/cache/mappings"; + var allMappings = new List(); + + if (!Directory.Exists(mappingsDir)) + { + return Ok(new { mappings = allMappings, totalCount = 0 }); + } + + var files = Directory.GetFiles(mappingsDir, "*_mappings.json"); + + foreach (var file in files) + { + try + { + var json = await System.IO.File.ReadAllTextAsync(file); + var playlistMappings = JsonSerializer.Deserialize>(json); + + if (playlistMappings != null) + { + var fileName = Path.GetFileNameWithoutExtension(file); + var playlistName = fileName.Replace("_mappings", "").Replace("_", " "); + + foreach (var mapping in playlistMappings.Values) + { + allMappings.Add(new + { + playlist = playlistName, + spotifyId = mapping.SpotifyId, + type = !string.IsNullOrEmpty(mapping.JellyfinId) ? "jellyfin" : "external", + jellyfinId = mapping.JellyfinId, + externalProvider = mapping.ExternalProvider, + externalId = mapping.ExternalId, + createdAt = mapping.CreatedAt + }); + } + } + } + catch (Exception ex) + { + _logger.LogWarning(ex, "Failed to read mapping file {File}", file); + } + } + + return Ok(new + { + mappings = allMappings.OrderBy(m => ((dynamic)m).playlist).ThenBy(m => ((dynamic)m).createdAt), + totalCount = allMappings.Count, + jellyfinCount = allMappings.Count(m => ((dynamic)m).type == "jellyfin"), + externalCount = allMappings.Count(m => ((dynamic)m).type == "external") + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Failed to get track mappings"); + return StatusCode(500, new { error = "Failed to get track mappings" }); + } + } + /// /// Test Spotify lyrics API by fetching lyrics for a specific Spotify track ID /// Example: GET /api/admin/lyrics/spotify/test?trackId=3yII7UwgLF6K5zW3xad3MP