Any chance to get working Youtube download code?

Status
Not open for further replies.
14 comments
If you mean the youtube video download code, then check the rapidleech youtube class.

Their download class works flawless and supports different resolution and format.
Once you get the video convert it to mp3 using ffmpeg.

Hope it helps.
 
Goes like this:

PHP:
        $d = file_get_contents("http://www.youtube.com/get_video_info?&video_id={$youtubeId}&el=detailpage&ps=default&eurl=&gl=US&hl=en");

        parse_str($d, $array);

        $formats = explode(',', $array['url_encoded_fmt_stream_map']);

        $streams = array();

        foreach ($formats as $format)
        {
            parse_str($format, $formatArray);
            
            $streams[$formatArray['itag']] = "{$formatArray['url']}&fallback_host={$formatArray['fallback_host']}&signature={$formatArray['sig']}";
            
        }
$streams contains the video url's indexed by the video itag. Info about itag: http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs

I've not figured out yet how to bypass the ratelimit (i.e. slow download speed) for all $streams. It's possible to add "&ratelimit=false" to some video url's, but for some it doesn't work.
 
Well of course you have to implement error handling and validation. Put that snippet in a function/method and return false or throw exception.

// What I wrote above about ratlimit was a little wrong. It's not &ratelimit=false but &ratebypass=true
 
Last edited:
ChaoscripT: script suggested by momoe can help you download video files, but not MP3. YouTube doesn't host any MP3 files. If you want to make a Youtube-to-MP3 website, then your script has to download first the video on your server (maybe using momoe's script), and then convert from flv or mp4 (the format used by youtube for videos) to mp3. it's not that easy as appears to be :)
 
Status
Not open for further replies.
Back
Top