Crates.io | jw_client |
lib.rs | jw_client |
version | 1.0.0 |
source | src |
created_at | 2024-10-31 01:50:41.155125 |
updated_at | 2024-11-05 15:32:30.51085 |
description | A simple API wrapper for the JW Player media management API. List or stream library into native Rust structs and download renditions. |
homepage | |
repository | |
max_upload_size | |
id | 1429516 |
size | 20,423 |
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.
Add this crate to your Cargo.toml
:
[dependencies]
jw_client = "1.0.0"
Ensure that you have an API key from JW Player and the necessary permissions to access the media management API.
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);
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;
For large libraries, retrieve items in streamed chunks:
use tokio_stream::StreamExt;
let mut streamed_data = client.get_library_stream(Some(200), Some("tags: NOT ( cherries )".to_string())).await;
while let Some(Ok(items)) = streamed_data.next().await {
for media in items.media {
println!("{:?}", media.id);
}
}
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;
}
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)
}
}
This project is licensed under the MIT License.