Skip to content

Often get multiple video files downloaded, don't always get something that plays #72

@MrYossu

Description

@MrYossu

I am using this package in a Blazor server-side app,. I have a page where people can search YT, and click a button to download the video.

The download method takes a `` object, which contain the info about the video, as well as some properties that are used to updatethe UI with progress. Here is a (slightly simplified version of) the code...

  private async Task Download(SearchResult result) {
    result.DownloadButtonColour = ThemeConstants.Button.ThemeColor.Warning;
    result.Progress = "Downloading...";
    Progress<double> progress = new();
    progress.ProgressChanged += (_, d) => {
      result.Progress = $"{d * 100:F0}%";
      StateHasChanged();
    };
    YoutubeDL ytdl = new() {
      YoutubeDLPath = @$"{_path}\yt-dlp_x86.exe",
      FFmpegPath = @$"{_path}\ffmpeg.exe"
    };
    Progress<DownloadProgress> downloadProgress = new(p => {
      result.Progress = $"{p.Progress * 100:F0}%";
      StateHasChanged();
    });
    RunResult<string> videoRes = await ytdl.RunVideoDownload(result.Url,
      overrideOptions: new OptionSet {
        WindowsFilenames = true,
        // The Clean method ensures the title is safe for filenames
        Output = $"{Clean(result.Title)}.%(ext)s",
        Paths = Path.Combine(_path, "Downloads")
      },
      progress: downloadProgress);
    Console.WriteLine($"Written to {videoRes.Data}");
    result.Progress = SearchResult.ProgressDefault;
    result.DownloadButtonColour = ThemeConstants.Button.ThemeColor.Primary;
  }

This works, but not very well. As an example, I tried this on the following video...

https://www.youtube.com/watch?v=acbrnHYC9a0

I tried it four times, using the video title with a number added at the end. The first two attempts gave a single file each, but with very different sizes. The third attempt gave two files, and the fourth attempt gave three, as you can see...

Image

This happens pretty much every time I run this code, it's not specific to this video.

The smaller files are almost always either audio only, or don't play at all. Of the larger files, some play OK, but many will only play correctly for a short while, then the video freezes, and I'm left with just audio. Often there are skips.

Even out of the videos that work, I will get quite different file sizes using the same video and the same code.

I have very similar code for downloading just the audio. The only real difference is the following two lines...

      RunResult<string> audioRes = await ytdl.RunAudioDownload(result.Url,
        AudioConversionFormat.Mp3,

This will often download multiple files, some .mp3 and some .mp4. Generally the .mp3 files play OK, but it's quite common for them to skip whilst playing.

Anyone able to advise? How can I get it to download just one video or audio that plays correctly?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions