FlacParser

Struct FlacParser 

Source
pub struct FlacParser<T>
where T: AsRef<Path>,
{ pub stream_info: BlockStreamInfo, pub application: BlockApplication, pub seek_table: BlockSeekTable, pub picture: Vec<BlockPicture>, pub cue_sheet: BlockCueSheet, pub padding_length: u32, /* private fields */ }

Fields§

§stream_info: BlockStreamInfo§application: BlockApplication§seek_table: BlockSeekTable§picture: Vec<BlockPicture>§cue_sheet: BlockCueSheet§padding_length: u32

Implementations§

Source§

impl<T> FlacParser<T>
where T: AsRef<Path>,

Source

pub fn new(fp: T) -> Result<Self>

Create a new FlacParser

Examples found in repository?
examples/runme.rs (line 34)
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}
Source

pub fn parse(&mut self) -> Result<()>

Start parsing flac.

Examples found in repository?
examples/runme.rs (line 35)
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}
Source

pub fn get(&mut self, query: &str) -> Option<Vec<String>>

Get vorbis comment according to query.

Return a Vec wrapped in an Option.

Examples found in repository?
examples/runme.rs (line 39)
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}
Source

pub fn get_all(&mut self) -> Result<(Vec<String>, Vec<Vec<String>>)>

Given that Vorbis allows for customized key values,

there may be key values other than those in common use,

so this method is provided to print all key-value pairs.

Examples found in repository?
examples/runme.rs (line 44)
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}
Source

pub fn write_image(&mut self) -> Result<()>

Write image(s) to disk.

Examples found in repository?
examples/runme.rs (line 68)
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}
Source

pub fn change_target(&mut self, new_fp: T)

As the method says.

In addition, its own data will be cleared.

Examples found in repository?
examples/runme.rs (line 70)
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}

Trait Implementations§

Source§

impl<T> Debug for FlacParser<T>
where T: AsRef<Path> + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for FlacParser<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for FlacParser<T>
where T: RefUnwindSafe,

§

impl<T> Send for FlacParser<T>
where T: Send,

§

impl<T> Sync for FlacParser<T>
where T: Sync,

§

impl<T> Unpin for FlacParser<T>
where T: Unpin,

§

impl<T> UnwindSafe for FlacParser<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.