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"
103103name = "curd"
104104version = "0.1.0"
105105dependencies = [
106 "json",
106107 "reqwest",
107108 "serde",
108109 "serde_json",
@@ -421,6 +422,12 @@ dependencies = [
421422 "wasm-bindgen",
422423]
423424
425[[package]]
426name = "json"
427version = "0.12.4"
428source = "registry+https://github.com/rust-lang/crates.io-index"
429checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd"
430
424431[[package]]
425432name = "libc"
426433version = "0.2.159"
Cargo.toml +3 −2
@@ -4,7 +4,8 @@ version = "0.1.0"
44edition = "2021"
55
66[dependencies]
7reqwest = { version = "0.12.8", features = ["blocking"] }
7json = "0.12.4"
8reqwest = { version = "0.12.8", features = ["blocking", "json"] }
89serde = {version = "1.0.210", features = ["derive"] }
910serde_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
21use reqwest::{header::{HeaderMap, HeaderValue, AUTHORIZATION, CONTENT_TYPE}, Error};
32use serde::{Serialize, Deserialize};
43
@@ -37,12 +36,12 @@ struct ResponseData {
3736}
3837
3938#[derive(Deserialize, Debug)]
40struct ApiResponse {
41 data: ResponseData,
39pub struct ApiResponse {
40 pub data: ResponseData,
4241}
4342
4443pub struct AnimeApi {
45 token: String,
44 pub token: String,
4645}
4746
4847impl AnimeApi {
@@ -95,12 +94,29 @@ impl AnimeApi {
9594 let api_response: ApiResponse = response.json()?;
9695 Ok(api_response)
9796 } 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 })
99113 }
114
100115 }
101116}
102117
103118
119
104120// pub fn parse_search_anime_anilist(response_text: &String) -> Result<Vec<SkipTime>, Box<dyn Error>>{
105121// // Deserialize the JSON into AniskipResponse
106122// let parsed_data: AniskipResponse = serde_json::from_str(response_text)?;
src/main.rs +31 −30
@@ -1,13 +1,14 @@
1use anilist::AnimeApi;
12// use std::process::exit;
23use curd::aniskip::{get_skip_times, SkipType, SkipTime};
34use curd::Anime;
4// mod anilist;
5mod anilist;
56
67fn main() {
7 // let query = "Naruto";
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
10 // match anilist::search_anime_anilist(query, token) {
8 let query = AnimeApi::new(String::from(""));
9 let response = query.search_anime_anilist("One piece");
10 println!("{:?}", response);
11 // match anilist::AnimeApi::search_anime_anilist(query, ) {
1112 // Ok(response) => {
1213 // println!("{:#?}", response);
1314 // }
@@ -16,31 +17,31 @@ fn main() {
1617 // }
1718 // }
1819
19 let mut anime = Anime::new();
20 anime.anilist_id(21);
21 anime.watching_ep(2);
22 // let episode_no = 2;
23 anime.skip_times(
24 match get_skip_times(anime.anilist_id.unwrap(), anime.watching_ep.unwrap()) {
25 Ok(skips) => {
26 skips
27 },
28 Err(_) => {
29 println!("Failed to get skip times");
30 vec![SkipTime::new(SkipType::Op, 0, 0), SkipTime::new(SkipType::Ed, 0, 0)]
31 }
32 }
33 );
20 // let mut anime = Anime::new();
21 // anime.anilist_id(21);
22 // anime.watching_ep(2);
23 // // let episode_no = 2;
24 // anime.skip_times(
25 // match get_skip_times(anime.anilist_id.unwrap(), anime.watching_ep.unwrap()) {
26 // Ok(skips) => {
27 // skips
28 // },
29 // Err(_) => {
30 // println!("Failed to get skip times");
31 // vec![SkipTime::new(SkipType::Op, 0, 0), SkipTime::new(SkipType::Ed, 0, 0)]
32 // }
33 // }
34 // );
3435
35 anime.skip_times.map(|anime_skip| { // Would never fail as it would be 0 0
36 for skip in anime_skip {
37 if skip.kind == SkipType::Op {
38 println!("Opening: {} to {}", skip.intervals.start, skip.intervals.end);
39 }
40 else if skip.kind == SkipType::Ed {
41 println!("Ending: {} to {}", skip.intervals.start, skip.intervals.end);
42 }
43 }
44 });
36 // anime.skip_times.map(|anime_skip| { // Would never fail as it would be 0 0
37 // for skip in anime_skip {
38 // if skip.kind == SkipType::Op {
39 // println!("Opening: {} to {}", skip.intervals.start, skip.intervals.end);
40 // }
41 // else if skip.kind == SkipType::Ed {
42 // println!("Ending: {} to {}", skip.intervals.start, skip.intervals.end);
43 // }
44 // }
45 // });
4546
4647}
\ No newline at end of file