|
|
|
@ -1,5 +1,104 @@ |
|
|
|
|
function getAliUrl(share_id, file_id, alitoken) { |
|
|
|
|
try { |
|
|
|
|
let urls = []; |
|
|
|
|
let names = []; |
|
|
|
|
let heads = []; |
|
|
|
|
let u = startProxyServer($.toString((aliSharePlayUrl,file_id,share_id,alitoken) => { |
|
|
|
|
function geturl(fileid,line){ |
|
|
|
|
//预加载时会变file_id,所以ts过期更新时还取原来的id
|
|
|
|
|
let playUrlList = aliSharePlayUrl(share_id, fileid, alitoken) || []; |
|
|
|
|
let aliurl; |
|
|
|
|
playUrlList.forEach((item) => { |
|
|
|
|
if(item.template_id == line){ |
|
|
|
|
aliurl = JSON.parse(request(item.url, { headers: { 'Referer': 'https://www.aliyundrive.com/' }, onlyHeaders: true, redirect: false, timeout: 3000 })).headers.location[0]; |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
//上面是获取阿里的播放地址
|
|
|
|
|
//log("我在代理" + aliurl);
|
|
|
|
|
let home = aliurl.split('media.m3u8')[0]; |
|
|
|
|
let f = fetch(aliurl, { headers: { 'Referer': 'https://www.aliyundrive.com/' }, timeout: 3000}).split("\n"); |
|
|
|
|
let ff = f.map(it => { |
|
|
|
|
if (it.startsWith("media-")) { |
|
|
|
|
return "/proxy?url=" + base64Encode(home+it); |
|
|
|
|
} |
|
|
|
|
return it; |
|
|
|
|
}).join("\n"); |
|
|
|
|
//log('ufid-'+fileid);
|
|
|
|
|
writeFile('hiker://files/cache/_fileSelect_'+fileid+'.m3u8',ff); |
|
|
|
|
return ff; |
|
|
|
|
} |
|
|
|
|
let url = base64Decode(MY_PARAMS.url); |
|
|
|
|
if(url.includes(".ts")){ |
|
|
|
|
let fid = url.split('&f=')[1].split('&')[0]; |
|
|
|
|
//log('sfid-'+fid);
|
|
|
|
|
let f = fetch('hiker://files/cache/_fileSelect_'+fid+'.m3u8').split("\n"); |
|
|
|
|
f.forEach(it => { |
|
|
|
|
if(it&&it.startsWith('/proxy?url=')){ |
|
|
|
|
let furl = base64Decode(it.replace('/proxy?url=','')); |
|
|
|
|
if(url.substr(url.indexOf('/media-'),url.indexOf('.ts')) == furl.substr(furl.indexOf('/media-'),furl.indexOf('.ts'))){ |
|
|
|
|
url = furl; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
let expires = url.split('x-oss-expires=')[1].split('&')[0]; |
|
|
|
|
const lasttime = parseInt(expires) - Date.now() / 1000; |
|
|
|
|
if(lasttime < 40){ |
|
|
|
|
//log('过期更新')
|
|
|
|
|
let line = url.split('/media')[0];//取之前播放的ts段线路
|
|
|
|
|
line = line.substring(line.lastIndexOf('/')+1); |
|
|
|
|
let f = geturl(fid,line).split("\n"); |
|
|
|
|
f.forEach(it => { |
|
|
|
|
if(it&&it.startsWith('/proxy?url=')){ |
|
|
|
|
let furl = base64Decode(it.replace('/proxy?url=','')); |
|
|
|
|
if(url.substr(url.indexOf('/media-'),url.indexOf('.ts')) == furl.substr(furl.indexOf('/media-'),furl.indexOf('.ts'))){ |
|
|
|
|
url = furl; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
//log('未过期')
|
|
|
|
|
//log("代理ts:" + url);
|
|
|
|
|
} |
|
|
|
|
return JSON.stringify({ |
|
|
|
|
statusCode: 302, |
|
|
|
|
headers: { |
|
|
|
|
"Location": url, |
|
|
|
|
'Referer': 'https://www.aliyundrive.com/' |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}else{ |
|
|
|
|
//log('首次更新')
|
|
|
|
|
let line = url.split('|')[1]; |
|
|
|
|
let ff = geturl(file_id,line); |
|
|
|
|
return ff; |
|
|
|
|
} |
|
|
|
|
},aliSharePlayUrl,file_id,share_id,alitoken)); |
|
|
|
|
|
|
|
|
|
let playUrlList = aliSharePlayUrl(share_id, file_id, alitoken) || []; |
|
|
|
|
if(playUrlList.length>0){ |
|
|
|
|
playUrlList.forEach((item) => { |
|
|
|
|
urls.push(u + "?url=" + base64Encode(item.url+"|"+item.template_id) + "#.m3u8#pre#"); |
|
|
|
|
names.push(transcoding[item.template_id] ? transcoding[item.template_id] : item.template_height); |
|
|
|
|
heads.push({ 'Referer': 'https://www.aliyundrive.com/' }); |
|
|
|
|
}) |
|
|
|
|
return { |
|
|
|
|
urls: urls, |
|
|
|
|
names: names, |
|
|
|
|
headers: heads |
|
|
|
|
}; |
|
|
|
|
}else{ |
|
|
|
|
log('未获取阿里播放地址,建议重进软件再试一次') |
|
|
|
|
return {}; |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
log('获取共享链接播放地址失败>' + e.message); |
|
|
|
|
return {}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function aliSharePlayUrl(share_id, file_id, alitoken){ |
|
|
|
|
try{ |
|
|
|
|
function getNowTime() { |
|
|
|
|
const yy = new Date().getFullYear() |
|
|
|
|
const MM = (new Date().getMonth() + 1) < 10 ? '0' + (new Date().getMonth() + 1) : (new Date().getMonth() + 1) |
|
|
|
@ -17,31 +116,32 @@ function getAliUrl(share_id, file_id, alitoken) { |
|
|
|
|
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.41", |
|
|
|
|
"x-canary": "client=web,app=adrive,version=v3.1.0" |
|
|
|
|
}; |
|
|
|
|
let nowtime = Date.now(); |
|
|
|
|
let oldtime = parseInt(getMyVar('userinfoChecktime','0').replace('time','')); |
|
|
|
|
let userinfo; |
|
|
|
|
let aliuserinfo = storage0.getMyVar('aliuserinfo'); |
|
|
|
|
if (aliuserinfo && aliuserinfo.user_id) { |
|
|
|
|
if (aliuserinfo && aliuserinfo.user_id && nowtime < (oldtime+1*60*60*1000)) { |
|
|
|
|
userinfo = aliuserinfo; |
|
|
|
|
} else { |
|
|
|
|
userinfo = JSON.parse(request('https://auth.aliyundrive.com/v2/account/token', { headers: headers, body: { "refresh_token": alitoken, "grant_type": "refresh_token" }, method: 'POST', timeout: 3000 })); |
|
|
|
|
storage0.putMyVar('aliuserinfo', userinfo); |
|
|
|
|
putMyVar('userinfoChecktime', nowtime+'time'); |
|
|
|
|
} |
|
|
|
|
let authorization = 'Bearer ' + userinfo.access_token; |
|
|
|
|
let deviceId = userinfo.device_id; |
|
|
|
|
let userId = userinfo.user_id; |
|
|
|
|
let signature; |
|
|
|
|
let public_key; |
|
|
|
|
if(typeof(justTestSign)!="undefined"){ |
|
|
|
|
let getaliecc = justTestSign('5dde4e1bdf9e4966b387ba58f4b3fdc3',deviceId,userId); |
|
|
|
|
signature = getaliecc.split('##')[0]; |
|
|
|
|
public_key = getaliecc.split('##')[1]; |
|
|
|
|
}else{ |
|
|
|
|
let getaliecc = JSON.parse(request('http://124.221.241.174:87/api', { body: 'did=' + deviceId + '&uid=' + userId + '&token=' + md5(getNowTime()), method: 'POST', timeout: 3000 })); |
|
|
|
|
if (getaliecc.code == 200) { |
|
|
|
|
signature = getaliecc.sign; |
|
|
|
|
public_key = getaliecc.key; |
|
|
|
|
} |
|
|
|
|
let getaliecc = JSON.parse(request('http://124.221.241.174:87/api', { body: 'did=' + deviceId + '&uid=' + userId + '&token=' + md5(getNowTime()), method: 'POST', timeout: 3000 })); |
|
|
|
|
if (getaliecc.code == 200) { |
|
|
|
|
signature = getaliecc.sign; |
|
|
|
|
public_key = getaliecc.key; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
let a = justTestSign('5dde4e1bdf9e4966b387ba58f4b3fdc3',deviceId,userId); |
|
|
|
|
signature = a.split('##')[0]; |
|
|
|
|
public_key = a.split('##')[1]; |
|
|
|
|
*/ |
|
|
|
|
headers['authorization'] = authorization; |
|
|
|
|
headers['x-device-id'] = deviceId; |
|
|
|
|
headers['x-signature'] = signature; |
|
|
|
@ -50,11 +150,12 @@ function getAliUrl(share_id, file_id, alitoken) { |
|
|
|
|
"modelName": "Windows网页版", |
|
|
|
|
"pubKey": public_key, |
|
|
|
|
} |
|
|
|
|
let aliyunUrl = []; |
|
|
|
|
if (signature && public_key) { |
|
|
|
|
let req = JSON.parse(request("https://api.aliyundrive.com/users/v1/users/device/create_session", { headers: headers, body: data, timeout: 3000 })); |
|
|
|
|
if (req.success) { |
|
|
|
|
headers['x-share-token'] = sharetoken; |
|
|
|
|
headers['fileid'] = userinfo.user_id; |
|
|
|
|
headers['fileid'] = userId; |
|
|
|
|
data = { |
|
|
|
|
"category": "live_transcoding", |
|
|
|
|
"file_id": file_id, |
|
|
|
@ -64,26 +165,13 @@ function getAliUrl(share_id, file_id, alitoken) { |
|
|
|
|
"get_subtitle_info": true |
|
|
|
|
} |
|
|
|
|
let json = JSON.parse(request('https://api.aliyundrive.com/v2/file/get_share_link_video_preview_play_info', { headers: headers, body: data, method: 'POST', timeout: 3000 })); |
|
|
|
|
let playurl = json.video_preview_play_info.live_transcoding_task_list; |
|
|
|
|
playurl.reverse(); |
|
|
|
|
let urls = []; |
|
|
|
|
let names = []; |
|
|
|
|
let heads = []; |
|
|
|
|
playurl.forEach(item => { |
|
|
|
|
let rurl = JSON.parse(request(item.url, { headers: { 'Referer': 'https://www.aliyundrive.com/' }, onlyHeaders: true, redirect: false, timeout: 3000 })).headers.location[0]; |
|
|
|
|
urls.push(rurl + "#isVideo=true##pre#"); |
|
|
|
|
names.push(transcoding[item.template_id] ? transcoding[item.template_id] : item.template_height); |
|
|
|
|
heads.push({ 'Referer': 'https://www.aliyundrive.com/' }); |
|
|
|
|
}) |
|
|
|
|
return { |
|
|
|
|
urls: urls, |
|
|
|
|
names: names, |
|
|
|
|
headers: heads |
|
|
|
|
}; |
|
|
|
|
aliyunUrl = json.video_preview_play_info.live_transcoding_task_list; |
|
|
|
|
aliyunUrl.reverse(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
log('获取共享链接播放地址失败>' + e.message); |
|
|
|
|
return {}; |
|
|
|
|
return aliyunUrl; |
|
|
|
|
}catch(e){ |
|
|
|
|
log('根据共享链接获取播放地址失败>'+e.message); |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
} |