Athlon1600 / youtube-downloader

:tv: PHP based alternative to youtube-dl and yt-dlp. Active and frequently updated! :star:
https://unblockvideos.com/
MIT License
801 stars 315 forks source link

Can't load another url when video is playing #85

Open taavandais2 opened 3 years ago

taavandais2 commented 3 years ago

Thank for create an awesome library!

I'm using your library in my Laravel project, it's work. But, when i use stream function my web can't open another urls and resources. And, in Safari on MacOS, it works well in localhost. But, when i publish to heroku hosting, it can't play video (the same direct link work well on Chrome).

This is stream function: $youtube = new \YouTube\YouTubeStreamer(); $youtube->stream('https://r4---sn-n4v7knll.googlevideo.com/videoplayback?...');

AgentSmith0 commented 3 years ago

The returning video urls are only for a specific client ip address. Your heroku app must parse a video url and then stream it. Try the following code, the $url variable is the full link to your YouTube video (the code is for the latest version):


$youtube = new \YouTube\YouTubeDownloader();

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

$best = $links->getFirstCombinedFormat();

if ($best) {
    $youtube = new \YouTube\YouTubeStreamer();
    $youtube->stream($best->url);
}