mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
Add legacy Spotify playlist format support with position control
This commit is contained in:
@@ -120,14 +120,16 @@ builder.Services.Configure<SpotifyImportSettings>(options =>
|
||||
// Parse SPOTIFY_IMPORT_PLAYLISTS env var (JSON array format)
|
||||
// Format: [["Name","Id","first|last"],["Name2","Id2","first|last"]]
|
||||
var playlistsEnv = builder.Configuration.GetValue<string>("SpotifyImport:Playlists");
|
||||
if (!string.IsNullOrWhiteSpace(playlistsEnv) && options.Playlists.Count == 0)
|
||||
if (!string.IsNullOrWhiteSpace(playlistsEnv))
|
||||
{
|
||||
Console.WriteLine($"Found SPOTIFY_IMPORT_PLAYLISTS env var: {playlistsEnv.Length} chars");
|
||||
try
|
||||
{
|
||||
// Parse as JSON array of arrays
|
||||
var playlistArrays = System.Text.Json.JsonSerializer.Deserialize<string[][]>(playlistsEnv);
|
||||
if (playlistArrays != null)
|
||||
if (playlistArrays != null && playlistArrays.Length > 0)
|
||||
{
|
||||
Console.WriteLine($"Parsed {playlistArrays.Length} playlists from JSON format");
|
||||
foreach (var arr in playlistArrays)
|
||||
{
|
||||
if (arr.Length >= 2)
|
||||
@@ -142,16 +144,26 @@ builder.Services.Configure<SpotifyImportSettings>(options =>
|
||||
: LocalTracksPosition.First
|
||||
};
|
||||
options.Playlists.Add(config);
|
||||
Console.WriteLine($" Added: {config.Name} (ID: {config.Id}, Position: {config.LocalTracksPosition})");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("JSON format was empty or invalid, will try legacy format");
|
||||
}
|
||||
}
|
||||
catch (System.Text.Json.JsonException ex)
|
||||
{
|
||||
Console.WriteLine($"Warning: Failed to parse SPOTIFY_IMPORT_PLAYLISTS: {ex.Message}");
|
||||
Console.WriteLine("Expected format: [[\"Name\",\"Id\",\"first|last\"],[\"Name2\",\"Id2\",\"first|last\"]]");
|
||||
Console.WriteLine("Will try legacy format instead");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("No SPOTIFY_IMPORT_PLAYLISTS env var found, will try legacy format");
|
||||
}
|
||||
|
||||
// Legacy support: Parse old SPOTIFY_IMPORT_PLAYLIST_IDS/NAMES env vars
|
||||
// Only used if new Playlists format is not configured
|
||||
|
||||
Reference in New Issue
Block a user