*многое сделано, не помню что
This commit is contained in:
1 parent
fdc72ae653
commit
abab08f133
8 files changed
+249
-85
No files matched your search
+37
-6
@@ -27,7 +27,7 @@ pub fn (mut audio Audio) detect_tags(mut data os.File) {
|
||||
}
|
||||
|
||||
pub fn get_bytes(mut audio os.File, position int, size int) []u8 {
|
||||
// ? ---------Работа с расположением указателя--------------
|
||||
// > ---------Работа с расположением указателя--------------
|
||||
// Ставим указатель на 128 байт с конца
|
||||
if position < 0 {
|
||||
audio.seek(position, os.SeekMode.end) or { panic(err) }
|
||||
@@ -42,7 +42,7 @@ pub fn get_bytes(mut audio os.File, position int, size int) []u8 {
|
||||
return last_bytes
|
||||
}
|
||||
|
||||
pub fn fill_tag[T](mut tag T, mut audio os.File) {
|
||||
pub fn dump_data[T](mut tag T, mut audio os.File) {
|
||||
mut current_frame := &Frame{}
|
||||
// Самая первая позиция
|
||||
mut start_position := u64(10)
|
||||
@@ -50,17 +50,48 @@ pub fn fill_tag[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 {
|
||||
current_frame.fill_frame(all_tag_bytes, start_position, tag.version)
|
||||
current_frame.fill(all_tag_bytes, start_position, tag.version)
|
||||
start_position = current_frame.end
|
||||
tag.size -= current_frame.size
|
||||
tag.size -= current_frame.cur_size
|
||||
|
||||
tag.add_frame(current_frame)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_full_size[T](mut tag T, mut audio os.File) {
|
||||
pub fn get_current_tag_size[T](mut tag T, mut audio os.File) {
|
||||
// Первые 10 байт тэга
|
||||
first_ten_bytes := get_bytes(mut audio, 0, 10)
|
||||
|
||||
tag.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 encode_header_size(size u64, idv3_version u8) []u8 {
|
||||
stride := if idv3_version == 3 {
|
||||
[u64(24), u64(16), u64(8), u64(0xFF)]
|
||||
} else {
|
||||
[u64(21), u64(14), u64(7), u64(0x7F)]
|
||||
}
|
||||
|
||||
mut encoded_size := []u8{len: 4}
|
||||
encoded_size[0] = u8((size >> stride[0]) & stride[3])
|
||||
encoded_size[1] = u8((size >> stride[1]) & stride[3])
|
||||
encoded_size[2] = u8((size >> stride[2]) & stride[3])
|
||||
encoded_size[3] = u8(size & stride[3])
|
||||
|
||||
return encoded_size
|
||||
|
||||
}
|
||||
|
||||
// Кодирование первых 10 байт ID3
|
||||
pub fn encode_header[T](mut id3v T) {
|
||||
// Байты для символов "ID3"
|
||||
id3v.encoded_header << [u8(73), u8(68), u8(51)]
|
||||
// Версия IDv3
|
||||
id3v.encoded_header << [id3v.version]
|
||||
// Минорная версия и спец. флаги
|
||||
id3v.encoded_header << []u8{len: 2}
|
||||
|
||||
id3v.encoded_header << metadata.encode_header_size(id3v.size, id3v.version)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user