parent
575b435fe1
commit
da6af25b9a
@ -1,353 +0,0 @@ |
||||
function createsession(headers,deviceId,userId){ |
||||
function getNowTime() { |
||||
const yy = new Date().getFullYear() |
||||
const MM = (new Date().getMonth() + 1) < 10 ? '0' + (new Date().getMonth() + 1) : (new Date().getMonth() + 1) |
||||
const dd = new Date().getDate() < 10 ? '0' + new Date().getDate() : new Date().getDate() |
||||
const HH = new Date().getHours() < 10 ? '0' + new Date().getHours() : new Date().getHours() |
||||
const mm = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes() |
||||
return yy + '' + dd + '' + HH + '' + MM + '' + mm |
||||
} |
||||
|
||||
for(let i=1; i<5; i++){ |
||||
let signature; |
||||
let public_key; |
||||
if(i == 3){ |
||||
try{ |
||||
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; |
||||
} |
||||
log("调用py服务器生成算法"); |
||||
}catch(e){ |
||||
log("调用py服务器失败"); |
||||
} |
||||
}else{ |
||||
let a = justTestSign('5dde4e1bdf9e4966b387ba58f4b3fdc3',deviceId,userId); |
||||
signature = a.split('##')[0]; |
||||
public_key = a.split('##')[1]; |
||||
} |
||||
headers['x-signature'] = signature; |
||||
let data = { |
||||
"deviceName": "Edge浏览器", |
||||
"modelName": "Windows网页版", |
||||
"pubKey": public_key, |
||||
} |
||||
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) { |
||||
return {"signature":signature, "success":1} |
||||
} |
||||
} |
||||
} |
||||
return {"success":0} |
||||
} |
||||
|
||||
function aliSharePlayUrl(share_id,file_id,share_pwd){ |
||||
try{ |
||||
share_pwd = share_pwd&&share_pwd.length==4?share_pwd:""; |
||||
let sharetoken = getsharetoken(share_id,share_pwd).share_token; |
||||
let authorization = 'Bearer ' + userinfo.access_token; |
||||
let deviceId = userinfo.device_id; |
||||
let userId = userinfo.user_id; |
||||
headers['authorization'] = authorization; |
||||
headers['x-device-id'] = deviceId; |
||||
let aliecc = createsession(headers,deviceId,userId); |
||||
let aliyunUrl = []; |
||||
if(aliecc.success){ |
||||
headers['x-signature'] = aliecc.signature; |
||||
headers['x-share-token'] = sharetoken; |
||||
headers['fileid'] = userId; |
||||
let data = data = {"category": "live_transcoding", "file_id": file_id, "get_preview_url": true, "share_id": share_id, "template_id": "", "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 })); |
||||
aliyunUrl = json.video_preview_play_info.live_transcoding_task_list; |
||||
aliyunUrl.reverse(); |
||||
} |
||||
return aliyunUrl; |
||||
}catch(e){ |
||||
log('根据共享链接获取播放地址失败,挂载的阿里分享应有密码>'+e.message); |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
function getAliUrl(share_id, file_id, share_pwd) { |
||||
try { |
||||
let urls = []; |
||||
let names = []; |
||||
let heads = []; |
||||
let u = startProxyServer($.toString((share_id,file_id,share_pwd,config) => { |
||||
function geturl(fileid,line){ |
||||
require(config.依赖.match(/http(s)?:\/\/.*\//)[0].replace('/Ju/','/master/') + 'SrcJyAliPublic.js'); |
||||
let playUrlList = aliSharePlayUrl(share_id,fileid,share_pwd) || []; |
||||
let aliurl; |
||||
playUrlList.forEach((item) => { |
||||
if(item.template_id == line){ |
||||
aliurl = item.url; |
||||
//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; |
||||
} |
||||
},share_id,file_id,share_pwd,config)); |
||||
if(getItem('aliyun_playMode', '智能')=="智能" || getItem('aliyun_playMode')=="原画"){ |
||||
let sharetoken = getsharetoken(share_id,share_pwd).share_token; |
||||
let openUrl = aliOpenPlayUrl(file_id,{sharetoken:sharetoken,share_id:share_id}); |
||||
if(openUrl){ |
||||
urls.push(openUrl + "#isVideo=true##pre#"); |
||||
names.push("原始 画质"); |
||||
heads.push({ 'Referer': 'https://www.aliyundrive.com/' }); |
||||
}else{ |
||||
log('获取开放接口原画播放地址失败'); |
||||
} |
||||
} |
||||
if((getItem('aliyun_playMode', '智能')=="智能" && urls.length==0) || getItem('aliyun_playMode')=="转码"){ |
||||
let playUrlList = aliSharePlayUrl(share_id,file_id,share_pwd) || []; |
||||
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/' }); |
||||
}) |
||||
}else{ |
||||
log('未获取阿里播放地址,建议重进软件再试一次') |
||||
} |
||||
} |
||||
return { |
||||
urls: urls, |
||||
names: names, |
||||
headers: heads |
||||
}; |
||||
} catch (e) { |
||||
log('获取共享链接播放地址失败>' + e.message); |
||||
return {}; |
||||
} |
||||
} |
||||
function getSubtitle(share_id,sub_file_id,share_pwd){ |
||||
try{ |
||||
share_pwd = share_pwd&&share_pwd.length==4?share_pwd:""; |
||||
let sharetoken = getsharetoken(share_id,share_pwd).share_token; |
||||
headers["authorization"] = userinfo.access_token; |
||||
headers["x-share-token"] = sharetoken; |
||||
let data = {"expire_sec":600,"file_id":sub_file_id,"share_id":share_id}; |
||||
let downurl = JSON.parse(request("https://api.aliyundrive.com/v2/file/get_share_link_download_url", { headers: headers, body: data, timeout: 3000 })).download_url; |
||||
let subfile = 'hiker://files/_cache/subtitles/'+sub_file_id+'.srt'; |
||||
downloadFile(downurl, subfile, {"referer": "https://www.aliyundrive.com/"}) |
||||
if(fetch(subfile)){ |
||||
return getPath(subfile); |
||||
}else{ |
||||
return ""; |
||||
} |
||||
}catch(e){ |
||||
log('获取字幕失败>'+e.message); |
||||
} |
||||
return ""; |
||||
} |
||||
|
||||
function aliMyPlayUrl(file_id) { |
||||
try { |
||||
let authorization = 'Bearer ' + userinfo.access_token; |
||||
let deviceId = userinfo.device_id; |
||||
let userId = userinfo.user_id; |
||||
let drive_id = getMyVar("selectDisk","1")=="1"?userinfo.default_drive_id:userinfo2.resource_drive_id; |
||||
headers['authorization'] = authorization; |
||||
headers['x-device-id'] = deviceId; |
||||
let aliecc = createsession(headers,deviceId,userId); |
||||
let aliyunUrl = []; |
||||
if(aliecc.success){ |
||||
headers['x-signature'] = aliecc.signature; |
||||
let data = { "drive_id": drive_id, "file_id": file_id, "category": "live_transcoding", "template_id": "", "get_subtitle_info": true } |
||||
let json = JSON.parse(request('https://api.aliyundrive.com/v2/file/get_video_preview_play_info', { headers: headers, body: data, method: 'POST', timeout: 3000 })); |
||||
aliyunUrl = json.video_preview_play_info.live_transcoding_task_list; |
||||
aliyunUrl.reverse(); |
||||
} |
||||
let urls = []; |
||||
let names = []; |
||||
let heads = []; |
||||
if (aliyunUrl.length > 0) { |
||||
aliyunUrl.forEach((item) => { |
||||
urls.push(item.url + "#isVideo=true##pre#"); |
||||
names.push(transcoding[item.template_id] ? transcoding[item.template_id] : item.template_height); |
||||
heads.push({ 'Referer': 'https://www.aliyundrive.com/' }); |
||||
}) |
||||
} else { |
||||
log('未获取阿里转码播放地址,建议重进软件再试一次') |
||||
} |
||||
let file_url = aliOpenPlayUrl(file_id); |
||||
if(file_url){ |
||||
urls.unshift(file_url+ "#isVideo=true##pre#"); |
||||
names.unshift("原始 画质"); |
||||
heads.unshift({'Referer':'https://www.aliyundrive.com/'}); |
||||
}else{ |
||||
clearMyVar('aliopeninfo'); |
||||
} |
||||
return { |
||||
urls: urls, |
||||
names: names, |
||||
headers: heads |
||||
}; |
||||
} catch (e) { |
||||
log('获取我的云盘播放地址失败>' + e.message); |
||||
return { message: '获取我的云盘播放地址失败>' + e.message }; |
||||
} |
||||
} |
||||
|
||||
function aliOpenPlayUrl(file_id,sharedata) { |
||||
try { |
||||
function fcopy(obj) { |
||||
try { |
||||
let json = JSON.parse(fetch('https://api.aliyundrive.com/adrive/v2/batch', { |
||||
headers: { |
||||
'User-Agent': PC_UA, |
||||
'Referer': 'https://www.aliyundrive.com/', |
||||
'authorization': obj.authorization, |
||||
'x-canary': 'client=web,app=share,version=v2.3.1', |
||||
'x-share-token': obj.sharetoken |
||||
}, |
||||
body: { |
||||
"requests": [{ |
||||
"body": { |
||||
"file_id": obj.file_id, |
||||
"share_id": obj.share_id, |
||||
"auto_rename": true, |
||||
"to_parent_file_id": "root", |
||||
"to_drive_id": obj.drive_id |
||||
}, |
||||
"headers": {"Content-Type": "application/json"},"id": "0","method": "POST","url": "/file/copy" |
||||
}], |
||||
"resource": "file" |
||||
}, |
||||
method: 'POST' |
||||
})).responses[0].body; |
||||
if(/size/.test(json.message)){ |
||||
log('云盘没有空间,无法操作转存'); |
||||
} |
||||
return json.file_id; |
||||
} catch (e) { |
||||
return ""; |
||||
} |
||||
}; |
||||
function fdel(obj) { |
||||
fetch('https://api.aliyundrive.com/adrive/v2/batch', { |
||||
headers: { |
||||
'User-Agent': PC_UA, |
||||
'Referer': 'https://www.aliyundrive.com/', |
||||
'authorization': obj.authorization, |
||||
'x-canary': 'client=web,app=share,version=v2.3.1', |
||||
'x-share-token': obj.sharetoken |
||||
}, |
||||
body: { |
||||
"requests": [{ |
||||
"body": { |
||||
"drive_id": obj.drive_id, |
||||
"file_id": obj.file_id |
||||
}, |
||||
"headers": {"Content-Type": "application/json"}, |
||||
"id": obj.file_id, |
||||
"method": "POST", |
||||
"url": "/file/delete" |
||||
}], |
||||
"resource": "file" |
||||
}, |
||||
method: 'POST' |
||||
}); |
||||
} |
||||
let authorization = 'Bearer ' + userinfo.access_token; |
||||
let drive_id = getMyVar("selectDisk","1")=="1"?userinfo.default_drive_id:userinfo2.resource_drive_id; |
||||
let newfile_id; |
||||
if(sharedata){ |
||||
sharedata.file_id = file_id; |
||||
sharedata.drive_id = drive_id; |
||||
sharedata.authorization = authorization; |
||||
newfile_id = fcopy(sharedata); |
||||
if(!newfile_id){ |
||||
return ""; |
||||
} |
||||
} |
||||
let url = ''; |
||||
try{ |
||||
let opentoken; |
||||
let nowtime = Date.now(); |
||||
let oldtime = parseInt(getMyVar('opentokenChecktime', '0').replace('time', '')); |
||||
let aliopentoken = getMyVar('aliopentoken'); |
||||
if (aliopentoken && nowtime < (oldtime + 1 * 60 * 60 * 1000)) { |
||||
opentoken = aliopentoken; |
||||
} else { |
||||
opentoken = getOpenToken(authorization); |
||||
putMyVar('aliopeninfo', opentoken); |
||||
putMyVar('opentokenChecktime', nowtime + 'time'); |
||||
} |
||||
headers['authorization'] = 'Bearer ' + opentoken; |
||||
let data3 = {"drive_id":drive_id,"file_id":newfile_id||file_id} |
||||
let json3 = JSON.parse(request('https://open.aliyundrive.com/adrive/v1.0/openFile/getDownloadUrl', { headers: headers, body: data3, method: 'POST', timeout: 8000})); |
||||
url = json3.url; |
||||
}catch(e){ |
||||
log('获取原画播放地址失败>' + e.message); |
||||
} |
||||
if (newfile_id) { |
||||
sharedata.file_id = newfile_id; |
||||
fdel(sharedata); |
||||
} |
||||
return url; |
||||
} catch (e) { |
||||
log('获取我的云盘原画出现异常>' + e.message); |
||||
} |
||||
return ""; |
||||
} |
Loading…
Reference in new issue