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
+1
View File
@@ -1 +1,2 @@
/target/
/output/
Generated
+1415 -11
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,3 +1,3 @@
[workspace]
resolver = "3"
members = ["master", "worker"]
members = ["types", "master", "worker"]
+2 -1
View File
@@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2024"
[dependencies]
types = { path = "../types" }
async-nats = { version = "0.46.0" }
serenity = { version = "0.12.5", default-features = false, features = [
"client",
@@ -14,4 +15,4 @@ serenity = { version = "0.12.5", default-features = false, features = [
] }
tokio = { version = "1.49.0", features = ["macros", "rt-multi-thread"] }
postcard = { version = "1.1.3", features = ["use-std"] }
serde = { version = "1.0.228" }
uuid = { version = "1.21.0" }
+14 -23
View File
@@ -6,19 +6,9 @@ use serenity::builder::CreateCommand;
use serenity::model::application::{CommandOptionType, ResolvedOption, ResolvedValue};
use postcard::to_stdvec;
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::{InnerStruct, Job, JobKind};
use types::misc::new_uuid_v4;
pub async fn run(
ctx: &Context,
@@ -32,19 +22,20 @@ pub async fn run(
..
}) = options.first()
{
let hehe = &MyStruct {
len: value.len(),
str: value,
inner: InnerStruct { str: &value.repeat(3) }
let job = &Job {
uuid: new_uuid_v4(),
kind: JobKind::Download,
inner: InnerStruct {
str: value.to_string(),
},
};
println!("{:?}", hehe);
println!("job {:?}", job);
let ahah = to_stdvec(hehe).unwrap();
println!("{:?}", ahah);
if let Err(why) = nats_client.publish("corro-dj.download", ahah.into()).await {
if let Err(_why) = nats_client
.publish("corro-dj.download", to_stdvec(job).unwrap().into())
.await
{
return Err(serenity::Error::Other("send error"));
}
@@ -52,7 +43,7 @@ pub async fn run(
.create_response(
ctx,
CreateInteractionResponse::Message(
CreateInteractionResponseMessage::new().content(*value),
CreateInteractionResponseMessage::new().content(format!("Sent: {value}")),
),
)
.await?;
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "types"
version = "0.1.0"
edition = "2024"
[dependencies]
serde = { version = "1.0.228" }
uuid = { version = "1.21.0", features = ["serde", "v4"]}
+19
View File
@@ -0,0 +1,19 @@
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Serialize, Deserialize, Debug)]
pub enum JobKind {
Download,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct InnerStruct {
pub str: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Job {
pub uuid: Uuid,
pub kind: JobKind,
pub inner: InnerStruct,
}
+2
View File
@@ -0,0 +1,2 @@
pub mod jobs;
pub mod misc;
+5
View File
@@ -0,0 +1,5 @@
use uuid::Uuid;
pub fn new_uuid_v4() -> Uuid{
Uuid::new_v4()
}
+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);
}
}