song download

This commit is contained in:
2026-02-25 23:48:21 +01:00
parent 5bdf915c4a
commit 5789278b4f
11 changed files with 1500 additions and 54 deletions
+3 -1
View File
@@ -4,9 +4,11 @@ version = "0.1.0"
edition = "2024"
[dependencies]
types = { path = "../types" }
async-nats = { version = "0.46.0" }
futures = { version = "0.3.32" }
futures-executor = { version = "0.3.32" }
tokio = { version = "1.49.0", features = ["macros", "rt-multi-thread"] }
postcard = { version = "1.1.3", features = ["use-std"] }
serde = { version = "1.0.228" }
yt-dlp = { version = "2.1.0" }
which = { version = "8.0.0" }
+30 -17
View File
@@ -1,21 +1,13 @@
use core::ops::Deref;
use std::path::PathBuf;
use which::which;
use futures::StreamExt;
use postcard::from_bytes;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
struct InnerStruct<'a> {
str: &'a str,
}
#[derive(Serialize, Deserialize, Debug)]
struct MyStruct<'a> {
len: usize,
str: &'a str,
inner: InnerStruct<'a>,
}
use types::jobs::Job;
use yt_dlp::{Downloader, client::Libraries};
#[tokio::main]
async fn main() {
@@ -27,14 +19,35 @@ async fn main() {
.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!("{:?}", message.payload);
let result: MyStruct = from_bytes(message.payload.deref()).unwrap();
println!("Received message {:?}", message);
let result: Job = from_bytes(message.payload.deref()).unwrap();
println!("{:?}", result);
println!("Received message {:?}", message);
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);
}
}