mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
logic fix 2
This commit is contained in:
@@ -117,6 +117,11 @@ builder.Services.Configure<SpotifyImportSettings>(options =>
|
|||||||
{
|
{
|
||||||
builder.Configuration.GetSection("SpotifyImport").Bind(options);
|
builder.Configuration.GetSection("SpotifyImport").Bind(options);
|
||||||
|
|
||||||
|
// Debug: Check what Bind() populated
|
||||||
|
Console.WriteLine($"DEBUG: After Bind(), Playlists.Count = {options.Playlists.Count}");
|
||||||
|
Console.WriteLine($"DEBUG: After Bind(), PlaylistIds.Count = {options.PlaylistIds.Count}");
|
||||||
|
Console.WriteLine($"DEBUG: After Bind(), PlaylistNames.Count = {options.PlaylistNames.Count}");
|
||||||
|
|
||||||
// Parse SPOTIFY_IMPORT_PLAYLISTS env var (JSON array format)
|
// Parse SPOTIFY_IMPORT_PLAYLISTS env var (JSON array format)
|
||||||
// Format: [["Name","Id","first|last"],["Name2","Id2","first|last"]]
|
// Format: [["Name","Id","first|last"],["Name2","Id2","first|last"]]
|
||||||
var playlistsEnv = builder.Configuration.GetValue<string>("SpotifyImport:Playlists");
|
var playlistsEnv = builder.Configuration.GetValue<string>("SpotifyImport:Playlists");
|
||||||
@@ -167,7 +172,12 @@ builder.Services.Configure<SpotifyImportSettings>(options =>
|
|||||||
|
|
||||||
// Legacy support: Parse old SPOTIFY_IMPORT_PLAYLIST_IDS/NAMES env vars
|
// Legacy support: Parse old SPOTIFY_IMPORT_PLAYLIST_IDS/NAMES env vars
|
||||||
// Only used if new Playlists format is not configured
|
// Only used if new Playlists format is not configured
|
||||||
if (options.Playlists.Count == 0)
|
// Check if we have legacy env vars to parse
|
||||||
|
var playlistIdsEnv = builder.Configuration.GetValue<string>("SpotifyImport:PlaylistIds");
|
||||||
|
var playlistNamesEnv = builder.Configuration.GetValue<string>("SpotifyImport:PlaylistNames");
|
||||||
|
var hasLegacyConfig = !string.IsNullOrWhiteSpace(playlistIdsEnv) || !string.IsNullOrWhiteSpace(playlistNamesEnv);
|
||||||
|
|
||||||
|
if (hasLegacyConfig && options.Playlists.Count == 0)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Parsing legacy Spotify playlist format...");
|
Console.WriteLine("Parsing legacy Spotify playlist format...");
|
||||||
|
|
||||||
@@ -179,7 +189,6 @@ builder.Services.Configure<SpotifyImportSettings>(options =>
|
|||||||
options.PlaylistNames.Clear();
|
options.PlaylistNames.Clear();
|
||||||
options.PlaylistLocalTracksPositions.Clear();
|
options.PlaylistLocalTracksPositions.Clear();
|
||||||
|
|
||||||
var playlistIdsEnv = builder.Configuration.GetValue<string>("SpotifyImport:PlaylistIds");
|
|
||||||
if (!string.IsNullOrWhiteSpace(playlistIdsEnv))
|
if (!string.IsNullOrWhiteSpace(playlistIdsEnv))
|
||||||
{
|
{
|
||||||
options.PlaylistIds = playlistIdsEnv
|
options.PlaylistIds = playlistIdsEnv
|
||||||
@@ -190,7 +199,82 @@ builder.Services.Configure<SpotifyImportSettings>(options =>
|
|||||||
Console.WriteLine($" Parsed {options.PlaylistIds.Count} playlist IDs from env var");
|
Console.WriteLine($" Parsed {options.PlaylistIds.Count} playlist IDs from env var");
|
||||||
}
|
}
|
||||||
|
|
||||||
var playlistNamesEnv = builder.Configuration.GetValue<string>("SpotifyImport:PlaylistNames");
|
if (!string.IsNullOrWhiteSpace(playlistNamesEnv))
|
||||||
|
{
|
||||||
|
options.PlaylistNames = playlistNamesEnv
|
||||||
|
.Split(',', StringSplitOptions.RemoveEmptyEntries)
|
||||||
|
.Select(name => name.Trim())
|
||||||
|
.Where(name => !string.IsNullOrEmpty(name))
|
||||||
|
.ToList();
|
||||||
|
Console.WriteLine($" Parsed {options.PlaylistNames.Count} playlist names from env var");
|
||||||
|
}
|
||||||
|
|
||||||
|
var playlistPositionsEnv = builder.Configuration.GetValue<string>("SpotifyImport:PlaylistLocalTracksPositions");
|
||||||
|
if (!string.IsNullOrWhiteSpace(playlistPositionsEnv))
|
||||||
|
{
|
||||||
|
options.PlaylistLocalTracksPositions = playlistPositionsEnv
|
||||||
|
.Split(',', StringSplitOptions.RemoveEmptyEntries)
|
||||||
|
.Select(pos => pos.Trim())
|
||||||
|
.Where(pos => !string.IsNullOrEmpty(pos))
|
||||||
|
.ToList();
|
||||||
|
Console.WriteLine($" Parsed {options.PlaylistLocalTracksPositions.Count} playlist positions from env var");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine(" No playlist positions env var found, will use defaults");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert legacy format to new Playlists array
|
||||||
|
Console.WriteLine($" Converting {options.PlaylistIds.Count} playlists to new format...");
|
||||||
|
for (int i = 0; i < options.PlaylistIds.Count; i++)
|
||||||
|
{
|
||||||
|
var name = i < options.PlaylistNames.Count ? options.PlaylistNames[i] : options.PlaylistIds[i];
|
||||||
|
var position = LocalTracksPosition.First; // Default
|
||||||
|
|
||||||
|
// Parse position if provided
|
||||||
|
if (i < options.PlaylistLocalTracksPositions.Count)
|
||||||
|
{
|
||||||
|
var posStr = options.PlaylistLocalTracksPositions[i];
|
||||||
|
if (posStr.Equals("last", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
position = LocalTracksPosition.Last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
options.Playlists.Add(new SpotifyPlaylistConfig
|
||||||
|
{
|
||||||
|
Name = name,
|
||||||
|
Id = options.PlaylistIds[i],
|
||||||
|
LocalTracksPosition = position
|
||||||
|
});
|
||||||
|
Console.WriteLine($" [{i}] {name} (ID: {options.PlaylistIds[i]}, Position: {position})");
|
||||||
|
}
|
||||||
|
#pragma warning restore CS0618
|
||||||
|
}
|
||||||
|
else if (hasLegacyConfig && options.Playlists.Count > 0)
|
||||||
|
{
|
||||||
|
// Bind() incorrectly populated Playlists from legacy env vars
|
||||||
|
// Clear it and re-parse properly
|
||||||
|
Console.WriteLine($"DEBUG: Bind() incorrectly populated {options.Playlists.Count} playlists, clearing and re-parsing...");
|
||||||
|
options.Playlists.Clear();
|
||||||
|
options.PlaylistIds.Clear();
|
||||||
|
options.PlaylistNames.Clear();
|
||||||
|
options.PlaylistLocalTracksPositions.Clear();
|
||||||
|
|
||||||
|
Console.WriteLine("Parsing legacy Spotify playlist format...");
|
||||||
|
|
||||||
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(playlistIdsEnv))
|
||||||
|
{
|
||||||
|
options.PlaylistIds = playlistIdsEnv
|
||||||
|
.Split(',', StringSplitOptions.RemoveEmptyEntries)
|
||||||
|
.Select(id => id.Trim())
|
||||||
|
.Where(id => !string.IsNullOrEmpty(id))
|
||||||
|
.ToList();
|
||||||
|
Console.WriteLine($" Parsed {options.PlaylistIds.Count} playlist IDs from env var");
|
||||||
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(playlistNamesEnv))
|
if (!string.IsNullOrWhiteSpace(playlistNamesEnv))
|
||||||
{
|
{
|
||||||
options.PlaylistNames = playlistNamesEnv
|
options.PlaylistNames = playlistNamesEnv
|
||||||
|
|||||||
Reference in New Issue
Block a user