开发者

Youtube download'er in highest possible format (server side)

Welcome,

I'm looking for youtube api what allow me to download youtube video in highest possible format.

Few years ago this job was more simple because url had information about quality like "fmt=22" or "fmt=6" right now we are live in future and that information is embed in player.

Now it's more complex... google use cache servers and get_video doesn't work.

Look for example: http://www.youtube.com/watch?v=XIz-MmKeoCs (it's just example with HD don't comment music)

Right now i'm using old PHPtube class (2007 year). phpclasses.org/browse/package/3966.html It allow only to download file in lowest quality via flv.

My question is, anyone have class what allow download in highest possible ?

I give video ID -> XIz-MmKeoCs It should check what quality is possible for download. Right now i don't have any idea how get it...

And give download link. (of course i know about security used by IP, and want download file on my server usin开发者_如何学运维g file_contents) but i got trouble only with getting that download link.

I will be great for any help...


Use this post as a guideline: youtube get_video not working

Using the $ytarr['fmt_url_map'] from that example, you can explode() it into the various available formats:

$fmt_array = array('5','34','35');    
$fmt_available = explode(',', $ytarr['fmt_stream_map']);
foreach ($fmt_array as $val) {
    foreach ($fmt_available as $fmtstr) {
        if (strpos($fmtstr,"$val|") !== false){
            $format = explode('|', $fmtstr);
            break 2;
        }
    }
}
echo $format['1'];

$fmt_array would hold all the formats you desire in order of priority. In this example, it would first print the direct link to format 5, and if 5 wasn't available it'd print 34, and so forth. You would obviously want to change that array to first list the highest formats.


If you pull a video page, parse it and look for &fmt_url_map= the stuff after here is a map of format id => download link. You have to do a little parsing of it but have a look and it's not that complicated.

The problem is that if you are developing this on your machine, it will work, but if you want to put it live it will not work as the download urls have some sort of signature that only applies for the machine that pulled the video page, which in this case will not match with your local machine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜