pub struct ID3Parser<T>{
pub pheader: ProtocolHeader,
pub eheader: ExtendedHeader,
pub padding_size: u32,
pub footer: Footer,
pub id3v1: ID3v1,
/* private fields */
}Fields§
§pheader: ProtocolHeaderprotocol header
eheader: ExtendedHeaderextended header
padding_size: u32sum of extended header (including payload), frames, padding
id3v1: ID3v1ID3v1 tag
Implementations§
Source§impl<T> ID3Parser<T>
impl<T> ID3Parser<T>
Sourcepub fn new(fp: T) -> Result<Self>
pub fn new(fp: T) -> Result<Self>
Create a new parser. 传入一个列表,启动多个线程进行解析:怎么返回值?线程切换成本? 用户启动多个线程,每个线程一个ID3Parser 异步?对已经确定的Buffer
Examples found in repository?
2fn main() -> std::io::Result<()> {
3 // https://drive.google.com/file/d/1fp_TYclIKZAWMwFTnxEEe4PqJCuBqHl4/view?usp=sharing
4 let mut id3_parser = ID3Parser::new("云烟成雨.mp3").unwrap();
5
6 id3_parser.parse_id3v1()?;
7 // The ID3v1 protocol does not specify the content encoding,
8 // which may be UTF-8, GBK or some other encoding,
9 // so it is not possible to decode it, so the bytecode is output directly
10 println!("{}", id3_parser.id3v1);
11
12 id3_parser.parse_id3v2()?;
13 println!("{}", id3_parser.pheader);
14 println!("{}", id3_parser.eheader);
15 println!("{}", id3_parser.footer);
16
17 // The `get` method is case insensitive,
18 // so you're allowed to pass in uppercase or lowercase characters or a mix of upper and lowercase characters,
19 // as is the `get_raw` method
20 println!("TIT2 = {:?}", id3_parser.get("TIT2").unwrap());
21 println!("TALB = {:?}", id3_parser.get("talb").unwrap());
22 println!("TPE1 = {:?}", id3_parser.get("tpe1").unwrap());
23 println!("TPE2 = {:?}", id3_parser.get("tpe2").unwrap());
24 println!("padding size = {}", id3_parser.padding_size);
25
26 // It is not recommended to print the APIC byte sequence because it is really long
27 // println!("APIC_raw = {:?}", parser.get_raw("apic").unwrap());
28
29 // Write filename.jpg to the current directory.
30 // No need to worry about multiple APIC frames in a file being overwritten by the same name.
31 // Naming rules: <filename>_mp3_<picture_type>[_index].jpg
32 id3_parser.write_image()?;
33
34 let mut flac_parser = FlacParser::new("云烟成雨.flac").unwrap();
35 flac_parser.parse()?;
36
37 // https://www.xiph.org/vorbis/doc/v-comment.html
38 // The `get` method is case insensitive
39 println!("artist = {:?}", flac_parser.get("artist").unwrap());
40
41 println!("album = {:?}", flac_parser.get("album").unwrap());
42
43 // Get all vorbis comments in the file
44 let (k, v) = flac_parser.get_all().unwrap();
45 let mut index = 0;
46 while index < k.len() {
47 println!(
48 "vorbis key = {:?}, vorbis comment = {:?}",
49 k[index], v[index]
50 );
51 index += 1;
52 }
53
54 // It is not recommended to print the APIC byte sequence because it is really long
55 // println!("picture_raw_data = {:?}", flac_parser.picture[0].data);
56
57 println!("md5 = {}", flac_parser.stream_info.md5);
58
59 println!(
60 "picture width = {}, picture width = {}, picture type = {:?}",
61 flac_parser.picture[0].width,
62 flac_parser.picture[0].height,
63 flac_parser.picture[0].pic_type
64 );
65
66 // This will write image[s] to disk
67 // Naming rules: <filename>_flac_<picture_type>[_index].jpg
68 flac_parser.write_image()?;
69
70 flac_parser.change_target("千千阙歌.flac");
71
72
73 let mut ogg_parser = OggParser::new("xhh.ogg");
74 ogg_parser.parse()?;
75 println!("ogg_vorbis_comment = {:?}", ogg_parser.get_all());
76 Ok(())
77}Sourcepub fn get(&self, query: &str) -> Option<Vec<String>>
pub fn get(&self, query: &str) -> Option<Vec<String>>
Return frame content that after decoding.
All text information frames should call this method, including TXXX.
This method is case insensitive.
Examples found in repository?
2fn main() -> std::io::Result<()> {
3 // https://drive.google.com/file/d/1fp_TYclIKZAWMwFTnxEEe4PqJCuBqHl4/view?usp=sharing
4 let mut id3_parser = ID3Parser::new("云烟成雨.mp3").unwrap();
5
6 id3_parser.parse_id3v1()?;
7 // The ID3v1 protocol does not specify the content encoding,
8 // which may be UTF-8, GBK or some other encoding,
9 // so it is not possible to decode it, so the bytecode is output directly
10 println!("{}", id3_parser.id3v1);
11
12 id3_parser.parse_id3v2()?;
13 println!("{}", id3_parser.pheader);
14 println!("{}", id3_parser.eheader);
15 println!("{}", id3_parser.footer);
16
17 // The `get` method is case insensitive,
18 // so you're allowed to pass in uppercase or lowercase characters or a mix of upper and lowercase characters,
19 // as is the `get_raw` method
20 println!("TIT2 = {:?}", id3_parser.get("TIT2").unwrap());
21 println!("TALB = {:?}", id3_parser.get("talb").unwrap());
22 println!("TPE1 = {:?}", id3_parser.get("tpe1").unwrap());
23 println!("TPE2 = {:?}", id3_parser.get("tpe2").unwrap());
24 println!("padding size = {}", id3_parser.padding_size);
25
26 // It is not recommended to print the APIC byte sequence because it is really long
27 // println!("APIC_raw = {:?}", parser.get_raw("apic").unwrap());
28
29 // Write filename.jpg to the current directory.
30 // No need to worry about multiple APIC frames in a file being overwritten by the same name.
31 // Naming rules: <filename>_mp3_<picture_type>[_index].jpg
32 id3_parser.write_image()?;
33
34 let mut flac_parser = FlacParser::new("云烟成雨.flac").unwrap();
35 flac_parser.parse()?;
36
37 // https://www.xiph.org/vorbis/doc/v-comment.html
38 // The `get` method is case insensitive
39 println!("artist = {:?}", flac_parser.get("artist").unwrap());
40
41 println!("album = {:?}", flac_parser.get("album").unwrap());
42
43 // Get all vorbis comments in the file
44 let (k, v) = flac_parser.get_all().unwrap();
45 let mut index = 0;
46 while index < k.len() {
47 println!(
48 "vorbis key = {:?}, vorbis comment = {:?}",
49 k[index], v[index]
50 );
51 index += 1;
52 }
53
54 // It is not recommended to print the APIC byte sequence because it is really long
55 // println!("picture_raw_data = {:?}", flac_parser.picture[0].data);
56
57 println!("md5 = {}", flac_parser.stream_info.md5);
58
59 println!(
60 "picture width = {}, picture width = {}, picture type = {:?}",
61 flac_parser.picture[0].width,
62 flac_parser.picture[0].height,
63 flac_parser.picture[0].pic_type
64 );
65
66 // This will write image[s] to disk
67 // Naming rules: <filename>_flac_<picture_type>[_index].jpg
68 flac_parser.write_image()?;
69
70 flac_parser.change_target("千千阙歌.flac");
71
72
73 let mut ogg_parser = OggParser::new("xhh.ogg");
74 ogg_parser.parse()?;
75 println!("ogg_vorbis_comment = {:?}", ogg_parser.get_all());
76 Ok(())
77}Sourcepub fn get_raw(&self, query: &str) -> Option<Vec<Vec<u8>>>
pub fn get_raw(&self, query: &str) -> Option<Vec<Vec<u8>>>
Return raw data without decoding.
APIC should call this method, as should SYLT.
SYLT may call the get method in the future.
This method is case insensitive.
Sourcepub fn parse_id3v1(&mut self) -> Result<()>
pub fn parse_id3v1(&mut self) -> Result<()>
Start parsing id3v1.
It is not recommended to call this method,
thinking that the ID3 protocol contains very little information,
unless a very old song.
Examples found in repository?
2fn main() -> std::io::Result<()> {
3 // https://drive.google.com/file/d/1fp_TYclIKZAWMwFTnxEEe4PqJCuBqHl4/view?usp=sharing
4 let mut id3_parser = ID3Parser::new("云烟成雨.mp3").unwrap();
5
6 id3_parser.parse_id3v1()?;
7 // The ID3v1 protocol does not specify the content encoding,
8 // which may be UTF-8, GBK or some other encoding,
9 // so it is not possible to decode it, so the bytecode is output directly
10 println!("{}", id3_parser.id3v1);
11
12 id3_parser.parse_id3v2()?;
13 println!("{}", id3_parser.pheader);
14 println!("{}", id3_parser.eheader);
15 println!("{}", id3_parser.footer);
16
17 // The `get` method is case insensitive,
18 // so you're allowed to pass in uppercase or lowercase characters or a mix of upper and lowercase characters,
19 // as is the `get_raw` method
20 println!("TIT2 = {:?}", id3_parser.get("TIT2").unwrap());
21 println!("TALB = {:?}", id3_parser.get("talb").unwrap());
22 println!("TPE1 = {:?}", id3_parser.get("tpe1").unwrap());
23 println!("TPE2 = {:?}", id3_parser.get("tpe2").unwrap());
24 println!("padding size = {}", id3_parser.padding_size);
25
26 // It is not recommended to print the APIC byte sequence because it is really long
27 // println!("APIC_raw = {:?}", parser.get_raw("apic").unwrap());
28
29 // Write filename.jpg to the current directory.
30 // No need to worry about multiple APIC frames in a file being overwritten by the same name.
31 // Naming rules: <filename>_mp3_<picture_type>[_index].jpg
32 id3_parser.write_image()?;
33
34 let mut flac_parser = FlacParser::new("云烟成雨.flac").unwrap();
35 flac_parser.parse()?;
36
37 // https://www.xiph.org/vorbis/doc/v-comment.html
38 // The `get` method is case insensitive
39 println!("artist = {:?}", flac_parser.get("artist").unwrap());
40
41 println!("album = {:?}", flac_parser.get("album").unwrap());
42
43 // Get all vorbis comments in the file
44 let (k, v) = flac_parser.get_all().unwrap();
45 let mut index = 0;
46 while index < k.len() {
47 println!(
48 "vorbis key = {:?}, vorbis comment = {:?}",
49 k[index], v[index]
50 );
51 index += 1;
52 }
53
54 // It is not recommended to print the APIC byte sequence because it is really long
55 // println!("picture_raw_data = {:?}", flac_parser.picture[0].data);
56
57 println!("md5 = {}", flac_parser.stream_info.md5);
58
59 println!(
60 "picture width = {}, picture width = {}, picture type = {:?}",
61 flac_parser.picture[0].width,
62 flac_parser.picture[0].height,
63 flac_parser.picture[0].pic_type
64 );
65
66 // This will write image[s] to disk
67 // Naming rules: <filename>_flac_<picture_type>[_index].jpg
68 flac_parser.write_image()?;
69
70 flac_parser.change_target("千千阙歌.flac");
71
72
73 let mut ogg_parser = OggParser::new("xhh.ogg");
74 ogg_parser.parse()?;
75 println!("ogg_vorbis_comment = {:?}", ogg_parser.get_all());
76 Ok(())
77}Sourcepub fn parse_id3v2(&mut self) -> Result<()>
pub fn parse_id3v2(&mut self) -> Result<()>
Start parsing id3v2.
Examples found in repository?
2fn main() -> std::io::Result<()> {
3 // https://drive.google.com/file/d/1fp_TYclIKZAWMwFTnxEEe4PqJCuBqHl4/view?usp=sharing
4 let mut id3_parser = ID3Parser::new("云烟成雨.mp3").unwrap();
5
6 id3_parser.parse_id3v1()?;
7 // The ID3v1 protocol does not specify the content encoding,
8 // which may be UTF-8, GBK or some other encoding,
9 // so it is not possible to decode it, so the bytecode is output directly
10 println!("{}", id3_parser.id3v1);
11
12 id3_parser.parse_id3v2()?;
13 println!("{}", id3_parser.pheader);
14 println!("{}", id3_parser.eheader);
15 println!("{}", id3_parser.footer);
16
17 // The `get` method is case insensitive,
18 // so you're allowed to pass in uppercase or lowercase characters or a mix of upper and lowercase characters,
19 // as is the `get_raw` method
20 println!("TIT2 = {:?}", id3_parser.get("TIT2").unwrap());
21 println!("TALB = {:?}", id3_parser.get("talb").unwrap());
22 println!("TPE1 = {:?}", id3_parser.get("tpe1").unwrap());
23 println!("TPE2 = {:?}", id3_parser.get("tpe2").unwrap());
24 println!("padding size = {}", id3_parser.padding_size);
25
26 // It is not recommended to print the APIC byte sequence because it is really long
27 // println!("APIC_raw = {:?}", parser.get_raw("apic").unwrap());
28
29 // Write filename.jpg to the current directory.
30 // No need to worry about multiple APIC frames in a file being overwritten by the same name.
31 // Naming rules: <filename>_mp3_<picture_type>[_index].jpg
32 id3_parser.write_image()?;
33
34 let mut flac_parser = FlacParser::new("云烟成雨.flac").unwrap();
35 flac_parser.parse()?;
36
37 // https://www.xiph.org/vorbis/doc/v-comment.html
38 // The `get` method is case insensitive
39 println!("artist = {:?}", flac_parser.get("artist").unwrap());
40
41 println!("album = {:?}", flac_parser.get("album").unwrap());
42
43 // Get all vorbis comments in the file
44 let (k, v) = flac_parser.get_all().unwrap();
45 let mut index = 0;
46 while index < k.len() {
47 println!(
48 "vorbis key = {:?}, vorbis comment = {:?}",
49 k[index], v[index]
50 );
51 index += 1;
52 }
53
54 // It is not recommended to print the APIC byte sequence because it is really long
55 // println!("picture_raw_data = {:?}", flac_parser.picture[0].data);
56
57 println!("md5 = {}", flac_parser.stream_info.md5);
58
59 println!(
60 "picture width = {}, picture width = {}, picture type = {:?}",
61 flac_parser.picture[0].width,
62 flac_parser.picture[0].height,
63 flac_parser.picture[0].pic_type
64 );
65
66 // This will write image[s] to disk
67 // Naming rules: <filename>_flac_<picture_type>[_index].jpg
68 flac_parser.write_image()?;
69
70 flac_parser.change_target("千千阙歌.flac");
71
72
73 let mut ogg_parser = OggParser::new("xhh.ogg");
74 ogg_parser.parse()?;
75 println!("ogg_vorbis_comment = {:?}", ogg_parser.get_all());
76 Ok(())
77}Sourcepub fn change_target(&mut self, new_fp: T)
pub fn change_target(&mut self, new_fp: T)
As the method says.
In addition, its own data will be cleared.
Sourcepub fn write_image(&self) -> Result<()>
pub fn write_image(&self) -> Result<()>
Write APIC frame’s raw to the current directory named with filename.jpg like 云烟成雨.jpg if there is only one APIC frame.
Unless, add a underline followd by a number after the filename start with the second one, like 云烟成雨_1.jpg.
Examples found in repository?
2fn main() -> std::io::Result<()> {
3 // https://drive.google.com/file/d/1fp_TYclIKZAWMwFTnxEEe4PqJCuBqHl4/view?usp=sharing
4 let mut id3_parser = ID3Parser::new("云烟成雨.mp3").unwrap();
5
6 id3_parser.parse_id3v1()?;
7 // The ID3v1 protocol does not specify the content encoding,
8 // which may be UTF-8, GBK or some other encoding,
9 // so it is not possible to decode it, so the bytecode is output directly
10 println!("{}", id3_parser.id3v1);
11
12 id3_parser.parse_id3v2()?;
13 println!("{}", id3_parser.pheader);
14 println!("{}", id3_parser.eheader);
15 println!("{}", id3_parser.footer);
16
17 // The `get` method is case insensitive,
18 // so you're allowed to pass in uppercase or lowercase characters or a mix of upper and lowercase characters,
19 // as is the `get_raw` method
20 println!("TIT2 = {:?}", id3_parser.get("TIT2").unwrap());
21 println!("TALB = {:?}", id3_parser.get("talb").unwrap());
22 println!("TPE1 = {:?}", id3_parser.get("tpe1").unwrap());
23 println!("TPE2 = {:?}", id3_parser.get("tpe2").unwrap());
24 println!("padding size = {}", id3_parser.padding_size);
25
26 // It is not recommended to print the APIC byte sequence because it is really long
27 // println!("APIC_raw = {:?}", parser.get_raw("apic").unwrap());
28
29 // Write filename.jpg to the current directory.
30 // No need to worry about multiple APIC frames in a file being overwritten by the same name.
31 // Naming rules: <filename>_mp3_<picture_type>[_index].jpg
32 id3_parser.write_image()?;
33
34 let mut flac_parser = FlacParser::new("云烟成雨.flac").unwrap();
35 flac_parser.parse()?;
36
37 // https://www.xiph.org/vorbis/doc/v-comment.html
38 // The `get` method is case insensitive
39 println!("artist = {:?}", flac_parser.get("artist").unwrap());
40
41 println!("album = {:?}", flac_parser.get("album").unwrap());
42
43 // Get all vorbis comments in the file
44 let (k, v) = flac_parser.get_all().unwrap();
45 let mut index = 0;
46 while index < k.len() {
47 println!(
48 "vorbis key = {:?}, vorbis comment = {:?}",
49 k[index], v[index]
50 );
51 index += 1;
52 }
53
54 // It is not recommended to print the APIC byte sequence because it is really long
55 // println!("picture_raw_data = {:?}", flac_parser.picture[0].data);
56
57 println!("md5 = {}", flac_parser.stream_info.md5);
58
59 println!(
60 "picture width = {}, picture width = {}, picture type = {:?}",
61 flac_parser.picture[0].width,
62 flac_parser.picture[0].height,
63 flac_parser.picture[0].pic_type
64 );
65
66 // This will write image[s] to disk
67 // Naming rules: <filename>_flac_<picture_type>[_index].jpg
68 flac_parser.write_image()?;
69
70 flac_parser.change_target("千千阙歌.flac");
71
72
73 let mut ogg_parser = OggParser::new("xhh.ogg");
74 ogg_parser.parse()?;
75 println!("ogg_vorbis_comment = {:?}", ogg_parser.get_all());
76 Ok(())
77}