Andy's Blog » youtube, youtube get_video_info, www youtube com/get_video_info, youtube 下载 代码, videoplayback YOUTUBE, youtube get video info, get_video_info youtube, div_dl, get_video_info下载, javascript youtube get_video_info, youtube的playback代码, youtube.com get_video_info?video_id » YouTube 下载器核心代码

YouTube 下载器核心代码

YouTube 视频的地址规则是这样的

http://www.youtube.com/watch?v=9pzro0T8rgY

此视频的相关信息地址为

http://www.youtube.com/get_video_info?video_id=9pzro0T8rgY

得到一堆字符串,需要解码,用如下脚本

var fmt_str = new Array();
fmt_str[0]  = ' (FLV, 320 x 240, Mono 22KHz MP3)';
fmt_str[5]  = ' (FLV, 320 x 240, Mono 44KHz MP3)';
fmt_str[6]  = ' (FLV, 480 x 360, Mono 44KHz MP3)';
fmt_str[34] = ' (FLV, 320 x 240, Stereo 44KHz MP3)';
fmt_str[35] = ' (FLV, 640 x 380, Stereo 44KHz MP3)';
fmt_str[13] = ' (3GP, 176 x 144, Stereo 8KHz)';
fmt_str[17] = ' (3GP, 176 x 144, Mono 22KHz)';
fmt_str[18] = ' (MP4, 480 x 360, Stereo 44KHz AAC H.264)';
fmt_str[22] = ' (MP4, 1280 x 720, Stereo 44KHz AAC H.264)';
fmt_str[37] = ' (MP4, 1920 x 1080, Stereo 44KHz AAC H.264)';
        
function getYouTubeUrl(){
 
var rdata = $('#videoInfo').val();
 
var rdataArray = rdata.split('&');
 
var succ = 0;
 
for(i = 0; i < rdataArray.length; i++){
    
r0 = rdataArray[i].substr(0, 11);
    
if(r0 == 'fmt_url_map'){
      
r1 = unescape(rdataArray[i].substr(12));
      
var temp1 = r1.split(',');
      
var fmt = new Array;
      
var fmt_url = new Array;
      
for(j = 0; j < temp1.length; j++){
        
var temp2 = temp1[j].split('|');
        
fmt.push(parseInt(temp2[0], 10));
        
fmt_url.push(temp2[1]);
      
}
      
      
var dllinks = '';
      
for(var k in fmt){
        
if(dllinks.length > 0){
          
dllinks += '<br />';
        
}
        
dllinks += '<a href="' + fmt_url[k] + '"><b>Download' + fmt_str[fmt[k]] + '</b></a>';
      
}
      $
('#result_div').remove();
      
var div_dl = document.createElement('div');
      $
(div_dl).html(dllinks).css('padding', '7 0 7px 0');
      $
(div_dl).attr('id', 'result_div');
      $
('#videoInfo').after(div_dl);
      
succ = 1;
    
}
 
}
 
if(succ == 0){
    
var result;
    
var rdata_status;
    
var rdata_reason;
    
var rdata_temp;
    
for(i = 0; i < rdataArray.length; i++){
      
rdata_temp = rdataArray[i].split('=');
      
if(rdata_temp[0] == 'status'){
        
rdata_status = rdata_temp[1];
      
}
      
if(rdata_temp[0] == 'reason'){
        
rdata_reason = urldecode(rdata_temp[1]);
      
}
    
}
    
result = '<b>&#28961;&#27861;&#21462;&#24471;&#24433;&#29255; URL</b><br />status : <span style="color:#f00;">' + rdata_status + '</span><br />' + 'reason : <span style="color:#f00;">' + rdata_reason + '</span>';
    $
('#result_div').remove();
    
var div_dl = document.createElement('div');
    $
(div_dl).html(result).css('padding', '7 0 7px 0');
    $
(div_dl).attr('id', 'result_div');
    $
('#videoInfo').after(div_dl);
 
}
}
 
function urldecode(str){
    
return decodeURIComponent(str.replace(/\+/g, '%20'));
}

解码后得到的地址
Download (FLV, 320 x 240, Stereo 44KHz MP3)

http://v17.lscache6.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor%2Coc%3AU0dXSVJOU19FSkNNN19KSFdD&algorithm=throttle-factor&itag=34&ipbits=0&burst=40&sver=3&expire=1284235200&key=yt1&signature=4A088FAE2C79856C44CCE8B936337E26B09DFEE6.B6CBF3FFFBFA04374F19AF37A85C22D412D9A824&factor=1.25&id=f69ceba344fcae06

Download (MP4, 480 x 360, Stereo 44KHz AAC H.264)

http://v20.lscache4.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor%2Coc%3AU0dXSVJOU19FSkNNN19KSFdD&algorithm=throttle-factor&itag=18&ipbits=0&burst=40&sver=3&expire=1284235200&key=yt1&signature=1FD50F7004D399EA3BC89AD8CCE8B3B6AF757579.A643EC09F3ADD599FA995A066349B938A7916D96&factor=1.25&id=f69ceba344fcae06

Download (FLV, 320 x 240, Mono 44KHz MP3)

http://v4.lscache4.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor%2Coc%3AU0dXSVJOU19FSkNNN19KSFdD&algorithm=throttle-factor&itag=5&ipbits=0&burst=40&sver=3&expire=1284235200&key=yt1&signature=BB9E2D23A41482A8688F018854A0F441B5289D56.72DFBE0B236D1C7AE817D12E9203BB91C06CC313&factor=1.25&id=f69ceba344fcae06

Incoming search terms:

Tags: Youtube, 解码

本文地址: http://www.21andy.com/new/20100911/1946.html

2 评论 to “PHP开源CMS之MODx”

  1. ikbear 于 2010-09-11 22:55:47 发表:

    这个好强大,收藏了。

  2. 拆墙部队 于 2010-09-12 07:04:44 发表:

    不过你今天怎么中邪了似的更新了这么多篇文章啊。