use clap::Parser;
use uuid::Uuid;
use mangadex_api::v5::MangaDexClient;
use mangadex_api_types::LegacyMappingType;
#[derive(Parser)]
#[clap(
name = "MangaDex Legacy ID Mapping",
about = "Get the new UUIDs from the legacy IDs"
)]
struct Args {
#[clap()]
ids: Vec<u32>,
#[clap(short, long, default_value = "manga")]
r#type: LegacyMappingType,
}
#[tokio::main]
async fn main() {
let args = Args::parse();
if let Err(e) = run(args).await {
use std::process;
eprintln!("Application error: {e}");
process::exit(1);
}
}
async fn run(args: Args) -> anyhow::Result<()> {
let client = MangaDexClient::default();
let mapped_ids = client
.legacy()
.mapping()
.post()
.map_type(args.r#type)
.ids(args.ids)
.build()?
.send()
.await?;
let ids: Vec<(u32, Uuid)> = mapped_ids
.data
.iter()
.map(|id_map| (id_map.attributes.legacy_id, id_map.attributes.new_id))
.collect();
println!("{ids:#?}");
Ok(())
}