Files
id3_editor/metadata/id3v2.3.v
T
2026-07-11 20:46:19 +03:00

114 lines
2.6 KiB
V
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
module metadata
import os { File }
// 00: ISO-8859-1 (1 байт на символ).
// 01: UTF-16 с BOM (2 байта на символ + 2 байта маркер).
// 03: UTF-8 (переменная длина).
// Пример из пункта 3 (13 байт размера):
// Если первый байт данных 01 (UTF-16), то реальный текст занимает:
// 13 - 1 (байт кодировки) - 2 (BOM) = 10 байт.
// В UTF-16 это будет всего 5 символов (так как 1 символ = 2 байта).
enum EnumID3v23 as u8 {
tit2
tpe1
tpe2
talb
tyer
trck
tcon
tcop
apic
comment
unknown
}
const start_idx = 10
pub fn (mut tag ID3v23) add_frame(frame Frame) {
name := EnumID3v23.from(frame.name.to_lower()) or { EnumID3v23.unknown }
match name {
.tit2 {
tag.tit2 = frame
}
.tpe1 {
tag.tpe1 = frame
}
.tpe2 {
tag.tpe2 = frame
}
.talb {
tag.talb = frame
}
.tyer {
tag.tyer = frame
}
.trck {
tag.trck = frame
}
.tcon {
tag.tcon = frame
}
.tcop {
tag.tcop = frame
}
.apic {
tag.apic = frame
}
else {
tag.others << frame
}
}
}
// [ID3v23] Получение размера всего тэга / фрейма
@[inline]
fn get_size_v23(size_bytes []u8) u64 {
return (u64(size_bytes[0]) << 24) | (u64(size_bytes[1]) << 16) | (u64(size_bytes[2]) << 8) | u64(size_bytes[3])
}
pub fn (mut id3v23 ID3v23) get_full_size(mut audio File) {
// Первые 10 байт тэга
first_ten_bytes := get_bytes(mut audio, 0, 10)
id3v23.size = (u64(first_ten_bytes[6]) << 21) | (u64(first_ten_bytes[7]) << 14) | (u64(first_ten_bytes[8]) << 7) | u64(first_ten_bytes[9])
}
pub fn (mut id3v23 ID3v23) fill_tag(mut audio File) {
mut current_frame := &Frame{}
// Самая первая позиция
mut start_position := u64(10)
// Версия IDv3
idv3_version := u8(3)
// Получаем вне возможные байты
all_tag_bytes := get_bytes(mut audio, 10, int(id3v23.size + start_position))
for id3v23.size > start_position {
current_frame.fill_frame(all_tag_bytes, start_position, idv3_version)
start_position = current_frame.end
id3v23.size -= current_frame.size
id3v23.add_frame(current_frame)
}
}
// Конвертировать ID3 v2.3 в ID3 v1
pub fn (id3v23 ID3v23) to_v1() ID3v1 {
return ID3v1{
genre: id3v23.tcon.text
title: id3v23.tit2.text
artist: id3v23.tpe2.text
album: id3v23.talb.text
track: id3v23.trck.text.split("/")[0]
year: id3v23.tyer.text
comment: id3v23.comment.text
}
}
pub fn to_bytes () {
}