#api-wrapper #api #wrapper #api-bindings #async #sdk #kodik

kodik-api

An unofficial async Rust library that allows you to interact with the Kodik API

9 releases

0.3.3 Apr 24, 2024
0.3.2 Apr 10, 2024
0.3.0 Mar 18, 2024
0.2.0 Dec 26, 2023
0.1.1 Jul 17, 2023

#26 in #api-wrapper

Download history 1/week @ 2024-03-09 107/week @ 2024-03-16 12/week @ 2024-03-23 9/week @ 2024-03-30 117/week @ 2024-04-06 10/week @ 2024-04-13 103/week @ 2024-04-20 8/week @ 2024-04-27 1/week @ 2024-05-04

574 downloads per month

MIT license

260KB
3.5K SLoC

Kodik Rust

Crate version Tests License

Kodik Rust - An efficient Rust library serving as a wrapper for the Kodik API 🦾

📖 Documentation

Installation

Install kodik from crates.io. Add the following line to your Cargo.toml file's dependencies section:

kodik-api = "0.3"

Or you can add with cargo

cargo add kodik-api

Usage

use kodik_api::Client;
use kodik_api::search::SearchQuery;

#[tokio::main]
async fn main() {
    // KODIK_API_KEY=q8p5vnf9crt7xfyzke4iwc6r5rvsurv7
    let api_key = std::env::var("KODIK_API_KEY").expect("KODIK_API_KEY is not set");

    let client = Client::new(api_key);

    let search_response = SearchQuery::new()
        .with_title("Cyberpunk: Edgerunners")
        .with_limit(1)
        .execute(&client)
        .await
        .unwrap();

    println!("search response = {search_response:#?}");
    // search response = SearchResponse {
    //     time: "3ms",
    //     total: 1,
    //     prev_page: None,
    //     next_page: None,
    //     results: [
    //         Release {
    //             id: "serial-45534",
    //             title: "Киберпанк: Бегущие по краю",
    //             title_orig: "Cyberpunk: Edgerunners",
    //             other_title: Some("サイバーパンク エッジランナーズ"),
    //             link: "//kodik.info/serial/45534/d8619e900d122ea8eff8b55891b09bac/720p",
    //             year: 2022,
    //             kinopoisk_id: Some(
    //                 "2000102",
    //             ),
    //             imdb_id: Some(
    //                 "tt12590266",
    //             ),
    //             mdl_id: None,
    //             worldart_link: Some(
    //                 "http://www.world-art.ru/animation/animation.php?id=10534",
    //             ),
    //             shikimori_id: Some(
    //                 "42310",
    //             ),
    //             release_type: AnimeSerial,
    //             quality: WebDlRip720p,
    //             camrip: false,
    //             lgbt: false,
    //             translation: Translation {
    //                 id: 610,
    //                 title: "AniLibria.TV",
    //                 translation_type: Voice,
    //             },
    //             created_at: "2022-09-14T10:54:34Z",
    //             updated_at: "2022-09-23T22:31:33Z",
    //             blocked_seasons: Some(
    //                 {},
    //             ),
    //             seasons: None,
    //             last_season: Some(
    //                 1,
    //             ),
    //             last_episode: Some(
    //                 10,
    //             ),
    //             episodes_count: Some(
    //                 10,
    //             ),
    //             blocked_countries: [],
    //             material_data: None,
    //             screenshots: [
    //                 "https://i.kodik.biz/screenshots/seria/104981222/1.jpg",
    //                 "https://i.kodik.biz/screenshots/seria/104981222/2.jpg",
    //                 "https://i.kodik.biz/screenshots/seria/104981222/3.jpg",
    //                 "https://i.kodik.biz/screenshots/seria/104981222/4.jpg",
    //                 "https://i.kodik.biz/screenshots/seria/104981222/5.jpg",
    //             ],
    //         },
    //     ],
    // }
}

Usage streams

use futures_util::{pin_mut, StreamExt};

use kodik_api::Client;
use kodik_api::list::ListQuery;
use kodik_api::types::ReleaseType;

#[tokio::main]
async fn main() {
    // KODIK_API_KEY=q8p5vnf9crt7xfyzke4iwc6r5rvsurv7
    let api_key = std::env::var("KODIK_API_KEY").expect("KODIK_API_KEY is not set");

    let client = Client::new(api_key);

    let stream = ListQuery::new()
        .with_limit(100)
        .with_types(&[ReleaseType::Anime, ReleaseType::AnimeSerial])
        .stream(&client);

    pin_mut!(stream);

    while let Some(response) = stream.next().await {
        match response {
            Ok(response) => {
                dbg!(response.total);
                dbg!(response.results);
            }
            Err(err) => {
                match err {
                    // Kodik error
                    kodik_api::error::Error::KodikError(message) => {
                        panic!("kodik error = {}", message);
                    }
                    // Reqwest error
                    kodik_api::error::Error::HttpError(_err) => {
                        // Another try
                        continue;
                    }
                    _ => {
                        panic!("Unknown error")
                    }
                }
            }
        }
    }
}

Dependencies

~4–18MB
~225K SLoC