song download
This commit is contained in:
+30
-17
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user