feat: combine upload and Openverse into one import page
Adding music took two navigation items that each did half the job. The new Import page has both sources as tabs and one shared list of what was added in this session, with the reason for every failure and a link to the library. From computer: drop several MP3 or WAV files or pick them with a multi-select dialog. Files are imported one by one on a background thread with a progress bar, and a failing file does not stop the rest. Openverse: search and download show a progress ring with a status text. Results that are already in the library or have no duration are marked in their row and cannot be imported; a double-click imports. To detect duplicates, songs now store the Openverse result id. The repository adds the column to existing databases and a unique index keeps one song per Openverse result. Refs #13 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a762a2f571
commit
0a0d8e1d4c
17 files changed
+582
-266
No files matched your search
@@ -9,7 +9,7 @@ public class SongRepository
|
||||
public static string DefaultDatabasePath { get; } = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Radiosender", "radiosender.db");
|
||||
|
||||
private const string Columns = "Id, Title, Artist, DurationMs, FilePath, Source, License, Attribution";
|
||||
private const string Columns = "Id, Title, Artist, DurationMs, FilePath, Source, License, Attribution, OpenverseId";
|
||||
|
||||
private readonly string _connectionString;
|
||||
|
||||
@@ -29,10 +29,36 @@ public class SongRepository
|
||||
FilePath TEXT NOT NULL,
|
||||
Source INTEGER NOT NULL,
|
||||
License TEXT,
|
||||
Attribution TEXT
|
||||
Attribution TEXT,
|
||||
OpenverseId TEXT
|
||||
)
|
||||
""";
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
// Databases from before the Openverse id get the column added.
|
||||
command.CommandText = "SELECT COUNT(*) FROM pragma_table_info('Songs') WHERE name = 'OpenverseId'";
|
||||
if ((long)command.ExecuteScalar()! == 0)
|
||||
{
|
||||
command.CommandText = "ALTER TABLE Songs ADD COLUMN OpenverseId TEXT";
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
// One song per Openverse result, also if two imports of the same track race.
|
||||
command.CommandText = "CREATE UNIQUE INDEX IF NOT EXISTS IX_Songs_OpenverseId ON Songs (OpenverseId) WHERE OpenverseId IS NOT NULL";
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
/// <summary>Ids of all Openverse results that are already in the library.</summary>
|
||||
public IReadOnlySet<string> GetOpenverseIds()
|
||||
{
|
||||
using var connection = Open();
|
||||
using var command = connection.CreateCommand();
|
||||
command.CommandText = "SELECT OpenverseId FROM Songs WHERE OpenverseId IS NOT NULL";
|
||||
using var reader = command.ExecuteReader();
|
||||
var ids = new HashSet<string>();
|
||||
while (reader.Read())
|
||||
ids.Add(reader.GetString(0));
|
||||
return ids;
|
||||
}
|
||||
|
||||
public IReadOnlyList<Song> GetAll()
|
||||
@@ -63,8 +89,8 @@ public class SongRepository
|
||||
using var connection = Open();
|
||||
using var command = connection.CreateCommand();
|
||||
command.CommandText = """
|
||||
INSERT INTO Songs (Title, Artist, DurationMs, FilePath, Source, License, Attribution)
|
||||
VALUES ($title, $artist, $durationMs, $filePath, $source, $license, $attribution);
|
||||
INSERT INTO Songs (Title, Artist, DurationMs, FilePath, Source, License, Attribution, OpenverseId)
|
||||
VALUES ($title, $artist, $durationMs, $filePath, $source, $license, $attribution, $openverseId);
|
||||
SELECT last_insert_rowid();
|
||||
""";
|
||||
AddParameters(command, song);
|
||||
@@ -112,6 +138,7 @@ public class SongRepository
|
||||
command.Parameters.AddWithValue("$source", (int)song.Source);
|
||||
command.Parameters.AddWithValue("$license", (object?)song.License ?? DBNull.Value);
|
||||
command.Parameters.AddWithValue("$attribution", (object?)song.Attribution ?? DBNull.Value);
|
||||
command.Parameters.AddWithValue("$openverseId", (object?)song.OpenverseId ?? DBNull.Value);
|
||||
}
|
||||
|
||||
private static Song Read(SqliteDataReader reader) => new()
|
||||
@@ -124,5 +151,6 @@ public class SongRepository
|
||||
Source = (SongSource)reader.GetInt32(5),
|
||||
License = reader.IsDBNull(6) ? null : reader.GetString(6),
|
||||
Attribution = reader.IsDBNull(7) ? null : reader.GetString(7),
|
||||
OpenverseId = reader.IsDBNull(8) ? null : reader.GetString(8),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user