Added code to get tag info
Some checks failed
Rust Build / Check (pull_request) Failing after 43s
Rust Build / Test Suite (pull_request) Failing after 47s
Rust Build / Rustfmt (pull_request) Failing after 42s
Rust Build / Clippy (pull_request) Failing after 42s
Rust Build / build (pull_request) Failing after 40s
Some checks failed
Rust Build / Check (pull_request) Failing after 43s
Rust Build / Test Suite (pull_request) Failing after 47s
Rust Build / Rustfmt (pull_request) Failing after 42s
Rust Build / Clippy (pull_request) Failing after 42s
Rust Build / build (pull_request) Failing after 40s
This commit is contained in:
46
src/lib.rs
46
src/lib.rs
@@ -2,6 +2,52 @@ pub fn add(left: u64, right: u64) -> u64 {
|
|||||||
left + right
|
left + right
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod meta_type {
|
||||||
|
pub enum Type {
|
||||||
|
Title,
|
||||||
|
Artist,
|
||||||
|
Album,
|
||||||
|
Genre,
|
||||||
|
Year,
|
||||||
|
Track,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod meta {
|
||||||
|
use super::*;
|
||||||
|
use taglib;
|
||||||
|
|
||||||
|
pub fn get_meta(t: meta_type::Type, filepath: &String) -> Result<String, taglib::FileError> {
|
||||||
|
match t {
|
||||||
|
meta_type::Type::Title => {
|
||||||
|
match get_file(filepath) {
|
||||||
|
Ok(file) => {
|
||||||
|
match get_tag(&file) {
|
||||||
|
Ok(tag) => {
|
||||||
|
match tag.title() {
|
||||||
|
Some(title) => Ok(title),
|
||||||
|
None => Err(taglib::FileError::NoAvailableTag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => Err(taglib::FileError::InvalidFile),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_file(filepath: &String) -> Result<taglib::File, taglib::FileError> {
|
||||||
|
taglib::File::new(filepath)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_tag(tag: &taglib::File) -> Result<taglib::Tag, taglib::FileError> {
|
||||||
|
tag.tag()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
Reference in New Issue
Block a user