use core::ops::Deref; use std::path::PathBuf; use which::which; use futures::StreamExt; use postcard::from_bytes; use types::jobs::Job; use yt_dlp::{Downloader, client::Libraries}; #[tokio::main] async fn main() { let nats_client = async_nats::connect("nats://localhost:4222") .await .expect("Error creating nats client"); let mut subscriber = nats_client .queue_subscribe("corro-dj.*", "download".to_string()) .await .unwrap(); let libraries = Libraries::new( PathBuf::from(which("yt-dlp").unwrap()), PathBuf::from(which("ffmpeg").unwrap()), ); let downloader = Downloader::builder(libraries, "output") .build() .await .unwrap(); // Receive and process messages while let Some(message) = subscriber.next().await { println!("Received message {:?}", message); let result: Job = from_bytes(message.payload.deref()).unwrap(); println!("{:?}", result); let video = downloader .fetch_video_infos(result.inner.str) .await .unwrap(); let audio_path = downloader .download_audio_stream_with_quality( &video, format!("{}.opus", video.id), yt_dlp::model::AudioQuality::Best, yt_dlp::model::AudioCodecPreference::Opus, ) .await; println!("{:?}", audio_path); } }