Next release (#14)
All checks were successful
Release Tagging / release (push) Successful in 36s
Rust Build / Check (push) Successful in 32s
Rust Build / Test Suite (push) Successful in 39s
Rust Build / Rustfmt (push) Successful in 27s
Rust Build / Clippy (push) Successful in 39s
Rust Build / build (push) Successful in 43s
All checks were successful
Release Tagging / release (push) Successful in 36s
Rust Build / Check (push) Successful in 32s
Rust Build / Test Suite (push) Successful in 39s
Rust Build / Rustfmt (push) Successful in 27s
Rust Build / Clippy (push) Successful in 39s
Rust Build / build (push) Successful in 43s
Reviewed-on: #14
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
[package]
|
||||
name = "icarus_meta"
|
||||
version = "0.1.0"
|
||||
version = "0.1.30"
|
||||
edition = "2024"
|
||||
rust-version = "1.86"
|
||||
|
||||
[dependencies]
|
||||
lofty = { version = "0.22.3" }
|
||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.4.3" }
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = { version = "3.19.1" }
|
125
src/lib.rs
125
src/lib.rs
@@ -1,123 +1,2 @@
|
||||
pub mod meta_type {
|
||||
pub enum Type {
|
||||
Title,
|
||||
Artist,
|
||||
Album,
|
||||
Genre,
|
||||
Year,
|
||||
Track,
|
||||
}
|
||||
}
|
||||
|
||||
pub mod meta_next {
|
||||
use lofty::file::AudioFile;
|
||||
|
||||
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)]
|
||||
mod tests {
|
||||
use util::{file_exists, get_full_path};
|
||||
|
||||
use super::*;
|
||||
|
||||
mod util {
|
||||
pub fn get_full_path(
|
||||
directory: &String,
|
||||
filename: &String,
|
||||
) -> Result<String, std::io::Error> {
|
||||
match path_buf(directory, filename) {
|
||||
Ok(pf) => Ok(pf.display().to_string()),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn file_exists(directory: &String, filename: &String) -> Result<bool, std::io::Error> {
|
||||
match path_buf(directory, filename) {
|
||||
Ok(pf) => Ok(pf.exists()),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
fn path_buf(
|
||||
directory: &String,
|
||||
filename: &String,
|
||||
) -> Result<std::path::PathBuf, std::io::Error> {
|
||||
let dir_path = std::path::Path::new(&directory);
|
||||
Ok(dir_path.join(filename))
|
||||
}
|
||||
|
||||
pub fn test_file_directory() -> String {
|
||||
String::from("tests/sample_tracks3")
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_title() {
|
||||
let filename = String::from("track01.flac");
|
||||
let dir = util::test_file_directory();
|
||||
|
||||
match file_exists(&dir, &filename) {
|
||||
Ok(_) => {
|
||||
let filepath = get_full_path(&dir, &filename).unwrap();
|
||||
|
||||
match meta_next::get_meta(meta_type::Type::Title, &filepath) {
|
||||
Ok(title) => {
|
||||
let found = title == "Just roll it";
|
||||
assert!(found, "Meta information was not found {:?}", title);
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: File does not exist {:?}", err.to_string());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
pub mod meta;
|
||||
pub mod types;
|
||||
|
1235
src/meta.rs
Normal file
1235
src/meta.rs
Normal file
File diff suppressed because it is too large
Load Diff
30
src/types.rs
Normal file
30
src/types.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
pub enum Type {
|
||||
Title,
|
||||
Artist,
|
||||
Album,
|
||||
AlbumArtist,
|
||||
Genre,
|
||||
Date,
|
||||
Track,
|
||||
Disc,
|
||||
TrackCount,
|
||||
DiscCount,
|
||||
}
|
||||
|
||||
pub mod access {
|
||||
|
||||
pub fn get_type(t: super::Type) -> Result<String, std::io::Error> {
|
||||
match t {
|
||||
super::Type::Title => Ok("TITLE".to_owned()),
|
||||
super::Type::Artist => Ok("ARTIST".to_owned()),
|
||||
super::Type::Album => Ok("ALBUM".to_owned()),
|
||||
super::Type::AlbumArtist => Ok("ALBUMARTIST".to_owned()),
|
||||
super::Type::Genre => Ok("GENRE".to_owned()),
|
||||
super::Type::Date => Ok("DATE".to_owned()),
|
||||
super::Type::Track => Ok("TRACKNUMBER".to_owned()),
|
||||
super::Type::Disc => Ok("DISCNUMBER".to_owned()),
|
||||
super::Type::TrackCount => Ok("TRACKCOUNT".to_owned()),
|
||||
super::Type::DiscCount => Ok("DISCCOUNT".to_owned()),
|
||||
}
|
||||
}
|
||||
}
|
BIN
tests/sample_tracks3/Sample Tracks 3 - Other one.png
Normal file
BIN
tests/sample_tracks3/Sample Tracks 3 - Other one.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
BIN
tests/sample_tracks3/Sample Tracks 3.png
Normal file
BIN
tests/sample_tracks3/Sample Tracks 3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user