• 1219 阅读
  • 1 回复

巧妙的获取优酷网视频的真实地址

视频在线上传+队列转换FLV+水印+捉图+修复+获时+转3GP(API语言不限,开视频站必备!)
简单的东西,文件很小滴说。本来是用file_get_contents()的,不过居然防盗链。汗一个~!

代码 复制 - 运行

<form action=""> 

<input type="text" name="url" id="url" size="100"><input type="submit" value="Submit"> 

</form> 

<?PHP 

//==================================================== 

//                FileName:        youku.php 

//                Summary:        获取优酷视频的真实地址 

//                Author:                millken(迷路林肯) 

//                LastModifed:2007-07-24 

//                copyright (c)2007 millken@gmail.com 

//==================================================== 

$url = empty($_GET['url'])?die():$_GET['url']; 

$opts = array( 

  'http'=>array( 

    'method'=>"GET", 

    'header'=>"Accept: */*\r\n" .  

              "Referer: http://www.youku.com/\r\n" 

  ) 

); 

$context = stream_context_create($opts); 

/* Sends an http request to $url with additional headers shown above */ 

$fp = fopen($url, 'rb', false, $context); 

$fpcontent = ""; 

while(!feof($fp)){$fpcontent .= fread($fp,4096);} 

fclose($fp); 

preg_match("/[A-Z0-9]{38}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12}/",$fpcontent,$fileid); 

//0100643AA2452A84A6E50A0003F696993AD6AF-C0C1-37E4-7D85-5C49409E9684 

$surl = "http://www.youku.com/player/getFlvPath/fileid/".$fileid[0]; 

echo "<a href=".file_get_contents($surl).">download this video</a>"; 

?> 



GET /player/getPlayList/VideoIDS/XMzAxMDA4OA==/version/5/source/out?onData=%5Btype%20Function%5D&n=3&%5Fparent=%5Flevel0%2Econtrol%5Fmc HTTP/1.1
Accept: */*
Referer: http://static.youku.com/v1.0.009 ... 22946d23867d51c59ae
x-flash-version: 9,0,28,0
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
Host: www.youku.com
Connection: Keep-Alive
Cookie: PHPSESSID=r63jed7i3lttocgtomucc91ht1; _=____ea0b18035c16c039a0647cd088832c1

http://www.youku.com/player/getP ... vel0%2Econtrol%5Fmc
本帖最后由 张小鱼 于 2011-06-05 19:32 编辑
小鱼的淘宝店铺-多多支持哇
视频在线上传+队列转换FLV+水印+捉图+修复+获时+转3GP(API语言不限,开视频站必备!)

代码 复制 - 运行

Imports System.Net   
Imports System.IO   
Imports System.Text   
Imports System.Text.RegularExpressions   
Public Class frmMain   
Structure VList   
Dim id As Integer   
Dim title As String   
Dim vid1 As String   
Dim vid2 As String   
Overloads Function ToString() As String   
Return String.Format("{0}:<{1}> [{2}]", id, title, vid1)   
End Function   
End Structure   
Dim myList As New List(Of VList)   
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click   
' 防止重复创建变量   
Dim wr1 As HttpWebRequest   
Dim wr2 As HttpWebResponse   
Dim ret As String   
Dim reg As Match   
Dim g As Group   
Dim preVid As String = "" '上一个VID   
Dim nowid As Integer = 0 '当前的视频集数   
Dim listUrl As String = TextBox1.Text '获取专辑URL,如 http://www.youku.com/playlist_show/id_2350764.html   
Dim tarUrl As String = "http://v.youku.com/v_playlist/f{0}" '{0}ListID   
reg = Regex.Match(listUrl, "playlist_show/id_(d+).*.html")   
If Not reg.Success Then   
MsgBox("专辑列表提取失败!")   
Exit Sub   
End If   
g = reg.Groups(1)   
tarUrl = String.Format(tarUrl, g.Value) & "o{1}p{0}.html" '{0}集数 {1}排序   
wr1 = HttpWebRequest.Create(TextBox1.Text)   
wr2 = wr1.GetResponse   
ret = New StreamReader(wr2.GetResponseStream, Encoding.GetEncoding(wr2.CharacterSet)).ReadToEnd   
reg = Regex.Match(ret, "")   
If Not reg.Success Then   
MsgBox("专辑名称提取失败!")   
Else   
g = reg.Groups(1)   
MsgBox("专辑名:《" & g.Value & "》")   
End If   
Do   
' 从Web流中获取页面文本   
wr1 = HttpWebRequest.Create(String.Format(tarUrl, nowid, "0")) '按倒序方式查找视频   
wr2 = wr1.GetResponse   
ret = New StreamReader(wr2.GetResponseStream, Encoding.GetEncoding(wr2.CharacterSet)).ReadToEnd   
'TextBox2.Text = ret   
' 创建一个临时视频列表变量   
Dim nlist As New VList   
nlist.id = nowid '获取ID   
' 获取videoId   
reg = Regex.Match(ret, "vars+videoIds*=s*""(d+)""s*;")   
If Not reg.Success Then Exit Do   
g = reg.Groups(1)   
' 如果VID等于上一个VID最退出   
If g.Value = preVid Then Exit Do   
nlist.vid1 = g.Value   
' 获取videoId2   
reg = Regex.Match(ret, "vars+videoId2s*=s*""((w|=)+)""s*;") '"vars+videoId2s*=s*""(w+)""s*;")   
If Not reg.Success Then Exit Do   
g = reg.Groups(1)   
nlist.vid2 = g.Value   
' 获取标题   
reg = Regex.Match(ret, "")   
If Not reg.Success Then   
nlist.title = "{名称查找错误}"   
Else   
g = reg.Groups(2)   
nlist.title = g.Value   
End If   
' 收尾工作   
myList.Add(nlist) '添加到总列表中   
preVid = nlist.vid1 '记录最后一个VID   
wr2.Close()   
Me.Text = nowid & " : 处理完成!"   
nowid += 1   
Loop   
wr2.Close()   
MsgBox(nowid & " 个视频全部采集处理完成!")   
Button2_Click(sender, e)   
End Sub   
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click   
ListBox1.Items.Clear()   
For Each ls As VList In myList   
ListBox1.Items.Add(String.Format("{0}:<{1}> [{2}]", ls.id, ls.title, ls.vid1))   
Next   
myList.Clear()   
End Sub   

End Class   


小鱼的淘宝店铺-多多支持哇