pub async fn start_download(&mut self, url: String) -> CommandResult {
        // create the download directory
        let dir = match self.get_download_directory().await {
            Ok(dir) => dir,
            Err(why) => return self.send_error(&why).await,
        };

        // create an update message to inform user about the current download state
        let mut update_message = match self.msg {
            Some(ref mut message) => {
                message
                    .edit(&self.http, |m| m.content("Starting download ..."))
                    .await?;
                message.clone()
            }
            None => {
                self.channel
                    .send_message(&self.http, |m| m.content("Starting download ..."))
                    .await?
            }
        };

        // download the video
        let file = match self.download_file(&dir, &url).await {
            Err(why) => {
                remove_dir_all(&dir)?; // clean dir on error
                return self.send_error(&why).await;
            }
            Ok(path) => path,
        };

        // create an update message to inform user about the current state
        update_message
            .edit(&self.http, |m| m.content("Start converting ..."))
            .await?;
        let max_upload = match self.cache.guild_channel(self.channel).await {
            Some(channel) => match self.cache.guild(channel.guild_id).await {
                Some(guild) => crate::model::discord_utils::get_max_uploadsize(&guild),
                None => MAX_DISCORD_FILE_SIZE,
            },
            None => MAX_DISCORD_FILE_SIZE,
        };

        if let Err(why) = self
            .upload_file(&mut update_message, file, max_upload)
            .await
        {
            remove_dir_all(&dir)?;
            self.send_error(&format!("{}", why)).await?;
        }

        // finally clear everything
        remove_dir_all(&dir)?;

        Ok(())
    }
///
/// Starts the YoutubeDL download and sends it to the user.
///
/// It also checks if the user is already downloading and if the file is too chonky
///
Starts the YoutubeDL download and sends it to the user.
It also checks if the user is already downloading and if the file is too chonky
Starts the YoutubeDL download and sends it to the user . It also checks if the user is already downloading and if the file is too chonky
pub async fn start_download(&mut self, url: String) -> CommandResult {
        // create the download directory
        let dir = match self.get_download_directory().await {
            Ok(dir) => dir,
            Err(why) => return self.send_error(&why).await,
        };
        // create an update message to inform user about the current download state
        let mut update_message = match self.msg {
            Some(ref mut message) => {
                message
                    .edit(&self.http, |m| m.content("Starting download ..."))
                    .await?;
                message.clone()
            }
            None => {
                self.channel
                    .send_message(&self.http, |m| m.content("Starting download ..."))
                    .await?
            }
        };
        // download the video
        let file = match self.download_file(&dir, &url).await {
            Err(why) => {
                remove_dir_all(&dir)?; // clean dir on error
                return self.send_error(&why).await;
            }
            Ok(path) => path,
        };
        // create an update message to inform user about the current state
        update_message
            .edit(&self.http, |m| m.content("Start converting ..."))
            .await?;
        let max_upload = match self.cache.guild_channel(self.channel).await {
            Some(channel) => match self.cache.guild(channel.guild_id).await {
                Some(guild) => crate::model::discord_utils::get_max_uploadsize(&guild),
                None => MAX_DISCORD_FILE_SIZE,
            },
            None => MAX_DISCORD_FILE_SIZE,
        };
        if let Err(why) = self
            .upload_file(&mut update_message, file, max_upload)
            .await
        {
            remove_dir_all(&dir)?;
            self.send_error(&format!("{}", why)).await?;
        }
        // finally clear everything
        remove_dir_all(&dir)?;
        Ok(())
    }
pub async fn start_download ( & mut self , url : String ) -> CommandResult { // create the download directory let dir = match self . get_download_directory ( ) . await { Ok ( dir ) => dir , Err ( why ) => return self . send_error ( & why ) . await , } ; // create an update message to inform user about the current download state let mut update_message = match self . msg { Some ( ref mut message ) => { message . edit ( & self . http , | m | m . content ( " " ) ) . await ? ; message . clone ( ) } None => { self . channel . send_message ( & self . http , | m | m . content ( " " ) ) . await ? } } ; // download the video let file = match self . download_file ( & dir , & url ) . await { Err ( why ) => { remove_dir_all ( & dir ) ? ; // clean dir on error return self . send_error ( & why ) . await ; } Ok ( path ) => path , } ; // create an update message to inform user about the current state update_message . edit ( & self . http , | m | m . content ( " " ) ) . await ? ; let max_upload = match self . cache . guild_channel ( self . channel ) . await { Some ( channel ) => match self . cache . guild ( channel . guild_id ) . await { Some ( guild ) => crate :: model :: discord_utils :: get_max_uploadsize ( & guild ) , None => MAX_DISCORD_FILE_SIZE , } , None => MAX_DISCORD_FILE_SIZE , } ; if let Err ( why ) = self . upload_file ( & mut update_message , file , max_upload ) . await { remove_dir_all ( & dir ) ? ; self . send_error ( & format ! ( " " why ) ) . await ? ; } // finally clear everything remove_dir_all ( & dir ) ? ; Ok ( ( ) ) }
Starts the YoutubeDL download and sends it to the user.
Starts the YoutubeDL download and sends it to the user .
&mut self
url
String
&mut self
url
String