This commit is contained in:
2026-03-11 00:21:56 +01:00
parent 816f8f75e7
commit 2f6f8414d0
13 changed files with 126 additions and 85 deletions
+3 -3
View File
@@ -8,7 +8,7 @@ async-nats = { version = "0.46.0" }
futures = { version = "0.3.32" }
futures-executor = { version = "0.3.32" }
postcard = { version = "1.1.3", features = ["use-std"] }
rustls = { version = "0.23.37", default-features = false, features = ["ring"] }
rustls = { version = "0.23.37", default-features = false, features = ["aws-lc-rs"] }
serenity = { version = "0.12.5", default-features = false, features = [
"cache",
"rustls_backend",
@@ -18,5 +18,5 @@ songbird = { git = "https://github.com/beerpsi-forks/songbird.git", branch = "da
symphonia = { version = "0.5.5" }
tokio = { version = "1.50.0", features = ["macros", "rt-multi-thread"] }
types = { path = "../../libs/types" }
which = { version = "8.0.1" }
yt-dlp = { version = "2.4.0" }
which = { version = "8.0.2" }
yt-dlp = { version = "2.5.0" }
+13 -5
View File
@@ -16,7 +16,7 @@ use yt_dlp::{Downloader, client::Libraries};
struct Handler {
nats_client: async_nats::Client,
yt_downloader: Downloader,
downloader: Downloader,
}
#[async_trait]
@@ -40,7 +40,7 @@ impl EventHandler for Handler {
let result = match subject {
"download" => workers::download::download(
&self.yt_downloader,
&self.downloader,
from_bytes(&message.payload).unwrap(),
)
.await
@@ -56,6 +56,14 @@ impl EventHandler for Handler {
error: res.error,
})
}
"search" => {
workers::search::search(&self.downloader, from_bytes(&message.payload).unwrap())
.await
.map(|res| JobResponse {
content: res.content.map(Jobs::Search),
error: res.error,
})
}
_ => Err(format!("subject {subject} does not exists")),
};
@@ -81,7 +89,7 @@ impl EventHandler for Handler {
#[tokio::main]
async fn main() {
rustls::crypto::ring::default_provider()
rustls::crypto::aws_lc_rs::default_provider()
.install_default()
.expect("Failed to install rustls crypto provider");
@@ -91,7 +99,7 @@ async fn main() {
.await
.expect("Error creating nats client");
let yt_downloader = Downloader::builder(
let downloader = Downloader::builder(
Libraries::new(which("yt-dlp").unwrap(), which("ffmpeg").unwrap()),
"output",
)
@@ -101,7 +109,7 @@ async fn main() {
let handler = Handler {
nats_client,
yt_downloader,
downloader,
};
let mut discord_client = Client::builder(&discord_token, GatewayIntents::non_privileged())
+6 -3
View File
@@ -1,5 +1,8 @@
use types::jobs::{DownloadJob, DownloadResponse, JobResponse};
use yt_dlp::Downloader;
use yt_dlp::{
Downloader,
model::{AudioCodecPreference, AudioQuality},
};
pub async fn download(
downloader: &Downloader,
@@ -16,8 +19,8 @@ pub async fn download(
.download_audio_stream_with_quality(
&video,
format!("{}.ogg", video.id),
yt_dlp::model::AudioQuality::Best,
yt_dlp::model::AudioCodecPreference::Opus,
AudioQuality::Best,
AudioCodecPreference::Opus,
)
.await
{
+1
View File
@@ -1,2 +1,3 @@
pub mod download;
pub mod play;
pub mod search;
+34
View File
@@ -0,0 +1,34 @@
use types::jobs::{JobResponse, SearchJob, SearchResponse};
use yt_dlp::Downloader;
pub async fn search(
downloader: &Downloader,
job: SearchJob,
) -> Result<JobResponse<SearchResponse>, String> {
println!("job: {:?}", job);
let result = match downloader
.youtube_extractor()
.search_first(&job.query)
.await
{
Ok(result) => match result.webpage_url {
Some(url) => JobResponse {
content: Some(SearchResponse { url }),
error: None,
},
None => JobResponse {
content: None,
error: Some("url is not defined".to_string()),
},
},
Err(why) => JobResponse {
content: None,
error: Some(format!("{why}")),
},
};
println!("reply: {:?}", result.content);
Ok(result)
}