接上篇,通过firebug--flash项,就可以直接找到视频链接:
http://f.youku.com/player/getFlvPath/sid/136498197014419605553__00/st/flv/fileid/030002010051593E38054E06B0AAF638826A7A-9E31-DD72-E8A8-AE9C22EE340B?K=a5c2375c381bbf9b28287fb3
这个链接就是源地址。这个地址可以直接下载!(链接参数实时生成,可能此时无法下载)。
不难看出,http://f.youku.com/player/getFlvPath/sid/这一段是固定的,通过分析这个URL,我基本可以定为以下:
realUrls = "http://f.youku.com/player/getFlvPath/sid/" + this.getSid() + "_00" + "/st/flv/fileid/" + beginCode + realCode + endCode+ "?K=" + key1;
1、136498197014419605553__00 这是什么呢?不难看出,是时间+一些随机数!通过以下可以获得!
private String getSid(){
String sid = new Date().getTime() + ""
+ (1000 + new Random().nextInt(999)) + ""
+ (new Random().nextInt(9000) + 1000);
return sid;
}
2、030002010051593E38054E06B0AAF638826A7A-9E31-DD72-E8A8-AE9C22EE340B 这是什么?
通过以下可以获取到!
String realCode = this.getFileId(encryptUrl , Integer.parseInt(seed));
String beginCode = realCode.substring(0,8);
String endCode = realCode.substring(10,realCode.length());参数encryptUrl就是<span style="">32*40*32*32*32*44*32*7*32*32*15*55*40*32*7*15*23*28*15*1*12*29*32*15*28*12*32</span>...这一大串!
参数encryptUrl就是 32*40*32*32*32*44*32*7*32*32*15*55*40*32*7*15*23*28*15*1*12*29*32*15*28*12*32...这一大串!获取上一篇说的那个内容!
private String getFileId(String fileId, int seed) {
String mixed = getMixString(seed);
String[] ids = fileId.split("\\*");
String realId = "";
for (int i = 0; i < ids.length; ++i) {
int idx = Integer.parseInt(ids[i]);
realId += mixed.charAt(idx);
}
return realId;
}
private String getMixString(int seed) {
String mixed = "";
String source = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/\\:._-1234567890";
int len = source.length();
for (int i = 0; i < len; ++i) {
seed = (seed * 211 + 30031) % 65536;
int index = (int) (seed / 65536d * source.length());
char c = source.charAt(index);
mixed = mixed + c;
source = source.replace(c + "", "");
}
return mixed;
}
protected String toHex(int t){
String arr [] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};
char _arr[] = {'f', 'e', 'd', 'c', 'b', 'a', '9', '8', '7', '6', '5', '4', '3', '2', '1', '0'};
String ret = new String();
if (t < 0)
{
Arrays.copyOf(_arr, arr.length);
t ^= 0xffffffff;
}
while (t > 0)
{
ret = _arr[(t % 16)] + ret;
t /= 16;
t =(int) Math.floor(t);
}
return ret;
}
private String getKey(String key1, String key2) {
Long hex = Long.parseLong(key1, 16);
hex ^= 0xA55AA5A5;
return key2 + Integer.toHexString(hex.intValue());
}
3、a5c2375c381bbf9b28287fb3 这是什么?
flv中的key呀。优酷的视频分标清、高清、超清。
根据你想要的画质,拿不一样的KEY。flv是标清,mp4是高清 HD2是超清!
上一篇说的那些参数,可以通过jsonOjbect获取,例如:
JSONObject obj = JSONObject.fromObject(urlHtml);
JSONArray array = (JSONArray)obj.get("data");
JSONObject json = (JSONObject)array.get(0);
JSONObject flvJson = (JSONObject)json.get("segs");
JSONArray flvArray = (JSONArray)flvJson.get("flv");