fix: Don't use file_format crate as it didn't recognize all audio files, use zerocopy the right way.
This commit is contained in:
parent
2c5db4117b
commit
8575b80136
3 changed files with 5 additions and 50 deletions
9
Cargo.lock
generated
9
Cargo.lock
generated
|
@ -104,12 +104,6 @@ version = "1.6.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "abd57806937c9cc163efc8ea3910e00a62e2aeb0b8119f1793a978088f8f6b04"
|
checksum = "abd57806937c9cc163efc8ea3910e00a62e2aeb0b8119f1793a978088f8f6b04"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "file-format"
|
|
||||||
version = "0.26.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e7ef3d5e8ae27277c8285ac43ed153158178ef0f79567f32024ca8140a0c7cd8"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
|
@ -270,11 +264,10 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xbst"
|
name = "xbst"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"deunicode",
|
"deunicode",
|
||||||
"file-format",
|
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"zerocopy",
|
"zerocopy",
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "xbst"
|
name = "xbst"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -8,4 +8,3 @@ thiserror = "2.0.12"
|
||||||
clap = { version = "4.5.31", features = ["derive"] }
|
clap = { version = "4.5.31", features = ["derive"] }
|
||||||
zerocopy = { version = "0.8.26", features = ["derive"] }
|
zerocopy = { version = "0.8.26", features = ["derive"] }
|
||||||
deunicode = "1.6.2"
|
deunicode = "1.6.2"
|
||||||
file-format = "0.26.0"
|
|
||||||
|
|
43
src/main.rs
43
src/main.rs
|
@ -11,7 +11,6 @@ mod utils;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use deunicode::AsciiChars;
|
use deunicode::AsciiChars;
|
||||||
use file_format::{FileFormat, Kind};
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use zerocopy::IntoBytes;
|
use zerocopy::IntoBytes;
|
||||||
|
|
||||||
|
@ -140,20 +139,6 @@ fn process(args: &Args) -> Result<(), Errors> {
|
||||||
let song = f.as_ref().unwrap();
|
let song = f.as_ref().unwrap();
|
||||||
let song_path = song.path();
|
let song_path = song.path();
|
||||||
|
|
||||||
// Get file format kind for the files inside soundtracks
|
|
||||||
let format = match FileFormat::from_file(&song_path).map_err(Errors::UnknownIO) {
|
|
||||||
Ok(f) => f.kind(),
|
|
||||||
Err(e) => {
|
|
||||||
eprintln!("\x1b[0;31m{}\x1b[0;20m", e);
|
|
||||||
Kind::Other
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Ignore non audio kind
|
|
||||||
if format != Kind::Audio {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
song_id[g] = total_songs_count as i32;
|
song_id[g] = total_songs_count as i32;
|
||||||
song_time_miliseconds[g] = match get_duration(song_path) {
|
song_time_miliseconds[g] = match get_duration(song_path) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
|
@ -373,37 +358,15 @@ fn write_database(
|
||||||
fs::create_dir_all(format!("{}/", &output)).map_err(Errors::UnknownIO)?;
|
fs::create_dir_all(format!("{}/", &output)).map_err(Errors::UnknownIO)?;
|
||||||
let mut database = File::create(format!("{}/ST.DB", &output)).map_err(Errors::UnknownIO)?;
|
let mut database = File::create(format!("{}/ST.DB", &output)).map_err(Errors::UnknownIO)?;
|
||||||
|
|
||||||
database.write_all(&header.magic.as_bytes())?;
|
database.write_all(header.as_bytes())?;
|
||||||
database.write_all(&header.num_soundtracks.as_bytes())?;
|
|
||||||
database.write_all(&header.next_soundtrack_id.as_bytes())?;
|
|
||||||
database.write_all(&header.soundtrack_ids.as_bytes())?;
|
|
||||||
database.write_all(&header.next_song_id.as_bytes())?;
|
|
||||||
database.write_all(&header.padding.as_bytes())?;
|
|
||||||
|
|
||||||
for st in &soundtracks {
|
database.write_all(soundtracks.as_bytes())?;
|
||||||
database.write_all(&st.magic.as_bytes())?;
|
|
||||||
database.write_all(&st.id.as_bytes())?;
|
|
||||||
database.write_all(&st.num_songs.as_bytes())?;
|
|
||||||
database.write_all(&st.song_groups_ids.as_bytes())?;
|
|
||||||
database.write_all(&st.total_time_miliseconds.as_bytes())?;
|
|
||||||
database.write_all(&st.name.as_bytes())?;
|
|
||||||
database.write_all(&st.padding.as_bytes())?;
|
|
||||||
}
|
|
||||||
|
|
||||||
for _ in 0..100 - &soundtracks.len() {
|
for _ in 0..100 - &soundtracks.len() {
|
||||||
database.write_all(&[0 as u8; 512])?;
|
database.write_all(&[0 as u8; 512])?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for s in songs {
|
database.write_all(songs.as_bytes())?;
|
||||||
database.write_all(&s.magic.as_bytes())?;
|
|
||||||
database.write_all(&s.soundtrack_id.as_bytes())?;
|
|
||||||
database.write_all(&s.id.as_bytes())?;
|
|
||||||
database.write_all(&s.ipadding.as_bytes())?;
|
|
||||||
database.write_all(&s.song_id.as_bytes())?;
|
|
||||||
database.write_all(&s.song_time_miliseconds.as_bytes())?;
|
|
||||||
database.write_all(&s.song_name.as_bytes())?;
|
|
||||||
database.write_all(&s.cpadding.as_bytes())?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue