Code Monkey home page Code Monkey logo

Comments (1)

kgtm avatar kgtm commented on September 26, 2024

Make sure your get_url_map($data) function in youtube-dl.class.php looks like this (look bellow). Basically you only need to add $videos = false; to the beginning of the function, seems the developer forgot to initialize the variable.
Another likely explanation is: the developer expected if(!isset($match[1])) { return FALSE; } to step in the event something went wrong with the process of finding the urls for each available stream (quality and format) for a given Youtube video, and return false as this function was supposed to.
Either way, since $videos is now initialized to false, when this function is unable to find the streams urls it will return false, and when it does find the streams it will return them instead.

/**
     *  Get the URL map for a YouTube Video.
     *  @access  private
     *  @param   string   $data  Info-File contents for a YouTube Video.
     *  @return  mixed    Returns an array, containg the Video URL map,
     *                    or (boolean) FALSE if extracting failed.
     */
    private function get_url_map($data)
    {
        $videos = false;
        preg_match('/stream_map=(.[^&]*?)&/i',$data,$match);
        if(!isset($match[1])) {
            return FALSE;
        }
        else {
            $fmt_url = urldecode($match[1]);
            if(preg_match('/^(.*?)\\\\u0026/',$fmt_url,$match2)) {
                $fmt_url = $match2[1];
            }

            $urls = explode(',',$fmt_url);
            $tmp = array();

            foreach($urls as $url) {
                if(preg_match('/itag=([0-9]+)&url=(.*?)&.*?/si',$url,$um))
                {
                    $u = urldecode($um[2]);
                    $tmp[$um[1]] = $u;
                }
            }

            $formats = array(
                '13' => array('3gp', '240p', '10'),
                '17' => array('3gp', '240p', '9'),
                '36' => array('3gp', '320p', '8'),
                '5' => array('flv', '240p', '7'),
                '6' => array('flv', '240p', '6'),
                '34' => array('flv', '320p', '5'),
                '35' => array('flv', '480p', '4'),
                '18' => array('mp4', '480p', '3'),
                '22' => array('mp4', '720p', '2'),
                '37' => array('mp4', '1080p', '1')
            );

            foreach ($formats as $format => $meta) {
                if (isset($tmp[$format])) {
                    $videos[] = array('pref' => $meta[2], 'ext' => $meta[0], 'type' => $meta[1], 'url' => $tmp[$format]);
                }
            }
            return $videos;
        }
    }

Note:
If this function is unable to extract the streams urls, php-yt-downloader will be unable to download any video. In the event this happens several times, this could mean the function's code responsible for extracting the urls needs to be updated.
This functions receives the content of: http://www.youtube.com/get_video_info?video_id=aahOEZKTCzU&el=embedded&ps=default&eurl=&hl=en_US (where "aahOEZKTCzU" is the ID of the Youtube video) and searches for the urls there after the &url_encoded_fmt_stream_map= section up until before &fallback_host=.
Now you know this, case this function needs update, you might be able to do it yourself.

Another Note: This same content is also passed to Youtube's Flash Player (using javascript to send flash vars to the player) on the regular video viewing page, for example: http://www.youtube.com/watch?v=aahOEZKTCzU, this was how I about 2 years ago did something like this php-yt-downloader class to download youtube videos for my own computer. Fortunately (and congratulations to eyecatchup) though the same, improved on it, and found a way to retrieve only the required pieces (stripping HTML, JavaScript and CSS, therefore maximizing performance) by accessing the required content from: http://www.youtube.com/get_video_info?video_id=aahOEZKTCzU&el=embedded&ps=default&eurl=&hl=en_US

Hope this helps you, and anybody else seeking to update this function, everytime Youtube changes it's own method of making streams available to it's own player. Whenever time allows it, I will too post answers to other issues.
Be well.

from php-yt_downloader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.