hand written cdparanoia III release 10.2 (September 11, 2008) parsing

This commit is contained in:
2026-08-24 13:15:32 -04:00
parent 0b62d31878
commit 03340fbeac
5 changed files with 359 additions and 5 deletions

View File

@@ -1,4 +1,7 @@
use std::{convert, ops::Index};
use core::panic;
use std::process::Command;
use sha1::{Digest, Sha1};
const B64TABLE: &str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._";
@@ -41,7 +44,86 @@ pub fn compute_disc_id(first_track: u8, last_track: u8, leadout: u32, offsets: &
let offset = offsets.get(i).copied().unwrap_or(0);
toc.push_str(&format!("{:08X}", offset));
}
toc
let hash = Sha1::digest(toc.as_bytes());
b64(&hash)
}
pub fn read_toc() {
let output = Command::new("cdparanoia")
.arg("-Q")
.output()
.expect("couldn't run cdparanoia :( is it installed?\nyou can probably look up how to install it\nfor your distro :)\n");
let toc_text = String::from_utf8_lossy(&output.stderr);
if !output.status.success() {
panic!("so cdparanoia got upset, idk?\nrun cdparanoia -Q yourself and see what happens\n");
}
let mut in_toc = false;
let mut first_track = 0;
let mut last_track = 0;
let mut leadout = 0;
let mut offsets: Vec<u32> = Vec::new();
for line in toc_text.lines() {
// i am assuming you are trying to read this because it is failing.
// don't read it.
// if you want it to work, install the following version of cdparanoia, and ONLY that version
// cdparanoia III release 10.2 (September 11, 2008)
// make sure that running cdparanoia -Q with a drive in, after the track number like 1.,
// there should be 4 spaces (5 characters, the period+4 spaces)
// if there isn't,
// make your own parser that outputs in the right format and overwrite the normal cdparanoia command with it
// shouldn't be that bad.
let line = line.trim();
if line.contains("TOTAL") {
leadout = line
.split_once("TOTAL")
.unwrap() // what's error handling?
.1
.trim()
.split_once(' ')
.unwrap() // what's error handling?
.0
.parse()
.unwrap(); // what's error handling?
leadout += 150;
break;
}
if in_toc {
let track_num: u8 = line.split('.').next().unwrap().parse().unwrap();
if first_track == 0 {
// before this method, i did it by counting the line number, subtracting 7 to get to the first parts
// of useful info, which WORKED for my build, but i replaced it, never forget, i-=7
first_track = track_num;
}
last_track = track_num;
offsets.push(
line.split_once(". ")
.unwrap() // what's error handling?
.1
.split_once(']')
.unwrap() // what's error handling?
.1
.trim()
.split_once(' ')
.unwrap() // what's error handling?
.0
.parse::<u32>()
.unwrap() // what's error handling?
+ 150,
);
}
if line.contains("===") {
in_toc = true;
}
}
println!(
"first track: {first_track} last track: {last_track} leadout: {leadout} offsets: {offsets:?}"
);
let id = compute_disc_id(first_track, last_track, leadout, &offsets);
println!("disc id: {id}");
// finally that function is over!
// still, what's error handling?
}
#[cfg(test)]
mod tests {

View File

@@ -132,6 +132,7 @@ fn remove_empty_dirs(dir: &Path) {
}
}
fn main() {
disc_id::read_toc();
let cat = include_bytes!("../cat_01.jpg"); // my kitty!
let cli = Cli::parse();