Commit ed2f1a5042

ed2f1a50421448242099d411000d79cb9b96aaa2

parent: 274ef10461

Unsigned

Wraient <wraient.911@gmail.com> · 2024-10-02 14:00 UTC

working search_anime_anilist

Layout: unified · split

Cargo.lock +7
@@ -103,6 +103,7 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
103name = "curd" 103name = "curd"
104version = "0.1.0" 104version = "0.1.0"
105dependencies = [ 105dependencies = [
106 "json",
106 "reqwest", 107 "reqwest",
107 "serde", 108 "serde",
108 "serde_json", 109 "serde_json",
@@ -421,6 +422,12 @@ dependencies = [
421 "wasm-bindgen", 422 "wasm-bindgen",
422] 423]
423 424
425[[package]]
426name = "json"
427version = "0.12.4"
428source = "registry+https://github.com/rust-lang/crates.io-index"
429checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd"
430
424[[package]] 431[[package]]
425name = "libc" 432name = "libc"
426version = "0.2.159" 433version = "0.2.159"
Cargo.toml +3 −2
@@ -4,7 +4,8 @@ version = "0.1.0"
4edition = "2021" 4edition = "2021"
5 5
6[dependencies] 6[dependencies]
7reqwest = { version = "0.12.8", features = ["blocking"] } 7json = "0.12.4"
8reqwest = { version = "0.12.8", features = ["blocking", "json"] }
8serde = {version = "1.0.210", features = ["derive"] } 9serde = {version = "1.0.210", features = ["derive"] }
9serde_json = "1.0.128" 10serde_json = "1.0.128"
10tokio = "1.40.0"\ No newline at end of file 11tokio = "1.40.0"
src/anilist.rs +21 −5
@@ -1,4 +1,3 @@
1
2use reqwest::{header::{HeaderMap, HeaderValue, AUTHORIZATION, CONTENT_TYPE}, Error}; 1use reqwest::{header::{HeaderMap, HeaderValue, AUTHORIZATION, CONTENT_TYPE}, Error};
3use serde::{Serialize, Deserialize}; 2use serde::{Serialize, Deserialize};
4 3
@@ -37,12 +36,12 @@ struct ResponseData {
37} 36}
38 37
39#[derive(Deserialize, Debug)] 38#[derive(Deserialize, Debug)]
40struct ApiResponse { 39pub struct ApiResponse {
41 data: ResponseData, 40 pub data: ResponseData,
42} 41}
43 42
44pub struct AnimeApi { 43pub struct AnimeApi {
45 token: String, 44 pub token: String,
46} 45}
47 46
48impl AnimeApi { 47impl AnimeApi {
@@ -95,12 +94,29 @@ impl AnimeApi {
95 let api_response: ApiResponse = response.json()?; 94 let api_response: ApiResponse = response.json()?;
96 Ok(api_response) 95 Ok(api_response)
97 } else { 96 } else {
98 Err(Error) 97 Ok(ApiResponse{
98 data: ResponseData{
99 Page: Page {
100 media: vec![
101 Media{
102 id: 0,
103 title: Title {
104 romaji: String::from("None"),
105 english: Some(String::from("None")),
106 native: String::from("None"),
107 }
108 }
109 ]
110 }
111 }
112 })
99 } 113 }
114
100 } 115 }
101} 116}
102 117
103 118
119
104// pub fn parse_search_anime_anilist(response_text: &String) -> Result<Vec<SkipTime>, Box<dyn Error>>{ 120// pub fn parse_search_anime_anilist(response_text: &String) -> Result<Vec<SkipTime>, Box<dyn Error>>{
105// // Deserialize the JSON into AniskipResponse 121// // Deserialize the JSON into AniskipResponse
106// let parsed_data: AniskipResponse = serde_json::from_str(response_text)?; 122// let parsed_data: AniskipResponse = serde_json::from_str(response_text)?;
src/main.rs +31 −30
@@ -1,13 +1,14 @@
1use anilist::AnimeApi;
1// use std::process::exit; 2// use std::process::exit;
2use curd::aniskip::{get_skip_times, SkipType, SkipTime}; 3use curd::aniskip::{get_skip_times, SkipType, SkipTime};
3use curd::Anime; 4use curd::Anime;
4// mod anilist; 5mod anilist;
5 6
6fn main() { 7fn main() {
7 // let query = "Naruto"; 8 let query = AnimeApi::new(String::from(""));
8 // let token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjY5NTU3NWExMzY5NjE5ZWUxZWYwNTY5OTA0MDUxZDc0NTE5ZTM2MmZmZDViOTI5YjE1YjMwMTBjZWQyNDMyZDJiYmZlNTcxZmMxNGU0OGQ0In0.eyJhdWQiOiIyMDY4NiIsImp0aSI6IjY5NTU3NWExMzY5NjE5ZWUxZWYwNTY5OTA0MDUxZDc0NTE5ZTM2MmZmZDViOTI5YjE1YjMwMTBjZWQyNDMyZDJiYmZlNTcxZmMxNGU0OGQ0IiwiaWF0IjoxNzI3MjcyNDkxLCJuYmYiOjE3MjcyNzI0OTEsImV4cCI6MTc1ODgwODQ5MSwic3ViIjoiNjcxOTUyNiIsInNjb3BlcyI6W119.cpypIpuRu1D0LfNZpKgNVyGGViEVeaB9IZ2zkWcoudfzmrT8xIweYgpCLjK7pCliPFX4UhT3oC8vYh1kwDmUKGkr6TcyJ4zWEDpRVZUZwtT6jt6y9cotNu5Wifk2FRSKQ4R9zLTsrgFRiSxHQC5gMk6-qbVsv94AO77QNIRXNTcjGY0260S-EQFsm988s77yEsWiGL27OJCU6D02ik89mS0vQqdifh3HvnJQI7rJOctg0zRouHSbhj8csevjzOcdU2zjwO669rn9zZZUerA99Sb1fUEQuAt-c7A8TdAJwekdX50bPNOETs-pHxH4maOW_5yV-osTVvdC8WoTSWr8rmGN3pvxhGJ-Z97nCw5L-RCyoJV93DkGZie4esfUPEKoewzB4l6TUtbuUFT0EYF-QD4Wh7dpzBcMXiVJUVyhfEuf25LpFknn3r3L2ATPj9MM-tgGLJQCqHKgEn0MVys6vbZJmYxPNAnQ9wej0hrLno1JoP8ap7obnU8_BG3cx9PDzgRHT_X6goH4V74tgxspt6gIUblDJC4xNjodnKbgrz3CCHNhb_HVWY7OtsdenBn69nNNz1iN4ZzH2ioksYzpfEm0tVoHmzIxGNDRJMe5yPKYO_ccOTviez7uIY4r2w2t9roNt-4pT5UkevKr-vrTKlx_LtlWl42u8KXfv1ta9fY"; // Replace with your token 9 let response = query.search_anime_anilist("One piece");
9 10 println!("{:?}", response);
10 // match anilist::search_anime_anilist(query, token) { 11 // match anilist::AnimeApi::search_anime_anilist(query, ) {
11 // Ok(response) => { 12 // Ok(response) => {
12 // println!("{:#?}", response); 13 // println!("{:#?}", response);
13 // } 14 // }
@@ -16,31 +17,31 @@ fn main() {
16 // } 17 // }
17 // } 18 // }
18 19
19 let mut anime = Anime::new(); 20 // let mut anime = Anime::new();
20 anime.anilist_id(21); 21 // anime.anilist_id(21);
21 anime.watching_ep(2); 22 // anime.watching_ep(2);
22 // let episode_no = 2; 23 // // let episode_no = 2;
23 anime.skip_times( 24 // anime.skip_times(
24 match get_skip_times(anime.anilist_id.unwrap(), anime.watching_ep.unwrap()) { 25 // match get_skip_times(anime.anilist_id.unwrap(), anime.watching_ep.unwrap()) {
25 Ok(skips) => { 26 // Ok(skips) => {
26 skips 27 // skips
27 }, 28 // },
28 Err(_) => { 29 // Err(_) => {
29 println!("Failed to get skip times"); 30 // println!("Failed to get skip times");
30 vec![SkipTime::new(SkipType::Op, 0, 0), SkipTime::new(SkipType::Ed, 0, 0)] 31 // vec![SkipTime::new(SkipType::Op, 0, 0), SkipTime::new(SkipType::Ed, 0, 0)]
31 } 32 // }
32 } 33 // }
33 ); 34 // );
34 35
35 anime.skip_times.map(|anime_skip| { // Would never fail as it would be 0 0 36 // anime.skip_times.map(|anime_skip| { // Would never fail as it would be 0 0
36 for skip in anime_skip { 37 // for skip in anime_skip {
37 if skip.kind == SkipType::Op { 38 // if skip.kind == SkipType::Op {
38 println!("Opening: {} to {}", skip.intervals.start, skip.intervals.end); 39 // println!("Opening: {} to {}", skip.intervals.start, skip.intervals.end);
39 } 40 // }
40 else if skip.kind == SkipType::Ed { 41 // else if skip.kind == SkipType::Ed {
41 println!("Ending: {} to {}", skip.intervals.start, skip.intervals.end); 42 // println!("Ending: {} to {}", skip.intervals.start, skip.intervals.end);
42 } 43 // }
43 } 44 // }
44 }); 45 // });
45 46
46}\ No newline at end of file 47}\ No newline at end of file