Compare commits

..

No commits in common. "21802286a527b6ff2b9ea2617b8ca78ed5a6c5d2" and "5fd7328d65f21aae5cf81552bb22d07d90e1b866" have entirely different histories.

4 changed files with 19 additions and 65 deletions

16
Cargo.lock generated
View file

@ -98,18 +98,6 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
[[package]]
name = "deunicode"
version = "1.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abd57806937c9cc163efc8ea3910e00a62e2aeb0b8119f1793a978088f8f6b04"
[[package]]
name = "file-format"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7ef3d5e8ae27277c8285ac43ed153158178ef0f79567f32024ca8140a0c7cd8"
[[package]]
name = "heck"
version = "0.5.0"
@ -270,11 +258,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "xbst"
version = "0.1.1"
version = "0.1.0"
dependencies = [
"clap",
"deunicode",
"file-format",
"thiserror",
"zerocopy",
]

View file

@ -1,11 +1,9 @@
[package]
name = "xbst"
version = "0.1.1"
version = "0.1.0"
edition = "2021"
[dependencies]
thiserror = "2.0.12"
clap = { version = "4.5.31", features = ["derive"] }
zerocopy = { version = "0.8.26", features = ["derive"] }
deunicode = "1.6.2"
file-format = "0.26.0"

View file

@ -10,8 +10,6 @@ use std::{
mod utils;
use clap::Parser;
use deunicode::AsciiChars;
use file_format::{FileFormat, Kind};
use thiserror::Error;
use zerocopy::IntoBytes;
@ -27,8 +25,6 @@ enum Errors {
FromUtf8(#[from] FromUtf8Error),
#[error("Skill issue on the programmer part ngl, report this to dev pls")]
SkillIssue(),
#[error("Didn't find any file to convert, is your input folder structued correctly?")]
NoFileToConvert(),
#[error("You are missing ffprobe in your PATH")]
MissingFfprobe(#[source] std::io::Error),
@ -54,8 +50,7 @@ fn main() {
let args = Args::parse();
println!(
"
"⠀⠀⠀⠂⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
@ -96,7 +91,6 @@ fn process(args: &Args) -> Result<(), Errors> {
for (i, soundtrack_dirs) in music_directory.enumerate() {
let soundtrack = soundtrack_dirs.map_err(Errors::UnknownFolder)?.path();
// Ignore non folders for soundtracks
if !soundtrack.is_dir() {
continue;
}
@ -104,16 +98,12 @@ fn process(args: &Args) -> Result<(), Errors> {
soundtrack_count += 1;
song_group_id = 0;
let soundtrack_name_str = soundtrack
// Convert the folder name into 2 bytes
let mut soundtrack_name = soundtrack
.file_name()
.map_or(OsStr::new("Unknown soundtrack"), |f| f)
.to_string_lossy()
.trim()
.ascii_chars()
.to_string();
// Convert the folder name into 2 bytes
let mut soundtrack_name = soundtrack_name_str
.bytes()
.map(|b| [b, 0])
.collect::<Vec<[u8; 2]>>();
@ -136,29 +126,14 @@ fn process(args: &Args) -> Result<(), Errors> {
let mut char_count = 0;
song_time_miliseconds = [0; 6];
for (g, f) in song_files.iter().enumerate() {
song_files.iter().enumerate().for_each(|(g, f)| {
let song = f.as_ref().unwrap();
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_time_miliseconds[g] = match get_duration(song_path) {
song_time_miliseconds[g] = match get_duration(song.path()) {
Ok(s) => s,
Err(e) => {
eprintln!("\x1b[0;31mFailed to get duration: {}\x1b[0;20m", e);
eprintln!("\x1b[0;31m{}\x1b[0;20m", e);
0
}
};
@ -170,9 +145,7 @@ fn process(args: &Args) -> Result<(), Errors> {
let filename = filepath
.file_stem()
.map_or(OsStr::new("Unknown track"), |f| f)
.to_string_lossy()
.ascii_chars()
.to_string();
.to_string_lossy();
let mut name = filename.trim().bytes().collect::<Vec<u8>>();
name.resize(32, 0);
@ -184,11 +157,10 @@ fn process(args: &Args) -> Result<(), Errors> {
files_to_convert.push(MusicFile {
path: song.path(),
soundtrack_name: soundtrack_name_str.clone(),
soundtrack_index: 0,
index: total_songs_count - 1,
});
}
});
let s = Song {
magic: 200819,
@ -251,10 +223,6 @@ fn process(args: &Args) -> Result<(), Errors> {
padding: [char::MIN; 24],
};
if files_to_convert.len() == 0 {
return Err(Errors::NoFileToConvert());
}
write_database(&args.output, header, soundtracks, songs)?;
for f in files_to_convert {
@ -277,17 +245,16 @@ fn process(args: &Args) -> Result<(), Errors> {
);
print!(
"{}\r{}Processing {} - {}",
"{}\r{}Processing {} ",
"\x1B[1B",
"\x1B[K",
f.soundtrack_name,
f.path
.file_stem()
.map_or(OsStr::new("Unknown track"), |f| f)
.to_string_lossy()
);
stdout().flush().map_err(Errors::UnknownIO)?;
let _ = stdout().flush().map_err(Errors::UnknownIO);
convert_to_wma(
f.path,
@ -333,8 +300,7 @@ fn convert_to_wma(
let binding = input.into_os_string();
let input = binding.to_str().unwrap();
fs::create_dir_all(format!("{}/{:0>4}", output, soundtrack_index))
.map_err(Errors::UnknownIO)?;
fs::create_dir_all(format!("{}/{:0>4}", output, soundtrack_index)).unwrap();
Command::new("ffmpeg")
.args([

View file

@ -5,11 +5,15 @@ use zerocopy::TryFromBytes;
pub struct MusicFile {
pub path: PathBuf,
pub soundtrack_index: u32,
pub soundtrack_name: String,
pub index: u32,
}
// https://xboxdevwiki.net/Soundtracks#ST.DB
#[derive(Debug, TryFromBytes)]
#[repr(C)]
pub struct Database {
pub header: Header,
pub soundtrack: Soundtrack,
}
#[derive(Debug, TryFromBytes)]
#[repr(C)]