mirror of
https://github.com/PeacefulBeastGames/audible-util.git
synced 2026-02-04 07:49:03 +00:00
Basic json deserialization
This commit is contained in:
92
src/chapters.rs
Normal file
92
src/chapters.rs
Normal file
@@ -0,0 +1,92 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Deserialize chapters information
|
||||
/// It goes 2 levels deep which works for Sandersons books which is all I want but there could be
|
||||
/// books with more levels
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AudibleChapters {
|
||||
#[serde(rename = "content_metadata")]
|
||||
pub content_metadata: ContentMetadata,
|
||||
#[serde(rename = "response_groups")]
|
||||
pub response_groups: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ContentMetadata {
|
||||
#[serde(rename = "chapter_info")]
|
||||
pub chapter_info: ChapterInfo,
|
||||
#[serde(rename = "content_reference")]
|
||||
pub content_reference: ContentReference,
|
||||
#[serde(rename = "last_position_heard")]
|
||||
pub last_position_heard: LastPositionHeard,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ChapterInfo {
|
||||
pub brand_intro_duration_ms: i64,
|
||||
pub brand_outro_duration_ms: i64,
|
||||
pub chapters: Vec<Chapter>,
|
||||
#[serde(rename = "is_accurate")]
|
||||
pub is_accurate: bool,
|
||||
#[serde(rename = "runtime_length_ms")]
|
||||
pub runtime_length_ms: i64,
|
||||
#[serde(rename = "runtime_length_sec")]
|
||||
pub runtime_length_sec: i64,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Chapter {
|
||||
#[serde(rename = "length_ms")]
|
||||
pub length_ms: i64,
|
||||
#[serde(rename = "start_offset_ms")]
|
||||
pub start_offset_ms: i64,
|
||||
#[serde(rename = "start_offset_sec")]
|
||||
pub start_offset_sec: i64,
|
||||
pub title: String,
|
||||
#[serde(default)]
|
||||
pub chapters: Vec<Chapter2>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Chapter2 {
|
||||
#[serde(rename = "length_ms")]
|
||||
pub length_ms: i64,
|
||||
#[serde(rename = "start_offset_ms")]
|
||||
pub start_offset_ms: i64,
|
||||
#[serde(rename = "start_offset_sec")]
|
||||
pub start_offset_sec: i64,
|
||||
pub title: String,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ContentReference {
|
||||
pub acr: String,
|
||||
pub asin: String,
|
||||
pub codec: String,
|
||||
#[serde(rename = "content_format")]
|
||||
pub content_format: String,
|
||||
#[serde(rename = "content_size_in_bytes")]
|
||||
pub content_size_in_bytes: i64,
|
||||
#[serde(rename = "file_version")]
|
||||
pub file_version: String,
|
||||
pub marketplace: String,
|
||||
pub sku: String,
|
||||
pub tempo: String,
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct LastPositionHeard {
|
||||
#[serde(rename = "last_updated")]
|
||||
pub last_updated: String,
|
||||
#[serde(rename = "position_ms")]
|
||||
pub position_ms: i64,
|
||||
pub status: String,
|
||||
}
|
||||
14
src/cli.rs
Normal file
14
src/cli.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Parser)]
|
||||
pub struct Cli {
|
||||
/// Path to aaxc file
|
||||
#[clap(short, long)]
|
||||
pub aaxc_path: PathBuf,
|
||||
|
||||
/// voucher file
|
||||
#[clap(long)]
|
||||
pub voucher_path: Option<PathBuf>,
|
||||
}
|
||||
23
src/main.rs
Normal file
23
src/main.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use clap::Parser;
|
||||
|
||||
mod chapters;
|
||||
mod cli;
|
||||
mod voucher;
|
||||
|
||||
fn main() {
|
||||
let cli = cli::Cli::parse();
|
||||
|
||||
let aaxc_file_path = cli.aaxc_path;
|
||||
let aaxc_file_path_stem = aaxc_file_path
|
||||
.file_stem()
|
||||
.expect("Could not get file stem, is the path a file?");
|
||||
|
||||
// Take the aaxc file stem and add .voucher to it to get the voucher file path
|
||||
let voucher_file_path =
|
||||
aaxc_file_path.with_file_name(format!("{}.voucher", aaxc_file_path_stem.to_str().unwrap()));
|
||||
|
||||
println!("aaxc file path: {}", aaxc_file_path.display());
|
||||
println!("aaxc file exists? {}", aaxc_file_path.exists());
|
||||
println!("voucher file path: {}", voucher_file_path.display());
|
||||
println!("voucher file exists? {}", voucher_file_path.exists());
|
||||
}
|
||||
129
src/voucher.rs
Normal file
129
src/voucher.rs
Normal file
@@ -0,0 +1,129 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Deserializing the voucher file generated by `audible-cli`
|
||||
/// All I need is two fields but since this is a generated struct I'll just leave it as is
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AudibleCliVoucher {
|
||||
#[serde(rename = "content_license")]
|
||||
pub content_license: ContentLicense,
|
||||
#[serde(rename = "response_groups")]
|
||||
pub response_groups: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ContentLicense {
|
||||
pub acr: String,
|
||||
pub asin: String,
|
||||
#[serde(rename = "content_metadata")]
|
||||
pub content_metadata: ContentMetadata,
|
||||
#[serde(rename = "drm_type")]
|
||||
pub drm_type: String,
|
||||
#[serde(rename = "granted_right")]
|
||||
pub granted_right: String,
|
||||
#[serde(rename = "license_id")]
|
||||
pub license_id: String,
|
||||
#[serde(rename = "license_response")]
|
||||
pub license_response: LicenseResponse,
|
||||
#[serde(rename = "license_response_type")]
|
||||
pub license_response_type: String,
|
||||
pub message: String,
|
||||
#[serde(rename = "playback_info")]
|
||||
pub playback_info: PlaybackInfo,
|
||||
pub preview: bool,
|
||||
#[serde(rename = "request_id")]
|
||||
pub request_id: String,
|
||||
#[serde(rename = "requires_ad_supported_playback")]
|
||||
pub requires_ad_supported_playback: bool,
|
||||
#[serde(rename = "status_code")]
|
||||
pub status_code: String,
|
||||
#[serde(rename = "voucher_id")]
|
||||
pub voucher_id: String,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ContentMetadata {
|
||||
#[serde(rename = "content_reference")]
|
||||
pub content_reference: ContentReference,
|
||||
#[serde(rename = "content_url")]
|
||||
pub content_url: ContentUrl,
|
||||
#[serde(rename = "last_position_heard")]
|
||||
pub last_position_heard: LastPositionHeard,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ContentReference {
|
||||
pub acr: String,
|
||||
pub asin: String,
|
||||
pub codec: String,
|
||||
#[serde(rename = "content_format")]
|
||||
pub content_format: String,
|
||||
#[serde(rename = "content_size_in_bytes")]
|
||||
pub content_size_in_bytes: i64,
|
||||
#[serde(rename = "file_version")]
|
||||
pub file_version: String,
|
||||
pub marketplace: String,
|
||||
pub sku: String,
|
||||
pub tempo: String,
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ContentUrl {
|
||||
#[serde(rename = "offline_url")]
|
||||
pub offline_url: String,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct LastPositionHeard {
|
||||
#[serde(rename = "last_updated")]
|
||||
pub last_updated: String,
|
||||
#[serde(rename = "position_ms")]
|
||||
pub position_ms: i64,
|
||||
pub status: String,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct LicenseResponse {
|
||||
pub key: String,
|
||||
pub iv: String,
|
||||
pub rules: Vec<Rule>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Rule {
|
||||
pub parameters: Vec<Parameter>,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Parameter {
|
||||
pub expire_date: String,
|
||||
#[serde(rename = "type")]
|
||||
pub type_field: String,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PlaybackInfo {
|
||||
#[serde(rename = "last_position_heard")]
|
||||
pub last_position_heard: LastPositionHeard2,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct LastPositionHeard2 {
|
||||
#[serde(rename = "last_updated")]
|
||||
pub last_updated: String,
|
||||
#[serde(rename = "position_ms")]
|
||||
pub position_ms: i64,
|
||||
pub status: String,
|
||||
}
|
||||
Reference in New Issue
Block a user