*исправлена запись новых тегов и apic

This commit is contained in:
K1ndWha1e committed 2026-09-26 00:13:48 +03:00
1 parent abab08f133
commit c06ef69c67
3 files changed
+63 -41

No files matched your search

+43 -2
View File
@@ -49,10 +49,17 @@ pub fn dump_data[T](mut tag T, mut audio os.File) {
// Получаем вне возможные байты
all_tag_bytes := get_bytes(mut audio, 10, int(tag.size + start_position))
for tag.size > start_position {
// Конец тэга с учётом 10 байт заголовка
tag_end := tag.size + 10
for start_position + 10 <= tag_end {
// Нулевой байт вместо названия фрейма — начался запас нулей
if all_tag_bytes[start_position] == 0 {
break
}
current_frame.fill(all_tag_bytes, start_position, tag.version)
start_position = current_frame.end
tag.size -= current_frame.cur_size
tag.add_frame(current_frame)
}
@@ -95,3 +102,37 @@ pub fn encode_header[T](mut id3v T) {
id3v.encoded_header << metadata.encode_header_size(id3v.size, id3v.version)
}
// Количество нулей в конце тэга
const tag_padding = 256
type ID3vType = ID3v23 | ID3v24
// Формируем полный полный тэг в байтах
pub fn get_full_embed_tag[ID3vType](mut id3v2 ID3vType) {
// Проход по всем полям стуктуры
mut tag_bytes := []u8{}
$for field in id3v2.fields {
$if field.typ is Frame {
// Читаются только заполненные тэги
if id3v2.$(field.name).cur_size > 0 {
if id3v2.$(field.name).name.to_lower() != "apic" {
// Кодируем значения полей
tag_bytes << id3v2.$(field.name).get_encoded_frame_tag(id3v2.version)
} else {
// Картинка не трогается
tag_bytes << id3v2.$(field.name).apic or { []u8{} }
}
}
}
}
// Запас нулей чтобы не пересчитывать весь тэг при маленьком редактировании
tag_bytes << []u8{len: tag_padding}
// Размер считается по уже закодированным фреймам
id3v2.size = u64(tag_bytes.len)
id3v2.encoded_header = []u8{}
encode_header(mut id3v2)
id3v2.encoded_header << tag_bytes
}