*чтение: пустые или испорченные («�») название, альбом и автор в ID3v2 берутся из ID3v1 (старые файлы хранят там cp1251)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
K1ndWha1eandClaude Opus 5.5 committed 2026-10-09 21:58:08 +03:00
1 parent a3e244205a
commit a76bbe18f1
2 files changed
+46

No files matched your search

+19
View File
@@ -348,11 +348,30 @@ fn read_book_tags_impl(path string) !FileTags {
if t.series == '' {
t.series = tit1
}
// Пустые или испорченные («�») поля — из ID3v1: старые файлы часто хранят там исходный текст в cp1251,
// а в ID3v2 он мог попасть уже испорченным (прочитан не в той кодировке и записан обратно)
if needs_v1(t.title) || needs_v1(t.album) || needs_v1(t.author) {
if v1 := read_v1(path) {
if needs_v1(t.title) && !needs_v1(v1.title) {
t.title = v1.title
}
if needs_v1(t.album) && !needs_v1(v1.album) {
t.album = v1.album
}
if needs_v1(t.author) && !needs_v1(v1.author) {
t.author = v1.author
}
}
}
// TPE1 мог быть не задан, тогда автор остаётся из TPE2
res.tags = t
return res
}
fn needs_v1(s string) bool {
return s.trim_space() == '' || s.contains('\uFFFD')
}
// "(101)" и "(101)Speech" из старых тэгов превращаем в название
fn clean_genre(g string) string {
if g.starts_with('(') && g.contains(')') {