pub struct File { /* private fields */ }
Expand description
A representation of an audio file, with meta-data and properties.
Implementations§
Source§impl File
impl File
Sourcepub fn new<P: AsRef<Path>>(path: P) -> Result<File, FileError>
pub fn new<P: AsRef<Path>>(path: P) -> Result<File, FileError>
Creates a new taglib::File
for the given filename
.
Examples found in repository?
examples/tagreader.rs (line 10)
5pub fn main() {
6 let args: Vec<String> = env::args().collect();
7
8 for i in 1..args.len() {
9 let ref arg = args[i];
10 let file = match taglib::File::new(arg) {
11 Ok(f) => f,
12 Err(e) => {
13 println!("Invalid file {} (error: {:?})", arg, e);
14 continue;
15 }
16 };
17
18 println!("*** \"{}\" ***", arg);
19
20 match file.tag() {
21 Ok(t) => {
22 println!("-- TAG --");
23 println!("title - {}", t.title().unwrap_or_default());
24 println!("artist - {}", t.artist().unwrap_or_default());
25 println!("album - {}", t.album().unwrap_or_default());
26 println!("year - {}", t.year().unwrap_or_default());
27 println!("comment - {}", t.comment().unwrap_or_default());
28 println!("track - {}", t.track().unwrap_or_default());
29 println!("genre - {}", t.genre().unwrap_or_default());
30 }
31 Err(e) => {
32 println!("No available tags for {} (error: {:?})", arg, e);
33 }
34 }
35
36 match file.audioproperties() {
37 Ok(p) => {
38 let secs = p.length() % 60;
39 let mins = (p.length() - secs) / 60;
40
41 println!("-- AUDIO --");
42 println!("bitrate - {}", p.bitrate());
43 println!("sample rate - {}", p.samplerate());
44 println!("channels - {}", p.channels());
45 println!("length - {}m:{}s", mins, secs);
46 }
47 Err(e) => {
48 println!("No available audio properties for {} (error: {:?})", arg, e);
49 }
50 }
51 }
52}
Sourcepub fn new_type(filename: &str, filetype: FileType) -> Result<File, FileError>
pub fn new_type(filename: &str, filetype: FileType) -> Result<File, FileError>
Creates a new taglib::File
for the given filename
and type of file.
Sourcepub fn tag(&self) -> Result<Tag<'_>, FileError>
pub fn tag(&self) -> Result<Tag<'_>, FileError>
Returns the taglib::Tag
instance for the given file.
Examples found in repository?
examples/tagreader.rs (line 20)
5pub fn main() {
6 let args: Vec<String> = env::args().collect();
7
8 for i in 1..args.len() {
9 let ref arg = args[i];
10 let file = match taglib::File::new(arg) {
11 Ok(f) => f,
12 Err(e) => {
13 println!("Invalid file {} (error: {:?})", arg, e);
14 continue;
15 }
16 };
17
18 println!("*** \"{}\" ***", arg);
19
20 match file.tag() {
21 Ok(t) => {
22 println!("-- TAG --");
23 println!("title - {}", t.title().unwrap_or_default());
24 println!("artist - {}", t.artist().unwrap_or_default());
25 println!("album - {}", t.album().unwrap_or_default());
26 println!("year - {}", t.year().unwrap_or_default());
27 println!("comment - {}", t.comment().unwrap_or_default());
28 println!("track - {}", t.track().unwrap_or_default());
29 println!("genre - {}", t.genre().unwrap_or_default());
30 }
31 Err(e) => {
32 println!("No available tags for {} (error: {:?})", arg, e);
33 }
34 }
35
36 match file.audioproperties() {
37 Ok(p) => {
38 let secs = p.length() % 60;
39 let mins = (p.length() - secs) / 60;
40
41 println!("-- AUDIO --");
42 println!("bitrate - {}", p.bitrate());
43 println!("sample rate - {}", p.samplerate());
44 println!("channels - {}", p.channels());
45 println!("length - {}m:{}s", mins, secs);
46 }
47 Err(e) => {
48 println!("No available audio properties for {} (error: {:?})", arg, e);
49 }
50 }
51 }
52}
Sourcepub fn audioproperties(&self) -> Result<AudioProperties<'_>, FileError>
pub fn audioproperties(&self) -> Result<AudioProperties<'_>, FileError>
Returns the taglib::AudioProperties
instance for the given file.
Examples found in repository?
examples/tagreader.rs (line 36)
5pub fn main() {
6 let args: Vec<String> = env::args().collect();
7
8 for i in 1..args.len() {
9 let ref arg = args[i];
10 let file = match taglib::File::new(arg) {
11 Ok(f) => f,
12 Err(e) => {
13 println!("Invalid file {} (error: {:?})", arg, e);
14 continue;
15 }
16 };
17
18 println!("*** \"{}\" ***", arg);
19
20 match file.tag() {
21 Ok(t) => {
22 println!("-- TAG --");
23 println!("title - {}", t.title().unwrap_or_default());
24 println!("artist - {}", t.artist().unwrap_or_default());
25 println!("album - {}", t.album().unwrap_or_default());
26 println!("year - {}", t.year().unwrap_or_default());
27 println!("comment - {}", t.comment().unwrap_or_default());
28 println!("track - {}", t.track().unwrap_or_default());
29 println!("genre - {}", t.genre().unwrap_or_default());
30 }
31 Err(e) => {
32 println!("No available tags for {} (error: {:?})", arg, e);
33 }
34 }
35
36 match file.audioproperties() {
37 Ok(p) => {
38 let secs = p.length() % 60;
39 let mins = (p.length() - secs) / 60;
40
41 println!("-- AUDIO --");
42 println!("bitrate - {}", p.bitrate());
43 println!("sample rate - {}", p.samplerate());
44 println!("channels - {}", p.channels());
45 println!("length - {}m:{}s", mins, secs);
46 }
47 Err(e) => {
48 println!("No available audio properties for {} (error: {:?})", arg, e);
49 }
50 }
51 }
52}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for File
impl RefUnwindSafe for File
impl !Send for File
impl !Sync for File
impl Unpin for File
impl UnwindSafe for File
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more