#live #stream #tiktok #api #api-bindings #reverse-engineering

bin+lib tiktoklive

A Rust library. Use it to receive live stream events such as comments and gifts in realtime from TikTok LIVE No credentials are required.

3 releases

0.0.5 Jan 6, 2024
0.0.4 Jan 4, 2024
0.0.1 Jan 4, 2024

#1413 in Network programming

Download history 10/week @ 2024-01-03 1/week @ 2024-02-14 8/week @ 2024-02-21 18/week @ 2024-02-28 13/week @ 2024-03-27 29/week @ 2024-04-03 51/week @ 2024-04-10

93 downloads per month

MIT/Apache

2MB
46K SLoC

TikTok Live Rust

❤️❤️🎁 Connect to TikTok live in 3 lines 🎁❤️❤️

Introduction

A Rust library. Use it to receive live stream events such as comments and gifts in realtime from TikTok LIVE No credentials are required.

Join the support discord and visit the #rust-support channel for questions, contributions and ideas. Feel free to make pull requests with missing/new features, fixes, etc

Do you prefer other programming languages?

NOTE: This is not an official API. It's a reverse engineering project.

Overview

Getting started

[dependencies]
 tiktoklive = "0.0.1"
#[tokio::main]
async fn main() {
    let user_name = "dash4214";
    let mut client = TikTokLive::new_client(user_name)
        .configure(configure)
        .on_event(handle_event)
        .build();

    client.connect().await;

    let mut input = String::new();
    if io::stdin().read_line(&mut input).is_ok() && input.trim() == "stop"
    {
        //client.disconnect();
    }
}

fn handle_event(client: &TikTokLiveClient, event: &TikTokLiveEvent)
{
    match event {
        TikTokLiveEvent::OnMember(joinEvent) =>
            {
                println!("user: {}  joined", joinEvent.raw_data.user.nickname);
            }
        TikTokLiveEvent::OnChat(chatEvent) =>
            {
                println!("user: {} -> {} ", chatEvent.raw_data.user.nickname, chatEvent.raw_data.content);
            }
        TikTokLiveEvent::OnGift(giftEvent) =>
            {
                let nick = &giftEvent.raw_data.user.nickname;
                let gift_name = &giftEvent.raw_data.gift.name;
                let gifts_amount = giftEvent.raw_data.gift.combo;

                println!("user: {} sends gift: {} x {}", nick, gift_name, gifts_amount);
            }
        _ => {}
    }
}

fn configure(settings: &mut TikTokLiveSettings)
{
    settings.http_data.time_out = Duration::from_secs(12);
}

Contributing

Your improvements are welcome! Feel free to open an issue or pull request.

Dependencies

~27–43MB
~514K SLoC