- Implement core Rust backend with FFmpeg integration - Add TheTVDB API client with token caching - Implement directory scanner with progress callbacks - Create file manager with rename and move operations - Add audit logging functionality - Implement file mapping for TV episode renaming - Build Node.js native addon via NAPI - Include comprehensive unit and integration tests - Update gitignore to exclude build artifacts and temp files Resolves #TBD
102 lines
3.7 KiB
Rust
102 lines
3.7 KiB
Rust
//! Example: TVDB API Integration
|
|
//!
|
|
//! This example demonstrates how to use the TVDB API to search for shows
|
|
//! and retrieve show details and episode information.
|
|
|
|
use movie_mapper::service::TVDBClient;
|
|
use std::env;
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
// Get API key from environment variable
|
|
let api_key = env::var("TVDB_API_KEY").expect("TVDB_API_KEY environment variable must be set");
|
|
|
|
println!("Using TVDB API with key: {}...", &api_key[..8]);
|
|
|
|
// Create TVDB client
|
|
let mut tvdb = TVDBClient::new(&api_key).expect("Failed to create TVDB client");
|
|
|
|
// Authenticate
|
|
println!("\nAuthenticating...");
|
|
tvdb.authenticate().await.expect("Authentication failed");
|
|
println!("✅ Authentication successful");
|
|
|
|
// Get search query from command line or use default
|
|
let query = env::args()
|
|
.nth(1)
|
|
.unwrap_or_else(|| "Breaking Bad".to_string());
|
|
|
|
println!("\nSearching for: '{}'", query);
|
|
|
|
// Search for shows
|
|
match tvdb.search(&query).await {
|
|
Ok(shows) => {
|
|
if shows.is_empty() {
|
|
println!("No shows found matching '{}'", query);
|
|
return;
|
|
}
|
|
|
|
println!("\nFound {} show(s):", shows.len());
|
|
|
|
for show in &shows {
|
|
println!("\n ID: {}", show.id);
|
|
println!(" Name: {}", show.series_name);
|
|
println!(" Status: {}", show.status);
|
|
println!(" First Aired: {:?}", show.first_aired);
|
|
println!(
|
|
" Overview: {}",
|
|
show.overview.chars().take(100).collect::<String>()
|
|
);
|
|
}
|
|
|
|
// Get details for first show
|
|
let first_show = &shows[0];
|
|
println!("\n\nGetting details for '{}':", first_show.series_name);
|
|
|
|
match tvdb.get_show_details(first_show.id).await {
|
|
Ok(details) => {
|
|
println!("\n Name: {}", details.name);
|
|
println!(" Status: {}", details.status);
|
|
println!(" First Aired: {:?}", details.first_aired);
|
|
println!(
|
|
" Overview: {}",
|
|
details.overview.chars().take(200).collect::<String>()
|
|
);
|
|
println!(" Image URL: {}", details.image);
|
|
println!(" Seasons: {}", details.seasons.len());
|
|
|
|
// Get episodes for first season
|
|
if !details.seasons.is_empty() {
|
|
let first_season = &details.seasons[0];
|
|
println!("\n Getting episodes for Season {}...", first_season.number);
|
|
|
|
match tvdb
|
|
.get_season_episodes(first_show.id, first_season.number)
|
|
.await
|
|
{
|
|
Ok(episodes) => {
|
|
println!("\n Found {} episode(s):", episodes.len());
|
|
for episode in &episodes {
|
|
println!(
|
|
" S{:02}E{:02} - {}",
|
|
first_season.number, episode.number, episode.name
|
|
);
|
|
}
|
|
}
|
|
Err(e) => {
|
|
eprintln!(" Error getting episodes: {}", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Err(e) => {
|
|
eprintln!(" Error getting show details: {}", e);
|
|
}
|
|
}
|
|
}
|
|
Err(e) => {
|
|
eprintln!("Error searching TVDB: {}", e);
|
|
}
|
|
}
|
|
}
|