9个版本
0.3.3 | 2024年4月24日 |
---|---|
0.3.2 | 2024年4月10日 |
0.3.0 | 2024年3月18日 |
0.2.0 | 2023年12月26日 |
0.1.1 | 2023年7月17日 |
#954 in 网络编程
每月 27 次下载
260KB
3.5K SLoC
Kodik Rust
Kodik Rust - 作为Kodik API包装器的有效Rust库 🦾
📖 文档 |
---|
安装
从crates.io安装 kodik。将以下行添加到您的 Cargo.toml
文件依赖部分
kodik-api = "0.3"
或者您可以使用cargo添加
cargo add kodik-api
用法
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",
// ],
// },
// ],
// }
}
用法流
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")
}
}
}
}
}
}
依赖
~4–15MB
~211K SLoC