runme/
runme.rs

1use music_metadata::{FlacParser, ID3Parser, OggParser};
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}