youtube-downloader icon indicating copy to clipboard operation
youtube-downloader copied to clipboard

Does not fetch the best quality link

Open CyberPunkCodes opened this issue 2 years ago • 4 comments

This doesn't fetch the best quality video source, it simply grabs the first one from the combined (video/audio) list returned.

You need to sort through the combined results, compare the widths, and return the one with the largest size.

Something as simple as this in DownloadOptions:

public function getBestCombinedFormat()
{
    $combined = $this->getCombinedFormats();

    $bestResult = null;
    $bestWidth = 0;

    foreach($combined as $test) {
        if ( isset($test->width) && ($test->width > $bestWidth) ) {
            $bestWidth = $test->width;
            $bestResult = $test;
        }
    }

    return $bestResult;
}

Then update in the try/catch in video_info.php:

$links = $youtube->getDownloadLinks($url);
$best = $links->getBestCombinedFormat();

CyberPunkCodes avatar Jul 31 '21 19:07 CyberPunkCodes

YouTube-DL does this, and I think its a terrible idea. You dont want to just sort the results, you want to also filter them. For example, with this 10 minute video [1], here are some of the results:

itag 315, height 2160, 26.8 mb/s, 1.5 GB, video/webm; codecs="vp9"
itag 308, height 1440, 13.3 mb/s, 545.1 MB, video/webm; codecs="vp9"
itag 303, height 1080, 4.5 mb/s, 204.0 MB, video/webm; codecs="vp9"
itag 302, height 720, 2.7 mb/s, 124.3 MB, video/webm; codecs="vp9"

I think in general, most people would be fine with defaulting to 720p, which in this case is 125 MB. If we just blindly take the highest quality, youre downloading 1.5 GB instead. Some people may need or want the 4K result, but I dont think it should be the default.

  1. https://www.youtube.com/watch?v=aqz-KE-bpKQ

89z avatar Aug 01 '21 15:08 89z

I understand what you are saying, but I would imagine most people want the highest quality available in most situations.

If I lost my backup HD and I need to download ALL of my old YouTube videos, why would I want an even worse quality version? When you upload it the first time, YouTube compresses it. So it's already a quality hit compared to your original. In the example above, the 1.5GB is as close to your original quality as you can get. So in the sense of using a tool like this to recover copies of all of your old uploaded videos (hard drive failed or whatever), you would always want the best quality version you can get to be as close to the original.

Downloading 1.5GB isn't a problem for most people's internet today.

User configurable options would work. Maybe allow them to take the best quality/largest size available regardless, or choose an ideal size (like 720 or 1080), or a file size limit (ie: don't take videos 1GB or larger). Instead of starting the download, you could return the results and let them choose which one they want.

It is always best to provide the developer with configurable options, or the user with choices, instead of forcing your choice on them. 1.5GB may seem large to you, but isn't anything for others to download.

CyberPunkCodes avatar Sep 01 '21 15:09 CyberPunkCodes

Dude this isn't even your repo lol..

Get lost and go troll your own projects.

Edit: And then he deletes all of his comments when he realizes the embarrassing error he made.

CyberPunkCodes avatar Sep 01 '21 19:09 CyberPunkCodes

sorter code no need loop, it already sorted lowest to highest

public function getBestCombinedFormat()
{
    $combined = $this->getCombinedFormats();
    $count = count($combined);
    return $count ? $combined[$count-1] : null;
}

ewwink avatar Nov 29 '21 21:11 ewwink