GyrosOfWar / youtube-dl-rs

A youtube-dl wrapper for Rust
132 stars 40 forks source link

Program Not Found ? #44

Closed JamalLyons closed 1 year ago

JamalLyons commented 1 year ago

Error when using lib:

thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()`
on an `Err` value: AppError { status: false, message: "Failed to download video: io error: program not found" }',

I got this when trying the code.

In my toml:

youtube_dl = "0.8.0"

A little code example:

/// Downloads the audio from a youtube video.
pub fn download_youtube_audio(
    video_url: &str,
    video_type_def: VideoLinkType,
) -> Result<(), AppError> {
    let video_type = get_video_type(video_type_def);

    if video_type == "playlist" {
        // ...
    } else if video_type == "video" {
        let output = create_ytdl(video_url)
            .unwrap()
            .run()
            .map_err(|e| AppError {
                status: false,
                message: format!("Failed to download video: {}", e),
            })?
            .into_single_video()
            .unwrap();

        println!("Video: {:#?}", output);
    } else {
        return Err(AppError {
            status: false,
            message: format!("Invalid video type: {}", video_type),
        });
    }

    Ok(())
}
fn create_ytdl(video_url: &str) -> Result<YoutubeDl, AppError> {
    let mut ytdl = YoutubeDl::new(video_url);

    ytdl.extract_audio(true);
    ytdl.output_template("%(title)s.%(ext)s");
    ytdl.download(true);
    ytdl.format("mp3");

    // Download the thumbnail for this audio as well.
    ytdl.extra_arg("--write-thumbnail");

    Ok(ytdl)
}
GyrosOfWar commented 1 year ago

Have you actually installed yt-dlp? If you enable the downloader feature flag, you can also let the library download it for you.