#api-wrapper #api #hydrus

hydrus-api

A rust wrapper for the hydrus client api

18 releases (8 breaking)

0.9.3 May 14, 2022
0.9.1 Apr 7, 2022
0.8.0 Mar 29, 2022
0.6.0 Sep 5, 2021
0.4.0 Jul 31, 2021

#5 in #api-wrapper

Download history 5/week @ 2022-12-01 28/week @ 2022-12-08 13/week @ 2022-12-15 12/week @ 2022-12-22 10/week @ 2022-12-29 8/week @ 2023-01-05 9/week @ 2023-01-12 24/week @ 2023-01-19 26/week @ 2023-01-26 18/week @ 2023-02-02 38/week @ 2023-02-09 71/week @ 2023-02-16 17/week @ 2023-02-23 8/week @ 2023-03-02 13/week @ 2023-03-09 43/week @ 2023-03-16

84 downloads per month
Used in 2 crates

Apache-2.0

135KB
3.5K SLoC

Hydrus Rust API

This is a WIP Rust Wrapper for the Hydrus Client API. The official API documentation can be found here.

Example with Wrapper

use std::env;
use hydrus_api::api_core::searching_and_fetching_files::FileSearchLocation;
use hydrus_api::wrapper::tag::Tag;
use hydrus_api::wrapper::service::ServiceName;
use hydrus_api::wrapper::hydrus_file::FileStatus;
use hydrus_api::wrapper::page::PageIdentifier;
use hydrus_api::wrapper::builders::search_builder::SortType;
use hydrus_api::wrapper::builders::or_chain_builder::OrChainBuilder;
use hydrus_api::wrapper::builders::tag_builder::{
    SystemTagBuilder, Comparator
};

#[tokio::main]
async fn main() {
    let hydrus_url = env::var("HYDRUS_URL").unwrap();
    let access_key = env::var("HYDRUS_ACCESS_KEY").unwrap();
    
    let hydrus = Hydrus::new(Client::new(hydrus_url, access_key));
    let files = hydrus.search()
        .add_tag(Tag::from("character:megumin"))
        .add_tag(SystemTagBuilder::new().archive().build())
        .add_tag(SystemTagBuilder::new().number_of_tags(Comparator::Greater, 12).build())
        .add_or_chain(
            OrChainBuilder::new()
                .add_tag("summer".into())
                .add_tag("winter".into())
                .build(),
        )
        .sort(SortType::ModifiedTime)
        .run().await.unwrap();

    for mut file in files {
        file.add_tags(ServiceName::my_tags().into(), vec![Tag::from("ark mage")]).await.unwrap();
    }

    let url = hydrus.import()
        .url("https://www.pixiv.net/member_illust.php?illust_id=83406361&mode=medium")
        .page(PageIdentifier::name("My Import Page"))
        .add_additional_tag(ServiceName::my_tags().into(), Tag::from("character:megumin"))
        .show_page(true)
        .run().await.unwrap();
}

Example with Client

use hydrus_api::Client;
use hydrus_api::paths::adding_tags::{AddTagsRequestBuilder, TagAction};
use std::env;
use hydrus_api::api_core::common::ServiceIdentifier;

#[tokio::main]
async fn main() {
    Client::new(
        env::var("HYDRUS_URL").unwrap(),
        env::var("HYDRUS_ACCESS_KEY").unwrap(),
    );
    // let's first import a file
    let hash = client.add_file("/path/to/my/file").await.unwrap().hash;
    
    // and now let's add tags to it
    let request = AddTagsRequestBuilder::default()
        .add_hash(hash)
        // for each tag the service has to be specified
        .add_tags(ServiceIdentifier::name("my tags"), vec!["beach".into(), "summer".into()])
        // with tag actions tags can also be removed. It's especially useful for the PTR
        .add_tag_with_action(ServiceIdentifier::name("my tags"), "rain", TagAction::DeleteFromLocalService)
        .build();
    
    client.add_tags(request).await.unwrap();
}

License

Apache-2.0

Dependencies

~6–15MB
~331K SLoC