fix: code-review #2 — dedup MagicBytes, auth für check_corrupted, UI-Flag, merged player streams, jq-JSON
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:path_provider/path_provider.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import '../models/song.dart';
|
||||
import '../database/db_helper.dart';
|
||||
import '../utils/audio_validator.dart';
|
||||
import 'id3_reader.dart';
|
||||
import 'melo_logger.dart';
|
||||
|
||||
@@ -52,7 +53,7 @@ class MusikScanner {
|
||||
final tags = Id3Reader.lesen(pfad);
|
||||
|
||||
// ── Magic-Byte-Prüfung ──
|
||||
final istKorrupt = !_hatValideMagicBytes(pfad);
|
||||
final istKorrupt = !hatValideMagicBytes(file);
|
||||
if (istKorrupt) {
|
||||
MeloLogger().fehler('magic_bytes_scan', 'Ungültiger Audio-Header: $pfad');
|
||||
}
|
||||
@@ -192,37 +193,6 @@ class MusikScanner {
|
||||
}
|
||||
}
|
||||
|
||||
static bool _hatValideMagicBytes(String pfad) {
|
||||
try {
|
||||
final file = File(pfad);
|
||||
if (!file.existsSync()) return false;
|
||||
final bytes = file.readAsBytesSync().take(16).toList();
|
||||
if (bytes.length < 4) return false;
|
||||
|
||||
// ID3v2 Tag (MP3) — 49 44 33
|
||||
if (bytes[0] == 0x49 && bytes[1] == 0x44 && bytes[2] == 0x33) return true;
|
||||
// MPEG Audio Frame Sync
|
||||
if (bytes[0] == 0xFF && (bytes[1] & 0xFE) == 0xFA) return true;
|
||||
if (bytes[0] == 0xFF && (bytes[1] == 0xF3 || bytes[1] == 0xF2)) return true;
|
||||
// M4A/AAC
|
||||
if (bytes.length >= 8 && bytes[4] == 0x66 && bytes[5] == 0x74 &&
|
||||
bytes[6] == 0x79 && bytes[7] == 0x70) return true;
|
||||
// FLAC
|
||||
if (bytes[0] == 0x66 && bytes[1] == 0x4C &&
|
||||
bytes[2] == 0x61 && bytes[3] == 0x43) return true;
|
||||
// WAV
|
||||
if (bytes[0] == 0x52 && bytes[1] == 0x49 &&
|
||||
bytes[2] == 0x46 && bytes[3] == 0x46) { return true; }
|
||||
// OGG
|
||||
if (bytes[0] == 0x4F && bytes[1] == 0x67 &&
|
||||
bytes[2] == 0x67 && bytes[3] == 0x53) { return true; }
|
||||
|
||||
return false;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
String _dateiNameOhneEndung(String pfad) {
|
||||
final name = pfad.split('/').last;
|
||||
final dot = name.lastIndexOf('.');
|
||||
|
||||
Reference in New Issue
Block a user