use anyhow::Result;
use yt_transcript_rs::api::YouTubeTranscriptApi;
#[tokio::main]
async fn main() -> Result<()> {
println!("YouTube Microformat Data Example");
println!("--------------------------------");
let api = YouTubeTranscriptApi::new(None, None, None)?;
let video_id = "arj7oStGLkU";
println!("Fetching microformat data for: {}", video_id);
match api.fetch_microformat(video_id).await {
Ok(microformat) => {
println!("\nMicroformat Data:");
println!("-----------------");
if let Some(title) = µformat.title {
println!("Title: {}", title);
}
if let Some(channel_name) = µformat.owner_channel_name {
println!("Channel: {}", channel_name);
if let Some(profile_url) = µformat.owner_profile_url {
println!("Channel URL: {}", profile_url);
}
if let Some(channel_id) = µformat.external_channel_id {
println!("Channel ID: {}", channel_id);
}
}
if let Some(category) = µformat.category {
println!("Category: {}", category);
}
if let Some(views) = µformat.view_count {
println!("View Count: {}", views);
}
if let Some(likes) = µformat.like_count {
println!("Like Count: {}", likes);
}
if let Some(length) = µformat.length_seconds {
println!("Length: {} seconds", length);
}
if let Some(is_unlisted) = microformat.is_unlisted {
println!("Is Unlisted: {}", is_unlisted);
}
if let Some(is_family_safe) = microformat.is_family_safe {
println!("Is Family Safe: {}", is_family_safe);
}
if let Some(is_shorts) = microformat.is_shorts_eligible {
println!("Is Shorts Eligible: {}", is_shorts);
}
if let Some(upload_date) = µformat.upload_date {
println!("Upload Date: {}", upload_date);
}
if let Some(publish_date) = µformat.publish_date {
println!("Publish Date: {}", publish_date);
}
if let Some(countries) = µformat.available_countries {
println!("\nAvailable in {} countries, including:", countries.len());
for country in countries.iter().take(10) {
print!("{} ", country);
}
println!("...");
}
if let Some(embed) = µformat.embed {
println!("\nEmbed Information:");
if let Some(iframe_url) = &embed.iframe_url {
println!("iFrame URL: {}", iframe_url);
}
if let Some(width) = embed.width {
if let Some(height) = embed.height {
println!("Dimensions: {}x{}", width, height);
}
}
}
if let Some(thumbnail) = µformat.thumbnail {
if let Some(thumbnails) = &thumbnail.thumbnails {
println!("\nThumbnails: {} available", thumbnails.len());
for (i, thumb) in thumbnails.iter().enumerate() {
println!(
" {}: {}x{} - {}",
i + 1,
thumb.width,
thumb.height,
thumb.url
);
}
}
}
if let Some(description) = µformat.description {
println!("\nDescription:");
let description_text = if description.len() > 300 {
format!("{}...", &description[..300])
} else {
description.clone()
};
println!("{}", description_text);
}
}
Err(e) => {
println!("Failed to fetch microformat data: {:?}", e);
}
}
Ok(())
}