cd can get info now!!!
This commit is contained in:
@@ -5,6 +5,8 @@ use sha1::{Digest, Sha1};
|
||||
|
||||
const B64TABLE: &str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._";
|
||||
|
||||
// credit to https://dev.to/vvkkumar06/converting-a-string-to-base64-manually-4ln2
|
||||
// for showing how to make a base64 converter (guide, i wrote the code).
|
||||
fn b64(data: &[u8]) -> String {
|
||||
let binary: Vec<u8> = data
|
||||
.iter()
|
||||
@@ -47,7 +49,7 @@ pub fn compute_disc_id(first_track: u8, last_track: u8, leadout: u32, offsets: &
|
||||
let hash = Sha1::digest(toc.as_bytes());
|
||||
b64(&hash)
|
||||
}
|
||||
pub fn read_toc() {
|
||||
pub fn get_disc_id() -> String {
|
||||
let output = Command::new("cdparanoia")
|
||||
.arg("-Q")
|
||||
.output()
|
||||
@@ -117,14 +119,16 @@ pub fn read_toc() {
|
||||
in_toc = true;
|
||||
}
|
||||
}
|
||||
println!(
|
||||
"first track: {first_track} last track: {last_track} leadout: {leadout} offsets: {offsets:?}"
|
||||
);
|
||||
//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}");
|
||||
//println!("disc id: {id}");
|
||||
id
|
||||
// finally that function is over!
|
||||
// still, what's error handling?
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
mod disc_id;
|
||||
mod musicbrainz;
|
||||
|
||||
use clap::{
|
||||
Parser, Subcommand,
|
||||
@@ -132,7 +133,7 @@ fn remove_empty_dirs(dir: &Path) {
|
||||
}
|
||||
}
|
||||
fn main() {
|
||||
disc_id::read_toc();
|
||||
musicbrainz::get_disc_info("http://catgpt-server:5000");
|
||||
let cat = include_bytes!("../cat_01.jpg"); // my kitty!
|
||||
|
||||
let cli = Cli::parse();
|
||||
|
||||
47
src/musicbrainz.rs
Normal file
47
src/musicbrainz.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
use crate::disc_id;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct DiscResponse {
|
||||
releases: Vec<Release>,
|
||||
}
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Release {
|
||||
title: String,
|
||||
media: Vec<Medium>,
|
||||
}
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Medium {
|
||||
tracks: Vec<Track>,
|
||||
}
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Track {
|
||||
title: String,
|
||||
position: u32,
|
||||
#[serde(rename = "artist-credit")]
|
||||
artist_credit: Vec<ArtistCredit>,
|
||||
}
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct ArtistCredit {
|
||||
name: String,
|
||||
}
|
||||
|
||||
pub fn get_disc_info(base_url: &str) {
|
||||
let disc_id = disc_id::get_disc_id();
|
||||
let url = format!("{base_url}/ws/2/discid/{disc_id}");
|
||||
|
||||
let body = ureq::get(&url)
|
||||
.query("inc", "recordings+artist-credits")
|
||||
.query("fmt", "json")
|
||||
.header(
|
||||
"User-Agent",
|
||||
"Timbre/0.1 ( https://gitea.owendeed.com/Toasterkitten/timbre )",
|
||||
)
|
||||
.call()
|
||||
.expect("idk\n")
|
||||
.body_mut()
|
||||
.read_to_string()
|
||||
.expect("?");
|
||||
let parsed: DiscResponse = serde_json::from_str(&body).unwrap();
|
||||
println!("{parsed:?}");
|
||||
}
|
||||
Reference in New Issue
Block a user