Rust library for interacting with the VTube Studio API

Overview

vtubestudio-rs

crates.io docs.rs MIT licensed

A library for interacting with the VTube Studio API.

Basic usage

This example creates a Client using the provided builder, which:

  • connects to ws://localhost:8001 using tokio_tungstenite
  • authenticates with an existing token (if present and valid)
  • reconnects when disconnected, and retries the failed request on reconnection success
  • requests a new auth token on receiving an auth error, and retries the initial failed request on authentication success
use vtubestudio::{Client, Error};
use vtubestudio::data::StatisticsRequest;

#[tokio::main]
async fn main() -> Result<(), Error> {
    // An auth token from a previous successful authentication request
    let stored_token = Some("...".to_string());

    let (mut client, mut new_tokens) = Client::builder()
        .auth_token(stored_token)
        .authentication("Plugin name", "Developer name", None)
        .build_tungstenite();

    tokio::spawn(async move {
        // This returns whenever the authentication middleware receives a new auth token.
        // We can handle it by saving it somewhere, etc.
        while let Some(token) = new_tokens.next().await {
            println!("Got new auth token: {}", token);
        }
    });

    // Use the client to send a `StatisticsRequest`, handling authentication if necessary.
    // The return type is inferred from the input type to be `StatisticsResponse`.
    let resp = client.send(&StatisticsRequest {}).await?;
    println!("VTube Studio has been running for {}ms", resp.uptime);

    Ok(())
}

For more details, please check the documentation on docs.rs.

Comments
  • API changes in 1.20.7-beta

    API changes in 1.20.7-beta

    Summary of changes: https://discord.com/channels/652602255748497449/832061334531211276/995815107600855112

    VTube Studio 1.20.7 is now on the beta branch (see above for information on how to access it).

    This update brings some big changes to the VTube Studio API, including the first part of the Item API.

    1. Added functionality to request list of hotkeys in a Live2D item using the new field live2DItemFileName in the HotkeysInCurrentModelRequest. https://github.com/DenchiSoft/VTubeStudio#requesting-list-of-hotkeys-available-in-current-or-other-vts-model

    2. Added functionality to trigger hotkeys in Live2D Items using the new optional field itemInstanceID in the HotkeyTriggerRequest. https://github.com/DenchiSoft/VTubeStudio#requesting-execution-of-hotkeys

    3. Added "add" mode for the InjectParameterDataRequest (new mode field), which allows multiple plugins to add values to a given parameter. This makes it possible for multiple plugins to work together without interfering with each other, for example external tracker plugins and bonk-type plugins. In general, the parameter value injection code has been rewritten from scratch, so if your plugin uses this request, please make sure it still works (there should be no issues). https://github.com/DenchiSoft/VTubeStudio#feeding-in-data-for-default-or-custom-parameters

    4. Item API: ItemListRequest, returns a list of items in the scene (or a list of available items in the user's "Items" folder). https://github.com/DenchiSoft/VTubeStudio#requesting-list-of-available-items-or-items-in-scene

    5. Item API: ItemLoadRequest, loads items of any type into the scene. https://github.com/DenchiSoft/VTubeStudio#loading-item-into-the-scene

    6. Item API: ItemUnloadRequest, unloads items currently loaded into the scene. https://github.com/DenchiSoft/VTubeStudio#removing-item-from-the-scene

    7. Item API: ItemAnimationControlRequest, controls item animations and other stuff like item brightness and transparency (for example for reactive-PNG type plugins). https://github.com/DenchiSoft/VTubeStudio#controling-items-and-item-animations

    8. Item API: ItemMoveRequest, moves around items in the scene using various movement modes. https://github.com/DenchiSoft/VTubeStudio#moving-items-in-the-scene

    Documentation diff: https://github.com/DenchiSoft/VTubeStudio/compare/13827014c4d3e401fa429bd2b5976f128203e147..1be2dc5f4b3ac6b6c5b010566618991405a6ba87

    opened by walfie 2
  • `Service` layer for rewriting request IDs

    `Service` layer for rewriting request IDs

    The request IDs sent back to the client in the ResponseEnvelope might not always match up with the original RequestEnvelope if there were additional requests made by the retry/auth middleware.

    This typically doesn't matter since users will be using Client which doesn't expose the response envelopes, but advanced use cases might want a layer that rewrites IDs.

    wontfix 
    opened by walfie 2
  • Add feature flags for websocket libraries

    Add feature flags for websocket libraries

    tokio_tungstenite is currently used by default, but it should be optional. We might also want to add an awc implementation as an example.

    These libraries should be toggleable as features, with tokio_tungstenite enabled by default.

    opened by walfie 2
  • Some feature labels not showing up on docs.rs

    Some feature labels not showing up on docs.rs

    The label that says:

    This is supported on crate feature tokio-tungstenite only.

    isn't showing up on all pages. Probably due to the weird way I structured the cfg metadata in the modules.

    E.g., it shows for some items here: https://docs.rs/vtubestudio/0.2.0/vtubestudio/transport/index.html

    doesn't show up here (intra-doc links also not working): https://docs.rs/vtubestudio/0.2.0/vtubestudio/codec/index.html

    opened by walfie 1
  • Use serde_json's `RawValue` instead of `Value`

    Use serde_json's `RawValue` instead of `Value`

    Currently RequestEnvelope and ResponseEnvelope use serde_json::Value to store arbitrary JSON data.

    Considering the primary use case of using an opaque value is to defer deserialization, and to allow for serializing/deserializing custom types defined outside this library, we might want to use RawValue instead.

    This would avoid the intermediate values (especially since the retry and auth middleware can clone these values). Users can still serialize/deserialize the raw value to a Value if necessary.

    opened by walfie 1
  • Use enums for error IDs and hotkey types

    Use enums for error IDs and hotkey types

    Error IDs: https://github.com/DenchiSoft/VTubeStudio/blob/master/Files/ErrorID.cs Hotkey types: https://github.com/DenchiSoft/VTubeStudio/blob/master/Files/HotkeyAction.cs

    There should be a variant in the enum that accepts a raw value (i32 or string) to be forward compatible, when new variants are added. Equality checks should also consider forward compatibility.

    Message types could also be enums.

    opened by walfie 1
  • Use original inner service in auth service call

    Use original inner service in auth service call

    Make sure to use the original service, rather than the cloned one, since the cloned instance may not be ready.

    https://docs.rs/tower/0.4.13/tower/trait.Service.html#be-careful-when-cloning-inner-services

    opened by walfie 0
  • Add new message types (up to date as of v1.21.11)

    Add new message types (up to date as of v1.21.11)

    Includes new fields for some existing messages, and adds these new messages:

    • ItemList{Request,Response}
    • ItemLoad{Request,Response}
    • ItemUnload{Request,Response}
    • ItemAnimationControl{Request,Response}
    • ItemMove{Request,Response}
    • ArtMeshSelection{Request,Response}

    The last one is still in beta so it might change.

    opened by walfie 0
  • Add Events API

    Add Events API

    https://github.com/DenchiSoft/VTubeStudio/tree/cbf875f9d16f868d57e9921235a129cf2f756a4d/Events

    ~~Also consider automatically resubscribing to events on reconnect.~~

    opened by walfie 0
  • Add new types for physics override requests

    Add new types for physics override requests

    Adds the following types:

    • GetCurrentModelPhysicsRequest
    • GetCurrentModelPhysicsResponse
    • SetCurrentModelPhysicsRequest
    • SetCurrentModelPhysicsResponse

    as well as some new error IDs.

    Closes #50

    opened by walfie 0
  • Change type of `color_overlay_{r,g,b}` fields

    Change type of `color_overlay_{r,g,b}` fields

    I mistakenly set them to u8 thinking the values would be between 0 and 255. According to the docs, they can go up to 459:

    This may produce values as high as 2 * 255 for R, G and B. The values are capped at 1.8 * 255 = 459.

    While u16 might be a tighter fit in terms of the number range, setting them to i32 allows for more flexibility.

    opened by walfie 0
Releases(v0.8.0)
  • v0.8.0(Oct 29, 2022)

    • 8ec9005 Add events API (#57)

    Events API

    Check the events example to see how to use VTube Studio's new events API.

    Breaking Changes

    The stream returned by ClientBuilder used to return new auth tokens as Strings, but it now returns ClientEvents. Tokens can now be found as ClientEvent::NewAuthTokens.

    Here is an example of updating existing code to handle the new events:

    - let (mut client, mut tokens) = Client::builder()
    + let (mut client, mut events) = Client::builder()
          .auth_token(stored_token)
          .authentication("Plugin name", "Developer name", None)
          .build_tungstenite();
    
      tokio::spawn(async move {
    -     while let Some(new_token) = tokens.next().await {
    -         println!("Got new auth token: {new_token}");
    -     }
    +     while let Some(event) = events.next().await {
    +         match event {
    +             ClientEvent::NewAuthToken(new_token) => {
    +                 println!("Got new auth token: {new_token}");
    +             }
    +             _ => {
    +                 // Other events, such as connections/disconnections, API events, etc
    +                 println!("Got event: {:?}", event);
    +             }
    +         }
    +     }
      });
    

    There are some other breaking changes for the underlying transport and service types, but most people are using the default ClientBuilder and will probably not need to make any changes besides the token handler mentioned above.

    Source code(tar.gz)
    Source code(zip)
  • v0.7.0(Sep 19, 2022)

    • 8d02684 Add new message types (up to date as of v1.21.11) (#56)

    Includes new fields for some existing messages, and adds these new messages:

    • ItemList{Request,Response}
    • ItemLoad{Request,Response}
    • ItemUnload{Request,Response}
    • ItemAnimationControl{Request,Response}
    • ItemMove{Request,Response}
    • ArtMeshSelection{Request,Response}

    The last one is still in beta so it might change.

    Source code(tar.gz)
    Source code(zip)
  • v0.6.1(Jun 18, 2022)

  • v0.6.0(Apr 30, 2022)

  • v0.5.1(Feb 20, 2022)

  • v0.5.0(Feb 5, 2022)

    • b22db67 Add new hotkey enum variant and description field (#46)
    • 917d821 Add docs for all request/response fields (#47)
    • 4b41813 Change type of color_overlay_{r,g,b} fields (#48)
    • 30dc282 Add new expression/NDI types (#49)
    Source code(tar.gz)
    Source code(zip)
  • v0.4.0(Nov 21, 2021)

    • 87d7ca2 Change added_by field to be optional (#42)
    • 231d22e Add into_inner methods for service wrappers (#43)
    • 2a586f4 Attempt to authenticate on initial connection (#44)
    • 21691dc Add debug logging for auth/retry middleware (#45)
    Source code(tar.gz)
    Source code(zip)
  • v0.3.2(Nov 21, 2021)

  • v0.3.1(Nov 21, 2021)

  • v0.3.0(Nov 19, 2021)

    • bc208c7 Add docs.rs link to the end of README.md
    • c2e6af4 Add the README.md example as a runnable example (#35)
    • 612bce4 Preserve input request ID if specified (#36)
    • 2463941 Add example for manually constructing a client (#37)
    • f5adbdf Use tower's BoxCloneService, remove re-exports. (#38)
    • 9640d22 Add example for triggering hotkeys (#39)
    Source code(tar.gz)
    Source code(zip)
  • v0.2.1(Nov 16, 2021)

    • 095315a Fix feature labels in docs (#30)
    • f28a013 Add docs for all request/response types (#31)
    • 3eb6112 Use smol_str for request ID strings (#32)
    • 8825892 Add spin example (#33)
    • a5153c5 Fix MoveModelRequest issue where model is reset (#34)
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Nov 15, 2021)

    • d85f608 Loosen dependency requirements (#15)
    • efe0683 Add tokio-tungstenite feature (#16)
    • a69bb67 Refactor codec to allow distinct input/output types (#17)
    • 1fb5594 Ignore tungstenite examples if feature disabled (#18)
    • 021bb48 Use enums for message_type field (#19)
    • bd99172 Refactor request/response type enums (#20)
    • d7a14fa Add ErrorId type (#21)
    • 577f42f Add HotkeyAction enum (#22)
    • 9a30ebc Expose generic EnumString helper (#23)
    • 690f34d Refactor ResponseEnvelope to eagerly parse API errors (#24)
    • eddb63e Use newtype wrapper for request ID (#25)
    • 71186ba Use serde_json::value::RawValue (#26)
    • d37122e Prepare for 0.2.0 release (#27)
    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Nov 12, 2021)

Owner
null
An opinionated Rust library for interacting with AWS DynamoDB single-table designs.

Modyne An opinionated library for interacting with AWS DynamoDB single-table designs. † Motive Modyne follows the precepts laid out for effective sing

Marcus Griep 14 Jun 8, 2023
A group of Rust projects for interacting with and producing software bill of materials (SBOMs).

sbom-rs A group of Rust projects for interacting with and producing software bill of materials (SBOMs). Examples cargo-sbom Create a SPDX SBOM for a C

Paul Sastrasinh 2 Jul 10, 2023
Utilities for interacting with the Behringer X-Touch Mini MIDI controller

xtouchmini Collection of utilities for interacting with the Behringer X-Touch Mini MIDI controller, including reading button/knob/fader inputs and sen

null 5 Nov 11, 2021
Femtorinth is a library to interact with a sub-set of the Modrinth API.

Femtorinth Femtorinth is a rust library to interact with a sub-set of the Modrinth api, it only includes the api calls that don't need auth (a.k.a onl

null 2 May 6, 2022
This article is about the unsound api which I found in owning_ref. Owning_ref is a library that has 11 million all-time downloads and 60 reverse dependencies.

Unsoundness in owning_ref This article is about the unsound api which I found in owning_ref. Owning_ref is a library that has 11 million all-time down

Noam Ta Shma 20 Aug 3, 2022
A simple omegle API written in Rust

omegalul-rs omegalul-rs is a work-in-progress opensource library for building Omegle clients. Features Current Features Fetching random server from om

NV6 5 Jun 21, 2022
High level rust abstractions for the libretro API

libretro-rs Design Philosophy The approach to this crate can best be summarized as wanting to expose all functionality, even if not idiomatically. The

null 9 Dec 25, 2022
⚡️ Fast MagicString port driven by Rust and N-API

magic-string-rs 100% API compatible (port) MagicString by Rich-Harris implementation for Node and modern browsers, also, for rust, of course. Installa

Hana 35 Nov 21, 2022
ncnn Rust API.

rust-ncnn ncnn Rust API. Prequisition Rust Env $ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh CMake >= 3.12 Rust cmake needs --paral

null 11 Dec 27, 2022
Rust crate for creating filters with DirectX shaders. Includes Scale, Color conversion using DirectX api.

DxFilter Scale and ColorConversion done with DirectX filters. You can also create your own filters with the provided api. Crate contains various tools

null 4 Aug 13, 2022
Examples of how to use Rust with Serverless Framework, Lambda, API Gateway v1 and v2, SQS, GraphQL, etc

Rust Serverless Examples All examples live in their own directories: project: there is nothing here, just a simple cargo new project_name with a custo

Fernando Daciuk 9 Dec 17, 2022
prelate-rs is an idiomatic, asynchronous Rust wrapper around the aoe4world API. Very much a WIP at this stage.

prelate-rs is an idiomatic, asynchronous Rust wrapper around the aoe4world API. Very much a WIP at this stage. Project Status We currently support the

William Findlay 4 Dec 29, 2022
An ActivityPub home server written in Rust, implementing the Mastodon API.

Tafarn An ActivityPub home server written in Rust, implementing the Mastodon API. At present no web UI is provided, the API is the only way to interac

✨ Q (it/its) ✨ 12 Jan 22, 2023
Rust wrapper for the Google Places API. Access their hundreds of millions of places, reviews, and ratings.

Google Places API Working Examples cargo run --example nearby_search cargo run --example place_details cargo run --example find_place cargo run --exam

Jared Ucherek 4 Jun 12, 2023
A scrapper that abstracts the IQ Option API calls into a Rust package.

IQ Option API - In Rust An abstraction of IQ Options API calls in a Rust library. License Licensed under either of MIT license (LICENSE-MIT or https:/

Vinícius Roque 8 Jul 17, 2023
Rust API deployed on Vercel.

This project is a Rust API deployed on Vercel. It is designed for users to build Rust code which can then be called using POST requests. This repository is an easy to use Rust-Vercel API that can be amended for your own requirements.

Ellie Sleightholm 3 Feb 28, 2024
Simple fake AWS Cognito User Pool API server for development.

Fakey Cognito ?? Homepage Simple fake AWS Cognito API server for development. ✅ Implemented features AdminXxx on User Pools API. Get Started # run wit

naokirin 4 Aug 30, 2022
C API to SpringQL (for embedded mode)

SpringQL C Client This repository is a C client for SpringQL and provides it provides: springql.h: C header file. libspringql_client.{so,dylib}: Share

SpringQL 4 Jun 8, 2022
Stream-based FSEvents API bindings.

fsevent-stream Stream-based FSEvents API bindings. Features Support directory-granular and file-granular events. Retrieve related file inode with kFSE

LightQuantum 7 Dec 28, 2022