最近在研究百度網盤的視頻解析,目的是找出網盤視頻的真實源地址。百度網盤對於超過1G的文件需要通過網盤客戶端下載,通過抓包研究,可下載源視頻有以下4個渠道:
一、https://pan.baidu.com/s/視頻地址
這是分享后的視頻地址
找到視頻源解析地址:

接口地址:https://pan.baidu.com/share/streaming
請求方式:GET,需帶登錄后的百度網盤COOKIE
參數:channel、uk、path、sign、timestamp、shareid、type
說明:
channel=chunlei (固定寫死)
uk、path、sign、timestamp、shareid在源代碼可以采集到

type為視頻類型和清晰度
視頻解析出來是m3u8格式
注:有時會出現驗證碼,所以做程序自動化解析比較難,而且分享的視頻會被限速,如發現惡意應用也可能會被百度封停分享地址;
二、https://pan.baidu.com/play/video#video/path=視頻地址
這是未分享的視頻地址,通過PC端網盤抓包的接口也一樣

找到視頻源解析地址:
接口地址:https://pan.baidu.com/api/download
請求方式:GET,需帶登錄后的百度網盤COOKIE
請求參數:timestamp、sign、fidlist、type
說明:
timestamp可以在頁面源代碼中采集;

sign需要取得sign3和sign1后(sign3和sign1在頁面源代碼中采集

),通過sign2的加密算法並base64后得到;
下面給出sign的php實現算法:
function s($j,$r)
{ $a = array(); $p = array(); $o = ""; $v = strlen($j); $j = str_split($j,1); for($q=0;$q<256;$q++)
{ $a[$q] = charCodeAt($j[$q%$v]); $p[$q]=$q; }
for($u=$q=0;$q<256;$q++)
{ $u=($u+$p[$q]+$a[$q])%256; $t=$p[$q]; $p[$q]=$p[$u]; $p[$u]=$t; }
for($i=$u=$q=0;$q<strlen($r);$q++)
{ $i=($i+1)%256; $u=($u+$p[$i])%256; $t=$p[$i]; $p[$i]=$p[$u]; $p[$u]=$t; $k=$p[(($p[$i]+$p[$u])%256)]; $r2 = str_split($r,1); $o.=fromCharCode(charCodeAt($r2[$q])^$k); } return base64_encode($o); } function charCodeAt($str)
{ $ret = mb_convert_encoding($str, 'UTF-32BE', 'UTF-8'); return hexdec(bin2hex($ret)); } function fromCharCode($codes)
{ if (is_scalar($codes)) $codes= func_get_args(); $str= ''; foreach ($codes as $code) $str.= chr($code); return $str; }
sign=s($sign3,$sign1);
fidlist值是視頻ID值的集合,例如視頻ID為1157929130,fidlist就是[1157929130],當取多視頻時就是[1157929130,1157929131,1157929132],視頻ID可以通過列表接口獲得:
type值寫死dlink
最后請求返回json結果,其中dlink就是我們要的視頻真實源地址:

百度開發者中心-PCS接口,目前暫停開放;
百度網盤開放平台-目前只支持AndroidSDK