Using get_video on YouTube to download a video

前端 未结 3 916
醉酒成梦
醉酒成梦 2021-02-09 15:26

I am trying to get the video URL of any YouTube video like this:

Open

http://youtube.com/get_video_info?video_id=VIDEOID

then take the

相关标签:
3条回答
  • 2021-02-09 15:59

    Sorry, that is not possible anymore. They limit the token to the IP that got it.

    Here's a workaround by using the get_headers() function, which gives you an array with the link to the video. I don't know anything about ios, so hopefully you can rewrite this PHP code yourself.

    <?php
    if(empty($_GET['id'])) {
        echo "No id found!";
    }
    
    else {
    
        function url_exists($url) {
            if(file_get_contents($url, FALSE, NULL, 0, 0) === false) return false;
            return true;
        }
    
        $id = $_GET['id'];
    
        $page = @file_get_contents('http://www.youtube.com/get_video_info?&video_id='.$id);
    
        preg_match('/token=(.*?)&thumbnail_url=/', $page, $token);
    
        $token = urldecode($token[1]);
    
        $get = $title->video_details;
    
        $url_array = array ("http://youtube.com/get_video?video_id=".$id."&t=".$token,
        "http://youtube.com/get_video?video_id=".$id."&t=".$token."&fmt=18");
    
        if(url_exists($url_array[1]) === true) {
            $file = get_headers($url_array[1]);
        }
    
        elseif(url_exists($url_array[0]) === true) {
            $file = get_headers($url_array[0]);
        }
    
        $url = trim($file[19],"Location: ");
    
        echo '<a href="'.$url.'">Download video</a>';
    }
    ?>
    
    0 讨论(0)
  • 2021-02-09 15:59

    Great! I needed a way to grab a whole playlist of videos.

    In Linux, this is what I used:

    y=http://www.youtube.com; f="http://gdata.youtube.com/feeds/api/playlists/PLeHqhPDNAZY_3377_DpzRSMh9MA9UbIEN?start-index=26"; for i in $(curl -s $f |grep -o "url='$y/watch?v=[^']'");do d=$(echo $i|sed "s|url\='$y/watch?v=(.)&.*'|\1|"); youtube-dl --restrict-filenames "$y/watch?v=$d"; done

    You have to find the playlist ID from a common Youtube URL like: https://www.youtube.com/playlist?list=PLeHqhPDNAZY_3377_DpzRSMh9MA9UbIEN

    Also, this technique uses gdata API, limiting 25 records per page.
    Hence the ?start-index=26 parameter (to get page 2 in my example)

    This could use some cleaning, and extra logic to iterate thru all sets of 25, too.

    Credits:

    https://stackoverflow.com/a/8761493/1069375

    http://www.commandlinefu.com/commands/view/3154/download-youtube-playlist (which itself didn't quite work)

    0 讨论(0)
  • 2021-02-09 16:04

    I use this and it rocks: http://rg3.github.com/youtube-dl/

    Just copy a YouTube URL from your browser and execute this command with the YouTube URL as the only argument. It will figure out how to find the best quality video and download it for you.

    0 讨论(0)
提交回复
热议问题