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

Not able to get URLs from Age Restricted videos, even though setting cookies

Open fightveryexplosion opened this issue 3 years ago • 1 comments

Hello. First of all, thank you so much for a very helpful library! It works flawlessly and I am thrilled to have found such a stabile version of youtube-dl that is actually made in PHP instead of Python.

I'm having trouble with getting the URLs for age restricted videos. I have downloaded my Youtube cookies into a .txt file, and tried setting it like below;

$youtube = new YouTubeDownloader();
$youtube->getBrowser()->setCookieFile('{actual path to directory}/youtube_cookies.txt');

try {
    $downloadOptions = $youtube->getDownloadLinks("https://www.youtube.com/watch?v=".$videoID);
    $urls = array();
      if ($downloadOptions->getAllFormats()) {
	      foreach ($downloadOptions->getAllFormats() as $format) {
		     
		      $url = $format->url;
		     echo $url;
	      }
		        
      } else {
	      http_response_code(404);
              exit();
      }
    
      
} catch (YouTubeException $e) {
  http_response_code(404);
  exit();
}

What happens is that no exception is thrown, and instead getAllFormats() is empty. The details of the video, (the title and description, etc) are returned without problem.

I have also tried the same cookies file out with youtube-dl and I was able to get the URLs without problem, but while using Youtube-Downloader it just doesn't seem to work.

I have tried a couple of age restricted videos and none work. These are a few of the ones I have tried;

https://www.youtube.com/watch?v=x8VYWazR5mE https://www.youtube.com/watch?v=eDY_Jdbhjyk https://www.youtube.com/watch?v=NIABFcVB3Is

Any advice or help with solving this would be greatly appreciated! If there is any additional information I can provide, let me know! Thank you.

fightveryexplosion avatar Jan 25 '22 07:01 fightveryexplosion

I have an alternate package that works:

package main
import "github.com/89z/mech/youtube"

func main() {
   ids := []string{"x8VYWazR5mE", "eDY_Jdbhjyk", "NIABFcVB3Is"}
   for _, id := range ids {
      play, err := youtube.Embed.Player(id)
      if err != nil {
         panic(err)
      }
      println(play.StreamingData.AdaptiveFormats[0].URL)
   }
}

89z avatar Feb 06 '22 20:02 89z

Did you fix it ?

felipe-silveira-dev avatar Aug 01 '23 19:08 felipe-silveira-dev