### Example Usage of LibraryInstaller Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.LibraryInstaller.html?search=std%3A%3Avec Demonstrates how to create a LibraryInstaller and install YouTube and FFmpeg libraries. ```rust let destination = PathBuf::from("libs"); let installer = LibraryInstaller::new(destination); let youtube = installer.install_youtube(None).await.unwrap(); let ffmpeg = installer.install_ffmpeg(None).await.unwrap(); ``` -------------------------------- ### Install YouTube from Main Repository Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.LibraryInstaller.html?search=std%3A%3Avec Installs yt-dlp from the main repository. Use this for standard installations. ```rust pub async fn install_youtube( &self, custom_name: Option, ) -> Result ``` -------------------------------- ### Start a Live Recording with Max Duration Source: https://docs.rs/yt-dlp/latest/yt_dlp/live/struct.LiveRecordingBuilder.html This example demonstrates how to fetch video information and then start a live recording with a specified maximum duration. The recording is saved to a file named 'live-recording.ts'. ```rust let video = downloader.fetch_video_infos("https://youtube.com/watch?v=LIVE_ID").await?; let result = downloader.record_live(&video, "live-recording.ts") .with_max_duration(Duration::from_secs(3600)) .execute() .await?; println!("Recorded {} bytes", result.total_bytes); ``` -------------------------------- ### Install ffmpeg Binary with Authentication Token Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search= Asynchronously installs the ffmpeg binary using an authentication token. ```rust pub async fn install_ffmpeg_with_token( &self, auth_token: impl Into, ) -> Result ``` -------------------------------- ### Install ffmpeg Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search=u32+-%3E+bool Asynchronously installs the ffmpeg binary. Returns a Result containing the PathBuf to the installed binary on success. ```rust self.install_ffmpeg().await?; ``` -------------------------------- ### Install FFmpeg from Static Builds Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.LibraryInstaller.html?search=std%3A%3Avec Installs FFmpeg from pre-compiled static builds. This is a convenient way to get FFmpeg. ```rust pub async fn install_ffmpeg( &self, custom_name: Option, ) -> Result ``` -------------------------------- ### Install yt-dlp Binary with Authentication Token Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search= Asynchronously installs the yt-dlp binary using an authentication token. ```rust pub async fn install_youtube_with_token( &self, auth_token: impl Into, ) -> Result ``` -------------------------------- ### Install ffmpeg Binary Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search= Asynchronously installs the ffmpeg binary to the configured path. ```rust pub async fn install_ffmpeg(&self) -> Result ``` -------------------------------- ### Install yt-dlp Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search=u32+-%3E+bool Asynchronously installs the yt-dlp binary. Returns a Result containing the PathBuf to the installed binary on success. ```rust self.install_youtube().await?; ``` -------------------------------- ### Install Binaries and Create Downloader Source: https://docs.rs/yt-dlp/latest/yt_dlp/struct.Downloader.html?search=u32+-%3E+bool Creates a Downloader instance while also installing the yt-dlp and ffmpeg binaries. This function can take a significant amount of time to complete. ```rust let downloader_builder = Downloader::with_new_binaries(PathBuf::from("binaries"), PathBuf::from("output")).await?; ``` -------------------------------- ### Install ffmpeg with Authentication Token Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search=u32+-%3E+bool Asynchronously installs the ffmpeg binary using an authentication token. This enables authenticated downloads. ```rust self.install_ffmpeg_with_token(auth_token).await?; ``` -------------------------------- ### Install Binaries and Create Downloader Source: https://docs.rs/yt-dlp/latest/yt_dlp/struct.Downloader.html Installs yt-dlp and ffmpeg binaries and creates a Downloader instance. This function can take a significant amount of time to complete. The output directory can be omitted if only fetching video information is required. ```rust let downloader_builder = Downloader::with_new_binaries(PathBuf::from("bin"), PathBuf::from("output")).await?; ``` -------------------------------- ### Install Dependencies Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search= Asynchronously installs all required dependencies for yt-dlp and ffmpeg. ```rust pub async fn install_dependencies(&self) -> Result ``` -------------------------------- ### Install yt-dlp Binary Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search= Asynchronously installs the yt-dlp binary to the configured path. ```rust pub async fn install_youtube(&self) -> Result ``` -------------------------------- ### Install yt-dlp and ffmpeg Binaries Source: https://docs.rs/yt-dlp/latest/yt_dlp/index.html?search=u32+-%3E+bool Installs both the yt-dlp and ffmpeg binaries to specified directories. Use this when both are required for advanced features. ```rust use yt_dlp::Downloader; use std::path::PathBuf; #[tokio::main] pub async fn main() -> Result<(), Box> { let executables_dir = PathBuf::from("libs"); let output_dir = PathBuf::from("output"); // Create fetcher and install binaries let downloader = Downloader::with_new_binaries( executables_dir, output_dir ).await?.build().await?; Ok(()) } ``` -------------------------------- ### Install YouTube from Custom Repository Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.LibraryInstaller.html Installs yt-dlp from a specified GitHub repository. Requires owner, repo, and optionally an auth token and custom name. ```rust let owner = "yt-dlp"; let repo = "yt-dlp"; let auth_token = None; let custom_name = None; let youtube = installer.install_youtube_from_repo(owner, repo, auth_token, custom_name).await.unwrap(); ``` -------------------------------- ### Install YouTube from Custom Repository Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.LibraryInstaller.html?search=std%3A%3Avec Installs yt-dlp from a specified GitHub repository. Useful for using forks or specific versions. ```rust pub async fn install_youtube_from_repo( &self, owner: impl Into, repo: impl Into, auth_token: Option, custom_name: Option, ) -> Result ``` -------------------------------- ### Libraries::install_youtube Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search= Installs the yt-dlp binary. ```APIDOC ## Libraries::install_youtube ### Description Installs the yt-dlp binary. ### Signature `pub async fn install_youtube(&self) -> Result` ### Returns `Result` - A Result containing the PathBuf to the installed yt-dlp binary on success, or an error on failure. ``` -------------------------------- ### Libraries::install_ffmpeg_with_token Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search= Installs the ffmpeg binary using an authentication token. ```APIDOC ## Libraries::install_ffmpeg_with_token ### Description Installs the ffmpeg binary using a provided authentication token. ### Signature `pub async fn install_ffmpeg_with_token(&self, auth_token: impl Into) -> Result` ### Parameters * `auth_token`: `impl Into` - The authentication token to use for downloading the dependency. ### Returns `Result` - A Result containing the PathBuf to the installed ffmpeg binary on success, or an error on failure. ``` -------------------------------- ### Libraries::install_youtube Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Installs the yt-dlp binary. ```APIDOC ## Libraries::install_youtube ### Description Installs the yt-dlp binary. ### Signature `pub async fn install_youtube(&self) -> Result` ### Returns * `Result` - A Result containing the PathBuf to the installed yt-dlp binary on success, or an error if installation fails. ``` -------------------------------- ### Initialize Downloader for Playlist Operations Source: https://docs.rs/yt-dlp/latest/yt_dlp/index.html?search= This code snippet shows the basic setup required for most playlist operations. It initializes the `Downloader` with paths to yt-dlp and ffmpeg executables, and specifies an output directory. This setup is common across various playlist functionalities. ```rust use yt_dlp::Downloader; use std::path::PathBuf; use yt_dlp::client::deps::Libraries; #[tokio::main] pub async fn main() -> Result<(), Box> { let libraries_dir = PathBuf::from("libs"); let output_dir = PathBuf::from("output"); let youtube = libraries_dir.join("yt-dlp"); let ffmpeg = libraries_dir.join("ffmpeg"); let libraries = Libraries::new(youtube, ffmpeg); let downloader = Downloader::builder(libraries, output_dir) .build() .await?; // ... rest of the playlist operations ... Ok(()) } ``` -------------------------------- ### Libraries::install_youtube_with_token Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search= Installs the yt-dlp binary using an authentication token. ```APIDOC ## Libraries::install_youtube_with_token ### Description Installs the yt-dlp binary using a provided authentication token. ### Signature `pub async fn install_youtube_with_token(&self, auth_token: impl Into) -> Result` ### Parameters * `auth_token`: `impl Into` - The authentication token to use for downloading the dependency. ### Returns `Result` - A Result containing the PathBuf to the installed yt-dlp binary on success, or an error on failure. ``` -------------------------------- ### Libraries::install_ffmpeg Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search= Installs the ffmpeg binary. ```APIDOC ## Libraries::install_ffmpeg ### Description Installs the ffmpeg binary. ### Signature `pub async fn install_ffmpeg(&self) -> Result` ### Returns `Result` - A Result containing the PathBuf to the installed ffmpeg binary on success, or an error on failure. ``` -------------------------------- ### Libraries::install_dependencies_with_token Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Installs all required dependencies using a provided authentication token. ```APIDOC ## Libraries::install_dependencies_with_token ### Description Installs all required dependencies using a provided authentication token. ### Signature `pub async fn install_dependencies_with_token(&self, auth_token: impl Into) -> Result` ### Parameters * `auth_token`: `impl Into` - The authentication token to use for downloading the dependencies. ### Returns * `Result` - A Result containing the updated Libraries instance on success, or an error if installation fails. ``` -------------------------------- ### Libraries::install_ffmpeg Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Installs the ffmpeg binary. ```APIDOC ## Libraries::install_ffmpeg ### Description Installs the ffmpeg binary. ### Signature `pub async fn install_ffmpeg(&self) -> Result` ### Returns * `Result` - A Result containing the PathBuf to the installed ffmpeg binary on success, or an error if installation fails. ``` -------------------------------- ### Rust yt-dlp CacheConfig Example Source: https://docs.rs/yt-dlp/latest/yt_dlp/cache/config/struct.CacheConfig.html Demonstrates how to create a CacheConfig instance using the builder pattern. This example sets the cache directory to 'cache'. ```rust use std::path::PathBuf; use yt_dlp::cache::CacheConfig; let config = CacheConfig::builder() .cache_dir(PathBuf::from("cache")) .build(); ``` -------------------------------- ### Libraries::install_ffmpeg_with_token Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Installs the ffmpeg binary using a provided authentication token. ```APIDOC ## Libraries::install_ffmpeg_with_token ### Description Installs the ffmpeg binary using a provided authentication token. ### Signature `pub async fn install_ffmpeg_with_token(&self, auth_token: impl Into) -> Result` ### Parameters * `auth_token`: `impl Into` - The authentication token to use for downloading the dependency. ### Returns * `Result` - A Result containing the PathBuf to the installed ffmpeg binary on success, or an error if installation fails. ``` -------------------------------- ### Install Dependencies with Authentication Token Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search= Asynchronously installs dependencies using a provided authentication token for private repositories or specific download sources. ```rust pub async fn install_dependencies_with_token( &self, auth_token: impl Into, ) -> Result ``` -------------------------------- ### Libraries::install_youtube_with_token Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Installs the yt-dlp binary using a provided authentication token. ```APIDOC ## Libraries::install_youtube_with_token ### Description Installs the yt-dlp binary using a provided authentication token. ### Signature `pub async fn install_youtube_with_token(&self, auth_token: impl Into) -> Result` ### Parameters * `auth_token`: `impl Into` - The authentication token to use for downloading the dependency. ### Returns * `Result` - A Result containing the PathBuf to the installed yt-dlp binary on success, or an error if installation fails. ``` -------------------------------- ### LibraryInstaller::install_ffmpeg Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.LibraryInstaller.html Installs ffmpeg from static builds. ```APIDOC ## LibraryInstaller::install_ffmpeg ### Description Install ffmpeg from static builds. ### Signature ```rust pub async fn install_ffmpeg(&self, custom_name: Option) -> Result ``` ### Arguments * `custom_name` (Option) - Optional custom name for the executable. ``` -------------------------------- ### LibraryInstaller::install_youtube Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.LibraryInstaller.html?search=std%3A%3Avec Installs yt-dlp from the main repository. ```APIDOC ## LibraryInstaller::install_youtube ### Description Installs yt-dlp from the main repository. ### Signature ```rust pub async fn install_youtube(&self, custom_name: Option) -> Result ``` ### Arguments * `custom_name` - `Option`: Optional custom name for the executable. ``` -------------------------------- ### LibraryInstaller::install_ffmpeg Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.LibraryInstaller.html?search=std%3A%3Avec Installs ffmpeg from static builds. ```APIDOC ## LibraryInstaller::install_ffmpeg ### Description Installs ffmpeg from static builds. ### Signature ```rust pub async fn install_ffmpeg(&self, custom_name: Option) -> Result ``` ### Arguments * `custom_name` - `Option`: Optional custom name for the executable. ``` -------------------------------- ### LibraryInstaller::install_youtube_from_repo Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.LibraryInstaller.html Installs yt-dlp from a custom repository. ```APIDOC ## LibraryInstaller::install_youtube_from_repo ### Description Install yt-dlp from a custom repository, assuming releases assets are named correctly. ### Signature ```rust pub async fn install_youtube_from_repo( &self, owner: impl Into, repo: impl Into, auth_token: Option, custom_name: Option, ) -> Result ``` ### Arguments * `owner` (impl Into) - The owner of the repository. * `repo` (impl Into) - The name of the repository. * `auth_token` (Option) - Optional GitHub token to avoid rate limits. * `custom_name` (Option) - Optional custom name for the executable. ``` -------------------------------- ### Libraries::install_dependencies_with_token Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search= Installs dependencies using an authentication token. ```APIDOC ## Libraries::install_dependencies_with_token ### Description Installs the required dependencies using a provided authentication token. ### Signature `pub async fn install_dependencies_with_token(&self, auth_token: impl Into) -> Result` ### Parameters * `auth_token`: `impl Into` - The authentication token to use for downloading the dependencies. ### Returns `Result` - A Result containing the updated Libraries instance on success, or an error on failure. ``` -------------------------------- ### Getting Start and End Times Source: https://docs.rs/yt-dlp/latest/yt_dlp/download/engine/partial/enum.PartialRange.html Retrieves the start and end times in seconds for a `PartialRange`. Returns `None` if the range needs chapter conversion. ```rust pub fn get_times(&self) -> Option<(f64, f64)> ``` -------------------------------- ### Download with Progress Tracking Source: https://docs.rs/yt-dlp/latest/yt_dlp/index.html?search=u32+-%3E+bool Sets up the downloader and prepares for downloading a video, including progress tracking setup. ```rust use yt_dlp::Downloader; use std::path::PathBuf; use yt_dlp::client::deps::Libraries; #[tokio::main] pub async fn main() -> Result<(), Box> { let libraries_dir = PathBuf::from("libs"); let output_dir = PathBuf::from("output"); let youtube = libraries_dir.join("yt-dlp"); let ffmpeg = libraries_dir.join("ffmpeg"); let libraries = Libraries::new(youtube, ffmpeg); let downloader = Downloader::builder(libraries, output_dir) .build() ``` -------------------------------- ### Initialize Downloader and Fetch Video Info (YouTube) Source: https://docs.rs/yt-dlp/latest/yt_dlp/struct.Downloader.html?search=u32+-%3E+bool Initializes the Downloader with libraries and output path, then fetches video information for a YouTube URL. Requires prior setup of Libraries and building the Downloader. ```rust let libraries = Libraries::new(PathBuf::from("libs/yt-dlp"), PathBuf::from("libs/ffmpeg")); let downloader = Downloader::builder(libraries, "output").build().await?; // YouTube is automatically detected and optimized let video = downloader .fetch_video_infos("https://youtube.com/watch?v=...".to_string()) .await?; downloader.download_video(&video, "video.mp4").await?; ``` -------------------------------- ### BuildFetcher Example Usage Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/ffmpeg/struct.BuildFetcher.html Demonstrates how to create a BuildFetcher, fetch an FFmpeg binary, download it, and then extract it. This is useful for setting up FFmpeg dependencies for your application. ```rust let path = PathBuf::from("ffmpeg-release.zip"); let fetcher = BuildFetcher::new(); let release = fetcher.fetch_binary().await?; release.download(path.clone()).await?; fetcher.extract_binary(path).await?; ``` -------------------------------- ### Libraries::install_dependencies Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search= Installs all required dependencies (yt-dlp and ffmpeg). ```APIDOC ## Libraries::install_dependencies ### Description Installs the required dependencies (yt-dlp and ffmpeg). ### Signature `pub async fn install_dependencies(&self) -> Result` ### Returns `Result` - A Result containing the updated Libraries instance on success, or an error on failure. ``` -------------------------------- ### Get the number of active downloads Source: https://docs.rs/yt-dlp/latest/yt_dlp/stats/struct.StatisticsTracker.html?search= Returns the count of downloads that are currently in progress. This includes downloads that have started but have not yet completed, failed, or been canceled. ```rust pub async fn active_count(&self) -> usize ``` -------------------------------- ### Initialize Downloader with Custom Directories Source: https://docs.rs/yt-dlp/latest/yt_dlp/struct.Downloader.html?search=u32+-%3E+bool Demonstrates how to create a Downloader instance specifying custom directories for executables and output. This is useful for managing yt-dlp binaries and download locations. ```rust let executables_dir = PathBuf::from("libs"); let output_dir = PathBuf::from("output"); let downloader = Downloader::with_new_binaries(executables_dir, output_dir) .await? .build() .await?; ``` -------------------------------- ### Initialize Libraries Struct Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search= Example of creating a new Libraries instance with specified paths for yt-dlp and ffmpeg. ```rust let destination = PathBuf::from("libs"); let youtube = destination.join("yt-dlp"); let ffmpeg = destination.join("ffmpeg"); let libraries = Libraries::new(youtube, ffmpeg); ``` -------------------------------- ### Get Subtitle File Extension Source: https://docs.rs/yt-dlp/latest/yt_dlp/model/types/caption/struct.Subtitle.html Retrieves the file extension of the subtitle as a string slice. For example, it returns "vtt" or "srt". ```rust pub fn file_extension(&self) -> &str ``` -------------------------------- ### Filter Playlist Entries by Index Range (1-based) Source: https://docs.rs/yt-dlp/latest/yt_dlp/model/types/playlist/struct.Playlist.html Gets playlist entries within a specific index range, using 1-based indexing for start and end. This provides an alternative to 0-based range filtering. ```rust pub fn filter_by_index_range( &self, start_index: usize, end_index: usize, ) -> Vec<&PlaylistEntry> ``` -------------------------------- ### ArchiveError Search Examples Source: https://docs.rs/yt-dlp/latest/yt_dlp/error/enum.ArchiveError.html?search= Examples of how to search for ArchiveError enums. These examples demonstrate different query patterns. ```APIDOC ## ArchiveError Search ### Description Provides examples of search queries for ArchiveError enums. ### Example Searches * `std::vec` * `u32 -> bool` * `Option, (T -> U) -> Option` ``` -------------------------------- ### LibraryInstaller::install_youtube_from_repo Method Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.LibraryInstaller.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Asynchronously installs yt-dlp from a custom GitHub repository. Requires owner, repo, and optionally accepts an auth token and custom executable name. ```rust pub async fn install_youtube_from_repo( &self, owner: impl Into, repo: impl Into, auth_token: Option, custom_name: Option, ) -> Result ``` -------------------------------- ### LibraryInstaller::install_youtube Method Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.LibraryInstaller.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Asynchronously installs yt-dlp from the main repository. Accepts an optional custom name for the executable. ```rust pub async fn install_youtube( &self, custom_name: Option, ) -> Result ``` -------------------------------- ### Basic install_libraries Macro Usage Source: https://docs.rs/yt-dlp/latest/yt_dlp/macro.install_libraries.html This snippet shows the basic usage of the install_libraries macro to create a Libraries instance in a specified directory. Ensure the directory exists or can be created. ```rust let libs = install_libraries!("libs")?; ``` -------------------------------- ### Install ffmpeg Binary Only Source: https://docs.rs/yt-dlp/latest/yt_dlp/index.html?search=u32+-%3E+bool Installs only the ffmpeg binary to a specified destination. Use this if yt-dlp is managed separately or not needed. ```rust use yt_dlp::client::deps::LibraryInstaller; use std::path::PathBuf; #[tokio::main] pub async fn main() -> Result<(), Box> { let destination = PathBuf::from("libs"); let installer = LibraryInstaller::new(destination); let ffmpeg = installer.install_ffmpeg(None).await.unwrap(); Ok(()) } ``` -------------------------------- ### Install yt-dlp Binary Only Source: https://docs.rs/yt-dlp/latest/yt_dlp/index.html?search=u32+-%3E+bool Installs only the yt-dlp binary to a specified destination. Use this if ffmpeg is not needed or already managed separately. ```rust use yt_dlp::client::deps::LibraryInstaller; use std::path::PathBuf; #[tokio::main] pub async fn main() -> Result<(), Box> { let destination = PathBuf::from("libs"); let installer = LibraryInstaller::new(destination); let youtube = installer.install_youtube(None).await.unwrap(); Ok(()) } ``` -------------------------------- ### Get Download Statistics Snapshot Source: https://docs.rs/yt-dlp/latest/yt_dlp/struct.Downloader.html?search=u32+-%3E+bool Retrieves a snapshot of statistics for all downloads and metadata fetches. Use this to get aggregate metrics. ```rust let downloader = Downloader::builder(libs, "output").build().await?; // ... perform downloads ... let snapshot = downloader.statistics().snapshot().await; println!("Completed: {}", snapshot.downloads.completed); ``` -------------------------------- ### Basic DownloaderBuilder Usage Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/builder/struct.DownloaderBuilder.html Demonstrates creating a Downloader instance with required libraries, output directory, custom arguments, and a timeout. ```rust let libraries = Libraries::new(PathBuf::from("libs/yt-dlp"), PathBuf::from("libs/ffmpeg")); let downloader = DownloaderBuilder::new(libraries, PathBuf::from("output")) .with_args(vec!["--no-playlist".to_string()]) .with_timeout(std::time::Duration::from_secs(120)) .build() .await?; ``` -------------------------------- ### PartialRange::time_range Source: https://docs.rs/yt-dlp/latest/yt_dlp/download/engine/partial/enum.PartialRange.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a `PartialRange::TimeRange` variant. Validates that start time is non-negative and end time is greater than start time. ```APIDOC ## PartialRange::time_range ### Description Creates a `PartialRange::TimeRange` variant. Validates that start time is non-negative and end time is greater than start time. ### Arguments * `start`: `f64` - Start time in seconds (must be non-negative). * `end`: `f64` - End time in seconds (must be greater than `start`). ### Returns A `PartialRange` instance representing the time range. ### Errors Returns an error if `start` is negative or `start >= end`. ``` -------------------------------- ### Install Dependencies Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.Libraries.html?search=u32+-%3E+bool Asynchronously installs the required dependencies for yt-dlp. This method returns a Result containing the updated Libraries struct upon success. ```rust self.install_dependencies().await?; ``` -------------------------------- ### Downloader::with_new_binaries Source: https://docs.rs/yt-dlp/latest/yt_dlp/struct.Downloader.html?search=u32+-%3E+bool Creates a new YouTube fetcher, and installs the yt-dlp and ffmpeg binaries. The output directory can be void if you only want to fetch the video information. Be careful, this function may take a while to execute. ```APIDOC ## Downloader::with_new_binaries ### Description Creates a new YouTube fetcher, and installs the yt-dlp and ffmpeg binaries. The output directory can be void if you only want to fetch the video information. Be careful, this function may take a while to execute. ### Arguments * `executables_dir` - The directory where the binaries will be installed. * `output_dir` - The directory where the video will be downloaded. ### Errors This function will return an error if the executables could not be installed. ``` -------------------------------- ### Downloader::with_new_binaries Source: https://docs.rs/yt-dlp/latest/yt_dlp/struct.Downloader.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new YouTube fetcher, and installs the yt-dlp and ffmpeg binaries. The output directory can be void if you only want to fetch the video information. Be careful, this function may take a while to execute. ```APIDOC ## Downloader::with_new_binaries ### Description Creates a new YouTube fetcher, and installs the yt-dlp and ffmpeg binaries. The output directory can be void if you only want to fetch the video information. Be careful, this function may take a while to execute. ### Method `with_new_binaries` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Arguments * `executables_dir` - The directory where the binaries will be installed. * `output_dir` - The directory where the video will be downloaded. ### Errors This function will return an error if the executables could not be installed. ### Returns A `Result`. ``` -------------------------------- ### Initialize Downloader with Libraries Source: https://docs.rs/yt-dlp/latest/yt_dlp/struct.Downloader.html?search= Initializes the Downloader with specified library paths and an output directory. This is a prerequisite for most download operations. ```rust let libraries = Libraries::new(PathBuf::from("libs/yt-dlp"), PathBuf::from("libs/ffmpeg")); let downloader = Downloader::builder(libraries, "output").build().await?; ``` -------------------------------- ### Get Statistics Snapshot Source: https://docs.rs/yt-dlp/latest/yt_dlp/index.html?search=u32+-%3E+bool Use the `snapshot()` method on the downloader's statistics object to get an atomic view of metrics. This is useful for monitoring download progress and success rates. ```rust use yt_dlp::Downloader; use yt_dlp::client::deps::Libraries; use std::path::PathBuf; #[tokio::main] async fn main() -> Result<(), Box> { let libraries = Libraries::new(PathBuf::from("libs/yt-dlp"), PathBuf::from("libs/ffmpeg")); let downloader = Downloader::builder(libraries, "output").build().await?; // Perform some downloads and fetches ... let video = downloader.fetch_video_infos("https://youtube.com/watch?v=...".to_string()).await?; downloader.download_video(&video, "video.mp4").await?; let snapshot = downloader.statistics().snapshot().await; println!("Downloads completed: {}", snapshot.downloads.completed); println!("Total bytes: {}", snapshot.downloads.total_bytes); println!("Avg speed (B/s): {:?}", snapshot.downloads.avg_speed_bytes_per_sec); println!("Download success %: {:?}", snapshot.downloads.success_rate); println!("Fetch success %: {:?}", snapshot.fetches.success_rate); println!("Post-process success: {:?}", snapshot.post_processing.success_rate); Ok(()) } ``` -------------------------------- ### LibraryInstaller::install_youtube_from_repo Method Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.LibraryInstaller.html?search=u32+-%3E+bool Installs yt-dlp from a custom GitHub repository. Requires owner and repo names, and optionally accepts an authentication token and custom executable name. ```rust pub async fn install_youtube_from_repo( &self, owner: impl Into, repo: impl Into, auth_token: Option, custom_name: Option, ) -> Result ``` -------------------------------- ### LibraryInstaller::install_youtube Method Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.LibraryInstaller.html?search=u32+-%3E+bool Installs yt-dlp from the main repository. Allows for an optional custom name for the executable. ```rust pub async fn install_youtube( &self, custom_name: Option, ) -> Result ``` -------------------------------- ### LiveStreamBuilder Source: https://docs.rs/yt-dlp/latest/yt_dlp/live/struct.LiveStreamBuilder.html Fluent builder for configuring and starting a live fragment stream. Created via `Downloader::stream_live`. Allows configuring format selection, maximum duration, and cancellation token before starting. ```APIDOC ## LiveStreamBuilder Fluent builder for configuring and starting a live fragment stream. Created via `Downloader::stream_live`. Allows configuring format selection, maximum duration, and cancellation token before starting. ### Methods #### `with_max_duration(self, duration: Duration) -> Self` Sets the maximum streaming duration. * **Arguments** * `duration` (Duration) - Maximum time to stream before automatically stopping. #### `with_format(self, format: &'a Format) -> Self` Selects a specific HLS format for streaming. If not set, the best quality live format is automatically selected. * **Arguments** * `format` (Format) - The HLS format to stream. #### `with_cancellation_token(self, token: CancellationToken) -> Self` Sets a custom cancellation token. If not set, the downloader’s cancellation token is used. * **Arguments** * `token` (CancellationToken) - The cancellation token to control streaming lifecycle. #### `execute(self) -> Result` Starts streaming live fragments. * **Returns** * `Result` - A `LiveFragmentStream` that yields HLS fragments as they are downloaded. * **Errors** * Returns an error if the video is not a live stream, no HLS format is available, or the streaming engine encounters an error. ``` -------------------------------- ### LiveRecordingBuilder Source: https://docs.rs/yt-dlp/latest/yt_dlp/live/struct.LiveRecordingBuilder.html?search=std%3A%3Avec Fluent builder for configuring and starting a live recording. Created via `Downloader::record_live`. Allows configuring the recording method, format selection, maximum duration, and cancellation token before starting. ```APIDOC ## Struct LiveRecordingBuilder Fluent builder for configuring and starting a live recording. Created via `Downloader::record_live`. Allows configuring the recording method, format selection, maximum duration, and cancellation token before starting. ### Methods #### `with_method(self, method: RecordingMethod) -> Self` Sets the recording method. * `method`: `RecordingMethod::Native` (default) or `RecordingMethod::Fallback`. #### `with_max_duration(self, duration: Duration) -> Self` Sets the maximum recording duration. * `duration`: Maximum time to record before automatically stopping. #### `with_format(self, format: &'a Format) -> Self` Selects a specific HLS format for recording. If not set, the best quality live format is automatically selected. * `format`: The HLS format to record. #### `with_cancellation_token(self, token: CancellationToken) -> Self` Sets a custom cancellation token. If not set, the downloader’s cancellation token is used. * `token`: The cancellation token to control recording lifecycle. #### `execute(self) -> Result` Starts a live recording and writes it to a file. * **Errors**: Returns an error if the video is not a live stream, no HLS format is available, or the recording engine encounters an error. * **Returns**: A `RecordingResult` containing recording statistics. ``` -------------------------------- ### Creating Time Range with Function Source: https://docs.rs/yt-dlp/latest/yt_dlp/download/engine/partial/enum.PartialRange.html Uses the `time_range` associated function to create a `PartialRange::TimeRange` variant. This function validates that the start time is non-negative and the end time is greater than the start time. ```rust pub fn time_range(start: f64, end: f64) -> Result ``` -------------------------------- ### LibraryInstaller::install_ffmpeg Method Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.LibraryInstaller.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Asynchronously installs ffmpeg from static builds. Accepts an optional custom name for the executable. ```rust pub async fn install_ffmpeg( &self, custom_name: Option, ) -> Result ``` -------------------------------- ### entries_with_thumbnails Source: https://docs.rs/yt-dlp/latest/yt_dlp/model/types/playlist/struct.Playlist.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets all entries with thumbnails. ```APIDOC ### fn entries_with_thumbnails(&self) -> Vec<&PlaylistEntry> Gets all entries with thumbnails. #### Returns Returns a vector of entries that have thumbnail URLs ``` -------------------------------- ### entries_with_thumbnails Source: https://docs.rs/yt-dlp/latest/yt_dlp/model/types/playlist/struct.Playlist.html?search= Gets all entries with thumbnails. ```APIDOC ## fn entries_with_thumbnails(&self) -> Vec<&PlaylistEntry> Gets all entries with thumbnails. ### Returns Returns a vector of entries that have thumbnail URLs ``` -------------------------------- ### Initialize and use StatisticsTracker Source: https://docs.rs/yt-dlp/latest/yt_dlp/stats/struct.StatisticsTracker.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to initialize a Downloader, perform downloads, and then retrieve statistics using StatisticsTracker.snapshot(). ```rust let libraries = Libraries::new(PathBuf::from("libs/yt-dlp"), PathBuf::from("libs/ffmpeg")); let downloader = Downloader::builder(libraries, "output").build().await?; // ... perform downloads ... let snapshot = downloader.statistics().snapshot().await; println!("Completed: {}", snapshot.downloads.completed); println!("Total bytes: {}", snapshot.downloads.total_bytes); ``` -------------------------------- ### ChapterList::with_titles Source: https://docs.rs/yt-dlp/latest/yt_dlp/model/types/chapter/struct.ChapterList.html?search= Gets all chapters that have titles. ```APIDOC ## ChapterList::with_titles ### Description Gets all chapters that have titles. ### Method Instance Method ### Returns - **Vec<&'a Chapter>** - Returns a vector of references to chapters with titles. ``` -------------------------------- ### Basic Event Stream Handling Source: https://docs.rs/yt-dlp/latest/yt_dlp/events/index.html Demonstrates how to set up a downloader and stream events, processing only download completion events. ```rust use tokio_stream::StreamExt; let downloader = Downloader::builder(libraries, output_dir).build().await?; let mut stream = downloader.event_stream(); while let Some(Ok(event)) = stream.next().await { match &*event { DownloadEvent::DownloadCompleted { download_id, output_path, .. } => { println!("Download {} completed: {:?}", download_id, output_path); } _ => {} } } ``` -------------------------------- ### Fetcher::with_range Source: https://docs.rs/yt-dlp/latest/yt_dlp/download/engine/fetcher/struct.Fetcher.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Constrains the download to `[start, end]` bytes of the URL. When set, [`fetch_asset`] downloads only those bytes and writes them starting from offset 0 in the destination file. HTTP requests still use absolute `Range: bytes=start-end` headers against the URL. ```APIDOC ## Fetcher::with_range ### Description Constrains the download to `[start, end]` bytes of the URL. When set, [`fetch_asset`] downloads only those bytes and writes them starting from offset 0 in the destination file. HTTP requests still use absolute `Range: bytes=start-end` headers against the URL. ### Arguments * `start` - First byte to download (URL-absolute, inclusive). * `end` - Last byte to download (URL-absolute, inclusive). ### Returns `Self` for method chaining. ``` -------------------------------- ### BuildFetcher::new Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/ffmpeg/struct.BuildFetcher.html Creates a new instance of the BuildFetcher, ready to fetch FFmpeg binaries. ```APIDOC ## BuildFetcher::new ### Description Creates a new fetcher for ffmpeg. ### Method `new()` ### Returns A new `BuildFetcher` instance. ``` -------------------------------- ### try_extension Source: https://docs.rs/yt-dlp/latest/yt_dlp/utils/fs/index.html?search= Gets the file extension from a path, lowercased. ```APIDOC ## Function: try_extension ### Description Retrieves the file extension from a given path and converts it to lowercase. ### Parameters * **path** (Path) - The path from which to get the extension. ### Returns * Option - The lowercase file extension, or None if the path has no extension. ``` -------------------------------- ### try_extension Source: https://docs.rs/yt-dlp/latest/yt_dlp/utils/fs/index.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets the file extension from a path, lowercased. ```APIDOC ## try_extension ### Description Gets the file extension from a path, lowercased. ### Parameters * **path** (Path) - The path to get the extension from. ### Returns * **Option** - The lowercased file extension, if present. ``` -------------------------------- ### LibraryInstaller::install_youtube_from_repo Source: https://docs.rs/yt-dlp/latest/yt_dlp/client/deps/struct.LibraryInstaller.html?search=std%3A%3Avec Installs yt-dlp from a custom repository, assuming releases assets are named correctly. ```APIDOC ## LibraryInstaller::install_youtube_from_repo ### Description Installs yt-dlp from a custom repository, assuming releases assets are named correctly. ### Signature ```rust pub async fn install_youtube_from_repo( &self, owner: impl Into, repo: impl Into, auth_token: Option, custom_name: Option, ) -> Result ``` ### Arguments * `owner` - `impl Into`: The owner of the repository. * `repo` - `impl Into`: The name of the repository. * `auth_token` - `Option`: Optional GitHub token to avoid rate limits. * `custom_name` - `Option`: Optional custom name for the executable. ``` -------------------------------- ### Example Usage of StatisticsTracker Source: https://docs.rs/yt-dlp/latest/yt_dlp/stats/index.html?search= Demonstrates how to initialize the Downloader, perform operations, and then access a snapshot of download and fetch statistics. Ensure the 'statistics' feature is enabled. ```rust use std::path::PathBuf; use yt_dlp::Downloader; use yt_dlp::client::deps::Libraries; #[tokio::main] async fn main() -> std::result::Result<(), Box> { let libraries = Libraries::new(PathBuf::from("libs/yt-dlp"), PathBuf::from("libs/ffmpeg")); let downloader = Downloader::builder(libraries, "output").build().await?; // ... perform downloads and fetches ... let snapshot = downloader.statistics().snapshot().await; println!("Completed: {}", snapshot.downloads.completed); println!("Total bytes: {}", snapshot.downloads.total_bytes); println!( "Avg speed (B/s): {:?}", snapshot.downloads.avg_speed_bytes_per_sec ); println!("Fetch success %: {:?}", snapshot.fetches.success_rate); Ok(()) } ``` -------------------------------- ### get_entries_in_range Source: https://docs.rs/yt-dlp/latest/yt_dlp/model/types/playlist/struct.Playlist.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets all entries within a range (inclusive). ```APIDOC ### fn get_entries_in_range(&self, start: usize, end: usize) -> &[PlaylistEntry] Gets all entries within a range (inclusive). #### Arguments - **start** (usize) - The start index (0-based) - **end** (usize) - The end index (0-based, inclusive) #### Returns A slice of entries within the specified range ``` -------------------------------- ### get_entries_in_range Source: https://docs.rs/yt-dlp/latest/yt_dlp/model/types/playlist/struct.Playlist.html?search= Gets all entries within a range (inclusive). ```APIDOC ## fn get_entries_in_range(&self, start: usize, end: usize) -> &[PlaylistEntry] Gets all entries within a range (inclusive). ### Arguments - `start`: usize - The start index (0-based) - `end`: usize - The end index (0-based, inclusive) ### Returns A slice of entries within the specified range ``` -------------------------------- ### Initialize Downloader Source: https://docs.rs/yt-dlp/latest/yt_dlp/struct.Downloader.html?search=u32+-%3E+bool Initializes a new Downloader instance. Ensure libraries and output directory are provided. ```rust let downloader = Downloader::builder(libraries, output_dir).build().await?; ``` -------------------------------- ### get_entry_by_index Source: https://docs.rs/yt-dlp/latest/yt_dlp/model/types/playlist/struct.Playlist.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets a playlist entry by its index (0-based). ```APIDOC ### fn get_entry_by_index(&self, index: usize) -> Option<&PlaylistEntry> Gets a playlist entry by its index (0-based). #### Arguments - **index** (usize) - The 0-based index of the entry #### Returns A reference to the entry at the given index, or `None` if out of bounds ``` -------------------------------- ### get_entry_by_index Source: https://docs.rs/yt-dlp/latest/yt_dlp/model/types/playlist/struct.Playlist.html?search= Gets a playlist entry by its index (0-based). ```APIDOC ## fn get_entry_by_index(&self, index: usize) -> Option<&PlaylistEntry> Gets a playlist entry by its index (0-based). ### Arguments - `index`: usize - The 0-based index of the entry ### Returns A reference to the entry at the given index, or `None` if out of bounds ``` -------------------------------- ### Building FFmpeg Arguments with FfmpegArgs Source: https://docs.rs/yt-dlp/latest/yt_dlp/executor/ffmpeg/struct.FfmpegArgs.html Example demonstrating how to use the FfmpegArgs builder to construct a complex FFmpeg command. This includes setting multiple inputs, mapping streams, copying codecs, and specifying an output file. ```rust use yt_dlp::executor::FfmpegArgs; let args = FfmpegArgs::new() .input("/tmp/input.mp4") .input("/tmp/audio.mp3") .args(["-map", "0:v", "-map", "1:a"]) .codec_copy() .output("/tmp/output.mkv") .build(); ``` -------------------------------- ### ChapterList::count Source: https://docs.rs/yt-dlp/latest/yt_dlp/model/types/chapter/struct.ChapterList.html?search= Gets the total number of chapters. ```APIDOC ## ChapterList::count ### Description Gets the total number of chapters. ### Method Instance Method ### Returns - **usize** - The total number of chapters. ``` -------------------------------- ### Create and Execute an Executor Source: https://docs.rs/yt-dlp/latest/yt_dlp/executor/struct.Executor.html?search=u32+-%3E+bool Demonstrates how to create a new Executor instance with a specified executable path, arguments, and timeout, and then execute the command, capturing its standard output. ```rust let args = vec!["--update"]; let executor = Executor::new( PathBuf::from("yt-dlp"), utils::to_owned(args), Duration::from_secs(30), ); let output = executor.execute().await?; println!("Output: {}", output.stdout); ```