fix formatting

This commit is contained in:
Oleg Sobolev 2024-03-25 17:14:33 +07:00
parent 91eca478c4
commit 22659046be
3 changed files with 18 additions and 15 deletions

View file

@ -1,6 +1,7 @@
use crate::track::TrackInfo;
use std::{path::Path, process::Command}; use std::{path::Path, process::Command};
use crate::track::TrackInfo;
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct DownloadError; pub struct DownloadError;
@ -14,12 +15,13 @@ pub fn download_from_youtube(url: &str) -> Result<TrackInfo, DownloadError> {
"mp3", "mp3",
"--print", "--print",
"%(id)s", "%(id)s",
"--no-simulate",
url, url,
]) ])
.output() .output()
.unwrap(); .unwrap();
if !output.stderr.is_empty() { if !output.stderr.is_empty() || output.stdout.is_empty() {
return Err(DownloadError); return Err(DownloadError);
} }

View file

@ -1,7 +1,8 @@
use std::{collections::VecDeque, fs::File, io::BufReader, thread, thread::JoinHandle};
use rodio::{Decoder, OutputStream, OutputStreamHandle, Sink};
use crate::channel::{self, Requester, Responder, TryRecvError}; use crate::channel::{self, Requester, Responder, TryRecvError};
use crate::track::TrackInfo; use crate::track::TrackInfo;
use rodio::{Decoder, OutputStream, OutputStreamHandle, Sink};
use std::{collections::VecDeque, fs::File, io::BufReader, thread, thread::JoinHandle};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
enum WorkerRequest { enum WorkerRequest {

View file

@ -1,11 +1,7 @@
use std::{ use std::sync::{Arc, Mutex};
path::Path,
sync::{Arc, Mutex},
};
use teloxide::{prelude::*, utils::command::BotCommands}; use teloxide::{prelude::*, utils::command::BotCommands};
use crate::{player::MusicPlayer, TrackInfo}; use crate::{player::MusicPlayer, download};
#[derive(BotCommands, Clone)] #[derive(BotCommands, Clone)]
#[command( #[command(
@ -47,11 +43,15 @@ impl TelegramBot {
match cmd { match cmd {
Command::Play(url) => { Command::Play(url) => {
println!("{}", url); println!("{}", url);
player match download::download_from_youtube(&url) {
.lock() Ok(track_info) => {
.unwrap() player.lock().unwrap().enqueue(track_info);
.enqueue(TrackInfo::new(Path::new("8bB0FNGlrEs.mp3"))); bot.send_message(msg.chat.id, "Added to the queue.").await?;
bot.send_message(msg.chat.id, "Added to the queue.").await?; },
Err(_) => {
bot.send_message(msg.chat.id, format!("Failed to download.")).await?;
}
}
} }
Command::Stop => { Command::Stop => {
player.lock().unwrap().stop(); player.lock().unwrap().stop();