song download
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
/target/
|
/target/
|
||||||
|
/output/
|
||||||
|
|||||||
Generated
+1415
-11
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
resolver = "3"
|
resolver = "3"
|
||||||
members = ["master", "worker"]
|
members = ["types", "master", "worker"]
|
||||||
|
|||||||
+2
-1
@@ -4,6 +4,7 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
types = { path = "../types" }
|
||||||
async-nats = { version = "0.46.0" }
|
async-nats = { version = "0.46.0" }
|
||||||
serenity = { version = "0.12.5", default-features = false, features = [
|
serenity = { version = "0.12.5", default-features = false, features = [
|
||||||
"client",
|
"client",
|
||||||
@@ -14,4 +15,4 @@ serenity = { version = "0.12.5", default-features = false, features = [
|
|||||||
] }
|
] }
|
||||||
tokio = { version = "1.49.0", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.49.0", features = ["macros", "rt-multi-thread"] }
|
||||||
postcard = { version = "1.1.3", features = ["use-std"] }
|
postcard = { version = "1.1.3", features = ["use-std"] }
|
||||||
serde = { version = "1.0.228" }
|
uuid = { version = "1.21.0" }
|
||||||
|
|||||||
@@ -6,19 +6,9 @@ use serenity::builder::CreateCommand;
|
|||||||
use serenity::model::application::{CommandOptionType, ResolvedOption, ResolvedValue};
|
use serenity::model::application::{CommandOptionType, ResolvedOption, ResolvedValue};
|
||||||
|
|
||||||
use postcard::to_stdvec;
|
use postcard::to_stdvec;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
use types::jobs::{InnerStruct, Job, JobKind};
|
||||||
struct InnerStruct<'a> {
|
use types::misc::new_uuid_v4;
|
||||||
str: &'a str,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
struct MyStruct<'a> {
|
|
||||||
len: usize,
|
|
||||||
str: &'a str,
|
|
||||||
inner: InnerStruct<'a>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn run(
|
pub async fn run(
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
@@ -32,19 +22,20 @@ pub async fn run(
|
|||||||
..
|
..
|
||||||
}) = options.first()
|
}) = options.first()
|
||||||
{
|
{
|
||||||
let hehe = &MyStruct {
|
let job = &Job {
|
||||||
len: value.len(),
|
uuid: new_uuid_v4(),
|
||||||
str: value,
|
kind: JobKind::Download,
|
||||||
inner: InnerStruct { str: &value.repeat(3) }
|
inner: InnerStruct {
|
||||||
|
str: value.to_string(),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("{:?}", hehe);
|
println!("job {:?}", job);
|
||||||
|
|
||||||
let ahah = to_stdvec(hehe).unwrap();
|
if let Err(_why) = nats_client
|
||||||
|
.publish("corro-dj.download", to_stdvec(job).unwrap().into())
|
||||||
println!("{:?}", ahah);
|
.await
|
||||||
|
{
|
||||||
if let Err(why) = nats_client.publish("corro-dj.download", ahah.into()).await {
|
|
||||||
return Err(serenity::Error::Other("send error"));
|
return Err(serenity::Error::Other("send error"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +43,7 @@ pub async fn run(
|
|||||||
.create_response(
|
.create_response(
|
||||||
ctx,
|
ctx,
|
||||||
CreateInteractionResponse::Message(
|
CreateInteractionResponse::Message(
|
||||||
CreateInteractionResponseMessage::new().content(*value),
|
CreateInteractionResponseMessage::new().content(format!("Sent: {value}")),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@@ -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"]}
|
||||||
@@ -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,
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod jobs;
|
||||||
|
pub mod misc;
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
pub fn new_uuid_v4() -> Uuid{
|
||||||
|
Uuid::new_v4()
|
||||||
|
}
|
||||||
+3
-1
@@ -4,9 +4,11 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
types = { path = "../types" }
|
||||||
async-nats = { version = "0.46.0" }
|
async-nats = { version = "0.46.0" }
|
||||||
futures = { version = "0.3.32" }
|
futures = { version = "0.3.32" }
|
||||||
futures-executor = { version = "0.3.32" }
|
futures-executor = { version = "0.3.32" }
|
||||||
tokio = { version = "1.49.0", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.49.0", features = ["macros", "rt-multi-thread"] }
|
||||||
postcard = { version = "1.1.3", features = ["use-std"] }
|
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
@@ -1,21 +1,13 @@
|
|||||||
use core::ops::Deref;
|
use core::ops::Deref;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use which::which;
|
||||||
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
|
||||||
use postcard::from_bytes;
|
use postcard::from_bytes;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
use types::jobs::Job;
|
||||||
struct InnerStruct<'a> {
|
use yt_dlp::{Downloader, client::Libraries};
|
||||||
str: &'a str,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
struct MyStruct<'a> {
|
|
||||||
len: usize,
|
|
||||||
str: &'a str,
|
|
||||||
inner: InnerStruct<'a>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
@@ -27,14 +19,35 @@ async fn main() {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.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
|
// Receive and process messages
|
||||||
while let Some(message) = subscriber.next().await {
|
while let Some(message) = subscriber.next().await {
|
||||||
println!("{:?}", message.payload);
|
println!("Received message {:?}", message);
|
||||||
|
let result: Job = from_bytes(message.payload.deref()).unwrap();
|
||||||
let result: MyStruct = from_bytes(message.payload.deref()).unwrap();
|
|
||||||
|
|
||||||
println!("{:?}", result);
|
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