#request-url #json-response #api-url #parse-json #download #content #r34

yanked r34_api

Create Request Urls for the R34 API and parse the Json Responses

5 releases

0.3.0 May 5, 2024
0.2.62 Apr 20, 2024
0.2.7 May 5, 2024

#10 in #request-url

Download history 17/week @ 2024-07-25 4/week @ 2024-08-01 15/week @ 2024-09-19 7/week @ 2024-09-26

421 downloads per month

MIT/Apache

24KB
402 lines

R34 API Library

The only R34 Rust Lib you need! (Just kidding😜)

With this lil library you can easily generate R34 api urls and parse json responses so you can use them to download content from R34.

There is an example inside the documentation. I hope it's easy to understand.

Projects with this Junk

I made an R34 Downloader that kinda works but has no certificate or anything. https://github.com/NunjaUwU/r34-board-downloader/tree/master


lib.rs:

Disclaimer: I made this lil library just for fun, with only a few features, so I wouldnt recommend using it. But if you use it anyway have fun :>.

There may be some parts where you need to know the R34 API, I probably forgot something 🤷‍♂️. So check out R34's API

https://api.rule34.xxx/

Lil example

use std::fs;
use r34_api as r34;
use reqwest;

#[tokio::main]
async fn main() {
    // First we make a new Api Url.
    // We add the 'big_boobs' tag and a post limit of one so only one
    // post will be returned and convert the ApiUrl type into a String.
    let request_url = r34::ApiUrl::new().add_tag("big_boobs").set_limit(1).to_api_url();

    // Next we send our request to R34's API.
    let api_response = reqwest::get(request_url).await.unwrap();

    // We then parse the json response and get a Vector with Post's.
    let posts: Vec<r34::Post> = r34::R34JsonParser::default().from_api_response(api_response).unwrap();

    // Here we get the filename and url of the post's file.
    let post_file_url = &posts[0].file_url;
    let post_file_name = &posts[0].image;

    // Now we Download the file
    let file_as_bytes = reqwest::get(post_file).await.unwrap().bytes().await.unwrap();
    // Define its path
    let path = format!("./{}", post_file_name);
    // And save it.
    fs::File::create(path).unwrap().write_all(&file_as_bytes).unwrap();
}    

Dependencies

~0.5–1MB
~20K SLoC