This commit is contained in:
2026-03-03 08:52:36 +01:00
parent feff3dd20e
commit d7edd53792
2 changed files with 31 additions and 16 deletions
+24 -9
View File
@@ -1,5 +1,7 @@
mod workers;
use std::env;
use futures::StreamExt;
use postcard::{from_bytes, to_stdvec};
use types::jobs::JobResponse;
@@ -8,6 +10,21 @@ use yt_dlp::{Downloader, client::Libraries};
#[tokio::main]
async fn main() {
let token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment");
let mut client = Client::builder(&token, intents)
.event_handler(Handler)
.framework(framework)
.register_songbird()
// We insert our own HTTP client here to make use of in
// `~play`. If we wanted, we could supply cookies and auth
// details ahead of time.
//
// Generally, we don't want to make a new Client for every request!
.type_map_insert::<HttpKey>(HttpClient::new())
.await
.expect("Err creating client");
let nats_client = async_nats::connect("nats://localhost:4222")
.await
.expect("Error creating nats client");
@@ -17,9 +34,10 @@ async fn main() {
.await
.unwrap();
let libraries = Libraries::new(which("yt-dlp").unwrap(), which("ffmpeg").unwrap());
let downloader = Downloader::builder(libraries, "output")
let yt_downloader = Downloader::builder(
Libraries::new(which("yt-dlp").unwrap(), which("ffmpeg").unwrap()),
"output",
)
.build()
.await
.unwrap();
@@ -32,20 +50,17 @@ async fn main() {
let result = match subject {
"download" => {
workers::download::download(&downloader, from_bytes(&message.payload).unwrap())
workers::download::download(&yt_downloader, from_bytes(&message.payload).unwrap())
.await
}
_ => {
println!("{subject}");
continue;
}
_ => Err(format!("subject {subject} does not exists")),
};
let response = match result {
Ok(response) => response,
Err(err) => JobResponse {
content: None,
error: Some(format!("{err}")),
error: Some(err),
},
};
+4 -4
View File
@@ -1,15 +1,15 @@
use types::jobs::{DownloadJob, DownloadResponse, JobResponse};
use yt_dlp::{Downloader, error::Error};
use yt_dlp::Downloader;
pub async fn download(
downloader: &Downloader,
job: DownloadJob,
) -> Result<JobResponse<DownloadResponse>, Error> {
) -> Result<JobResponse<DownloadResponse>, String> {
println!("job: {:?}", job);
let video = match downloader.fetch_video_infos(job.url).await {
Ok(video) => video,
Err(err) => return Err(err),
Err(err) => return Err(err.to_string()),
};
let audio_path = match downloader
@@ -22,7 +22,7 @@ pub async fn download(
.await
{
Ok(path) => path,
Err(err) => return Err(err),
Err(err) => return Err(err.to_string()),
};
println!("reply: {:?}", audio_path);