Auf Wunsch von Dustin: seine beste Freundin sortiert ihre Sammlung ueber das Album-Feld. In Melo ist der Album-Titel deshalb ab jetzt die Kategorie — sie muss nichts neu machen. 1) Album = Kategorie - kategorienAusTags(): Album-Titel steht VORN in der Kategorienliste (die erste Kategorie bestimmt das Coverbild), Genres dahinter. - Beide Scans (android_scan + scan_service) tragen ihn ein; von Hand gepflegte Kategorien (categoriesEdited) bleiben unberuehrt. - DB-Schema 9: einmalige Nachruestung bestehender Bibliotheken, damit das nicht erst beim naechsten vollstaendigen Scan sichtbar wird (der auf Android nur laeuft, wenn sich die Dateianzahl aendert). 2) Reiter: 'Songs/Kuenstler/Alben' -> 'Lieder/Kategorie/Kuenstler' - Neu: library/category_list.dart mit groupByCategory(); Lieder ohne Kategorie sammeln sich am Ende unter "Ohne Kategorie". - Entfernt: library/album_list.dart, groupByAlbum(), albumArtistLabel() — mit dem Alben-Reiter tot geworden. Das Album-FELD bleibt erhalten. 3) YouTube-Downloads ohne Original-Album - Feld "Kategorie (optional)" im YouTube-Bereich, mit Vorschlaegen aus der Bibliothek und freier Eingabe. - ordneDownloadEin() verwirft nach dem Scan das Album-Tag (yt-dlp leitet es aus Kanal/Playlist ab — als Kategorie waere das Unsinn) und setzt stattdessen die gewaehlte Kategorie. Beides als "von Hand gesetzt" markiert, damit der naechste Scan es nicht zurueckholt. - MeloDb.songByPath() und MeloDb.verwirfAlbum() neu. - CategoryService.alleNamen: Kategorienamen ohne zusaetzliche Abfrage — ohne das flackerte die Vorschlagsliste und im Widget-Test blieb ein Aufraeum-Timer von drift haengen. 295 Tests gruen (19 neue, 1 uebersprungen), flutter analyze ohne Befund. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FpPu4nuKjKKeX1RpdDeX81
99 lines
3.2 KiB
Dart
99 lines
3.2 KiB
Dart
import 'package:drift/drift.dart' show Value;
|
|
import 'package:drift/native.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:melo/downloads/download_einordnung.dart';
|
|
import 'package:melo/library/database.dart';
|
|
|
|
const _pfad = '/storage/emulated/0/Music/Melo/Neues Lied.mp3';
|
|
|
|
Future<MeloDb> _dbMitDownload({String? album}) async {
|
|
final db = MeloDb(NativeDatabase.memory());
|
|
await db.upsertSongs([
|
|
SongsCompanion.insert(
|
|
id: 'yt-1',
|
|
path: _pfad,
|
|
title: 'Neues Lied',
|
|
album: Value(album),
|
|
dateAddedMs: 0,
|
|
updatedAtMs: 0,
|
|
),
|
|
]);
|
|
// So sieht es nach dem Scan aus: das Album-Tag von YouTube ist bereits
|
|
// als Kategorie gelandet.
|
|
if (album != null) await db.setCategories('yt-1', [album]);
|
|
return db;
|
|
}
|
|
|
|
void main() {
|
|
group('ordneDownloadEin', () {
|
|
test('das Album-Tag von YouTube wird verworfen', () async {
|
|
final db = await _dbMitDownload(album: 'Topic - Various Artists');
|
|
addTearDown(db.close);
|
|
|
|
await ordneDownloadEin(db, _pfad, 'Nightcore');
|
|
|
|
final song = (await db.allSongs()).single;
|
|
expect(song.album, isNull);
|
|
expect(await db.categoriesOf('yt-1'), ['Nightcore']);
|
|
});
|
|
|
|
test('die gewählte Kategorie überlebt den nächsten Scan', () async {
|
|
final db = await _dbMitDownload(album: 'Topic - Various Artists');
|
|
addTearDown(db.close);
|
|
|
|
await ordneDownloadEin(db, _pfad, 'Nightcore');
|
|
|
|
final song = (await db.allSongs()).single;
|
|
expect(song.metadataEdited, isTrue, reason: 'Album bleibt verworfen');
|
|
expect(song.categoriesEdited, isTrue, reason: 'Kategorie bleibt stehen');
|
|
});
|
|
|
|
test('ohne Angabe bleibt der Titel bewusst ohne Kategorie', () async {
|
|
final db = await _dbMitDownload(album: 'Topic - Various Artists');
|
|
addTearDown(db.close);
|
|
|
|
await ordneDownloadEin(db, _pfad, ' ');
|
|
|
|
expect(await db.categoriesOf('yt-1'), isEmpty);
|
|
expect((await db.allSongs()).single.album, isNull);
|
|
});
|
|
|
|
test('umgebende Leerzeichen zählen nicht zum Namen', () async {
|
|
final db = await _dbMitDownload();
|
|
addTearDown(db.close);
|
|
|
|
await ordneDownloadEin(db, _pfad, ' Nightcore ');
|
|
|
|
expect(await db.categoriesOf('yt-1'), ['Nightcore']);
|
|
});
|
|
|
|
test('ein unbekannter Pfad ändert nichts', () async {
|
|
final db = await _dbMitDownload(album: 'Bleibt');
|
|
addTearDown(db.close);
|
|
|
|
await ordneDownloadEin(db, '/gibt/es/nicht.mp3', 'Nightcore');
|
|
|
|
expect((await db.allSongs()).single.album, 'Bleibt');
|
|
expect(await db.categoriesOf('yt-1'), ['Bleibt']);
|
|
});
|
|
});
|
|
|
|
group('kategorieVorschlaege', () {
|
|
const vorhanden = ['Nightcore', 'Schwarz', 'Rock Classics'];
|
|
|
|
test('leere Eingabe zeigt alles', () {
|
|
expect(kategorieVorschlaege('', vorhanden), vorhanden);
|
|
});
|
|
|
|
test('filtert nach Teiltreffer, unabhängig von Groß-/Kleinschreibung', () {
|
|
expect(kategorieVorschlaege('night', vorhanden), ['Nightcore']);
|
|
expect(kategorieVorschlaege('ROCK', vorhanden), ['Rock Classics']);
|
|
});
|
|
|
|
test('ohne Treffer bleibt die Liste leer — die Eingabe wird neue '
|
|
'Kategorie', () {
|
|
expect(kategorieVorschlaege('Gibtsnicht', vorhanden), isEmpty);
|
|
});
|
|
});
|
|
}
|