feat: do todos

This commit is contained in:
Soph :3 2025-09-10 07:19:57 +03:00
parent fb14a6f9a0
commit e5dd0206ca
4 changed files with 59 additions and 53 deletions

View file

@ -1,3 +1,4 @@
use crate::Configuration;
use crate::client::Client;
use crate::client::ClientEvent;
use crate::client::Note;
@ -17,11 +18,12 @@ use tokio::sync::Mutex;
pub struct PlayCommand {
midi_state: Arc<Mutex<MidiState>>,
conf: Configuration,
}
impl PlayCommand {
pub fn new(midi_state: Arc<Mutex<MidiState>>) -> Self {
Self { midi_state }
pub fn new(midi_state: Arc<Mutex<MidiState>>, conf: Configuration) -> Self {
Self { midi_state, conf }
}
}
@ -180,7 +182,7 @@ impl Command for PlayCommand {
filename_to_play = format!("midis/{}.mid", hashed);
filename_beautiful = first_capture.to_string();
let url = format!("https://files.sad.ovh/public/midis/{}", first_capture);
let url = format!("{}/{}", self.conf.commands.copyparty, first_capture);
let file_exists = tokio::fs::try_exists(&filename_to_play)
.await

View file

@ -2,6 +2,7 @@ use crate::client::Client;
use crate::client::ClientEvent;
use crate::client::Player;
use crate::Configuration;
use crate::commands::Command;
use crate::commands::MidiState;
use crate::commands::argument::{ArgumentSpec, ArgumentType, ParsedArgument, ParsedArguments};
@ -15,11 +16,12 @@ use tokio::sync::Mutex;
pub struct PlaylistCommand {
midi_state: Arc<Mutex<MidiState>>,
conf: Configuration,
}
impl PlaylistCommand {
pub fn new(midi_state: Arc<Mutex<MidiState>>) -> Self {
Self { midi_state }
pub fn new(midi_state: Arc<Mutex<MidiState>>, conf: Configuration) -> Self {
Self { midi_state, conf }
}
}
@ -59,50 +61,20 @@ impl Command for PlaylistCommand {
let mut filename_to_play: String = "".to_string();
let mut filename_beautiful: String = "".to_string();
if joined_args == "playlist_1" {
const TRACKS: &[&str] = &[
"A/autumn_leaves2-G85.mid",
"B/blue_bossa-kenny-dorham_dz.mid",
"J/Jobim_Desafinado.mid",
"J/Jobim_Wave.mid",
"J/Jobim_corcovado.mid",
"I/ipanema.mid",
"J/Jobim_Meditacao2.mid",
"S/so_what.mid",
"T/take_five2-Gb176-davebrubeck.mid",
"M/My_Funny_Valentine.mid",
"A/all_the_things_you_are-2_dm.mid",
"J/Johnny_Mathis_Misty.mid",
"H/HOWARD.Fly me to the moon.mid",
"R/Ray Charles - Georgia On My Mind.mid",
"B/blue_in_green.mid",
"S/Stella-By-Starlight-1.mid",
"F/FITZGERALD.Summertime K.mid",
"M/Moon River.mid",
"A/autumn_in_new_york2-Bb84.mid",
"J/Jobim_One_Note_Samba.mid",
];
for track in TRACKS {
if self.conf.commands.playlists.contains_key(joined_args) {
let tracks_ref = self.conf.commands.playlists.get(joined_args).unwrap();
for track in tracks_ref {
let hashed = simple_hash(track);
let filename = format!("midis/{}.mid", hashed);
let url = format!("https://files.sad.ovh/public/midis/{}", track);
let file_exists = tokio::fs::try_exists(&filename).await.unwrap_or(false);
if !file_exists {
match reqwest::get(&url).await {
match reqwest::get(&track.clone()).await {
Ok(resp) => {
if resp.status().is_success() {
match resp.bytes().await {
Ok(bytes) => match tokio::fs::write(&filename, &bytes).await {
Ok(_) => {
client
.message(format!(
"Downloaded midi from files.sad.ovh: {}",
track
))
.await;
}
Ok(_) => {}
Err(e) => {
client
.message(format!("Failed to write file: {}", e))
@ -137,7 +109,7 @@ impl Command for PlaylistCommand {
}
}
let mut tracks: Vec<&str> = TRACKS.to_vec();
let mut tracks = tracks_ref.clone();
tracks.shuffle(&mut rand::rng());
if let Some(first) = tracks.first() {
@ -175,7 +147,7 @@ impl Command for PlaylistCommand {
let first_capture = caps.trim();
if first_capture.ends_with('/') {
let url = format!("https://files.sad.ovh/public/midis/{}?ls", first_capture);
let url = format!("{}/{}?ls", self.conf.commands.copyparty, first_capture);
match reqwest::get(&url).await {
Ok(resp) => {
if resp.status().is_success() {
@ -209,8 +181,8 @@ impl Command for PlaylistCommand {
let hashed = simple_hash(&file_path);
let filename = format!("midis/{}.mid", hashed);
let url_file = format!(
"https://files.sad.ovh/public/midis/{}",
file_path
"{}/{}",
self.conf.commands.copyparty, file_path
);
let file_exists = tokio::fs::try_exists(&filename)