Got it working
All checks were successful
Rust Build / Check (pull_request) Successful in 30s
Rust Build / Test Suite (pull_request) Successful in 50s
Rust Build / Rustfmt (pull_request) Successful in 40s
Rust Build / Clippy (pull_request) Successful in 41s
Rust Build / build (pull_request) Successful in 44s
All checks were successful
Rust Build / Check (pull_request) Successful in 30s
Rust Build / Test Suite (pull_request) Successful in 50s
Rust Build / Rustfmt (pull_request) Successful in 40s
Rust Build / Clippy (pull_request) Successful in 41s
Rust Build / build (pull_request) Successful in 44s
This commit is contained in:
52
src/lib.rs
52
src/lib.rs
@@ -10,7 +10,53 @@ pub mod meta_type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub mod meta_next {
|
pub mod meta_next {
|
||||||
|
use lofty::file::AudioFile;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
fn get_type(t: meta_type::Type) -> Result<String, std::io::Error> {
|
||||||
|
match t {
|
||||||
|
meta_type::Type::Title => Ok("TITLE".to_owned()),
|
||||||
|
meta_type::Type::Artist => Ok("ARTIST".to_owned()),
|
||||||
|
meta_type::Type::Album => Ok("ALBUM".to_owned()),
|
||||||
|
meta_type::Type::Genre => Ok("GENRE".to_owned()),
|
||||||
|
meta_type::Type::Year => Ok("YEAR".to_owned()),
|
||||||
|
meta_type::Type::Track => Ok("TRACK".to_owned()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_meta(t: meta_type::Type, filepath: &String) -> Result<String, std::io::Error> {
|
||||||
|
match std::fs::File::open(filepath) {
|
||||||
|
Ok(mut content) => {
|
||||||
|
match lofty::flac::FlacFile::read_from(
|
||||||
|
&mut content,
|
||||||
|
lofty::config::ParseOptions::new(),
|
||||||
|
) {
|
||||||
|
Ok(flac_file) => match flac_file.vorbis_comments() {
|
||||||
|
Some(vb) => {
|
||||||
|
let type_str: String = get_type(t).unwrap();
|
||||||
|
match vb.get(&type_str) {
|
||||||
|
Some(val) => Ok(val.to_owned()),
|
||||||
|
None => Err(std::io::Error::new(
|
||||||
|
std::io::ErrorKind::InvalidData,
|
||||||
|
"Could not get tag data",
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => Err(std::io::Error::new(
|
||||||
|
std::io::ErrorKind::InvalidData,
|
||||||
|
"No tags found",
|
||||||
|
)),
|
||||||
|
},
|
||||||
|
Err(err) => Err(std::io::Error::new(
|
||||||
|
std::io::ErrorKind::InvalidData,
|
||||||
|
err.to_string(),
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -27,10 +73,9 @@ mod tests {
|
|||||||
println!("Path: {:?}", full_path);
|
println!("Path: {:?}", full_path);
|
||||||
|
|
||||||
assert!(full_path.exists(), "Path does not exists {:?}", full_path);
|
assert!(full_path.exists(), "Path does not exists {:?}", full_path);
|
||||||
let _filepath = full_path.display().to_string();
|
let filepath = full_path.display().to_string();
|
||||||
|
|
||||||
/*
|
match meta_next::get_meta(meta_type::Type::Title, &filepath) {
|
||||||
match meta_nouveaou::get_meta(meta_type::Type::Title, &filepath) {
|
|
||||||
Ok(title) => {
|
Ok(title) => {
|
||||||
let found = title == "Just roll it";
|
let found = title == "Just roll it";
|
||||||
assert!(found, "Meta information was not found {:?}", title);
|
assert!(found, "Meta information was not found {:?}", title);
|
||||||
@@ -39,6 +84,5 @@ mod tests {
|
|||||||
assert!(false, "Error: {:?}", err);
|
assert!(false, "Error: {:?}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user