A
A
Andrew2018-02-22 16:05:39
YouTube
Andrew, 2018-02-22 16:05:39

How to get the original YouTube video link?

How to get the original YouTube video link, similar to many video download services. After a bit of searching, I found several articles:

  • stackoverflow
  • Habr
The first one even contains JavaScript code, but when I started writing something similar, I ran into some problems:
  1. Multiple hits to ' https://www.youtube.com/get_video_info?video_id={V... return differently structured information. For example: On the first visit 5a8ebd701af38380963535.jpegOn the second visit 5a8ebdb6465d3949903363.jpegDo not say that this is a problem, because the links are still there.
  2. Due to the incomprehensible (to me) structure of this information, I can’t figure out how I can still correctly break down all the information and, suppose, create an array VIDEO_RESOLUTION => LINK_TO_CORRESPONDING FORMAT

And finally, a draft implementation that occasionally works
$config = urldecode(file_get_contents('https://www.youtube.com/get_video_info?video_id='.$id));
  $end = array();

  echo '<pre>';

  foreach ( explode('&', $config) as $key => $value ) 
  {
    array_push( $end, explode( '=', $value ) );
  }

  foreach ( $end as $el ) 
  {
    if( $el[0] == 'url' )
      echo '<a href="'.urldecode($el[1]).'">'.urldecode($el[1]).'</a><br>';
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
doublench21, 2018-02-22
@null_object

Why bother if there is youtube-dl
Actually, you call youtube-dl from php and get an array of links. I immediately warn you that the links to the videos are in quality up to 720p. For higher quality, you will need to merge the video and audio track, because. they go separately. (ffmpeg to the rescue)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question