#media #download #stream #player #api #api-client #management

jw_client

A simple API wrapper for the JW Player media management API. List or stream library into native Rust structs and download renditions.

3 releases (breaking)

new 0.5.0 Nov 4, 2024
0.4.0 Oct 31, 2024
0.3.0 Oct 31, 2024
0.2.0 Oct 31, 2024
0.1.0 Oct 31, 2024

#738 in Web programming

Download history 488/week @ 2024-10-28

488 downloads per month

MIT/Apache

20KB
367 lines

JW Player Media Management API Wrapper

A Rust library that provides an API wrapper for the JW Player media management. This wrapper allows users to query their media library, filter results by tags, stream large libraries in manageable chunks, and download specific video renditions.

Features

  • Query Media Library: Fetch details about all media items in your JW Player library.
  • Keyword Filtering: Filter media items based on keywords.
  • Stream Large Libraries: Efficiently stream large collections by retrieving items in chunks.
  • Download Renditions: Download specific video renditions with ease.
  • Delete Media: Delete specific video fromt the library.

Installation

Add this crate to your Cargo.toml:

[dependencies]
jw_client = "0.5.0"

Usage

Ensure that you have an API key from JW Player and the necessary permissions to access the media management API.

1. Set Up API Client

Initialize the API client with your JW API key and site id:

let token = std::env::var("JW_TOKEN").expect("JW_TOKEN must be set.");
let site_id = std::env::var("JW_SITE_ID").expect("JW_SITE_ID must be set.");

let client = Client::new(&token, &site_id);

2. Query the Media Library

Retrieve a static chunk of most recent JW library items, max 10k videos:

let default_response = client.get_library(None).await; //returns 10 items

let different_size_response = client.get_library(Some(42)).await; //sets return size to 42

let tags_include = client.get_library_by_tags(vec!["cherries"], None).await;

let tag_exclude = client.get_library_excluding_tags(vec!["cherries"], None).await;

3. Stream Media in Chunks

For large libraries, retrieve items in streamed chunks:

use tokio_stream::StreamExt;

let mut streamed_data = client.get_library_stream(Some(200)).await;
while let Some(Ok(items)) = streamed_data.next().await {
    for media in items.media {
        println!("{:?}", media.id);
    }
}

4. Download a Video Rendition

Download a specific rendition for a video:

let ten_videos = client.get_library(None).await.unwrap().unwrap();
for media in ten_videos.media {
    client.download(&media.id, "./").await;
}

5. Delete a Video

Delete a specific media entry - CAUTION this action cannot be undone.

let resp = client.delete_meida("XYZ12345").await;
match resp {
    Ok(()) => {
        println!("DELETED")
    }
    Err(e) => {
        println!("{}", e)
    }
}

License

This project is licensed under the MIT License.

Dependencies

~7–18MB
~234K SLoC