在收藏栏新建一个网址收藏,然后编辑,复制下方代码到网址内,名称随意
javascript:var download = function (text, filename, type) {let b = new Blob([text], {type: type || 'text/plain'}); let a = document.createElement("a"); a.href = URL.createObjectURL(b); a.setAttribute("download", filename); a.click();}; var findPssh = function (base64Str) {var ba = Uint8Array.from(atob(base64Str), c => c.charCodeAt(0)); for(let i = 0, f = false; i < ba.length - 5; i++) {if(ba[i+1] == 0x70 && ba[i+2] == 0x73 && ba[i+3] == 0x73 && ba[i+4] == 0x68) {if(f) {let p_len = ba[i]; let pssh = ba.slice(i-3, i+p_len-3); return btoa(String.fromCharCode.apply(null, pssh)); } f = true; } } }; var importCmd5xAsync = async function() { let jsCode = await fetch("https://static.iqiyi.com/js/common/f6a3054843de4645b34d205a9f377d25.js").then(resp => resp.text()); let script = document.createElement("script"); script.text = jsCode; document.getElementsByTagName("head")[0].appendChild(script); }; var importJsZipAsync = async function() { let jsCode = await fetch("https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.0/jszip.min.js").then(resp => resp.text()); let script = document.createElement("script"); script.text = jsCode; document.getElementsByTagName("head")[0].appendChild(script); }; var formatTime = function(dur) {var date = new Date(0); date.setSeconds(dur); return date.toISOString().substr(11, 8).replace(/:/,"h").replace(/:/,"m")+"s"; }; var fetchFlvAsync = async function(info) {var fs = info.fs; var content = "#EXTM3U\n"; var prefix = "https://data.video.iqiyi.com/videos"; let results = fs.map(async fs_i => { let url = fs_i.l; let api = prefix + url; let t = ""; if(playerObject._player.package.engine.adproxy.engine.movieinfo.current.boss){t = playerObject._player.package.engine.adproxy.engine.movieinfo.current.boss.data.t;} api = prefix + url +"✗domain=1&t="+ t +"&QY00001="+ /qd_uid=(\d+)/g.exec(url)[1] +"&ib=4&ptime=0&ibt="+ cmd5x(t + /\/(\w{10,})/g.exec(url)[1]); let resp = await fetch(api,{credentials:'same-origin'}); let json = await resp.json(); return"#EXTINF:"+(fs_i.d/1000).toFixed(2)+"\n"+ json["l"]; }); let urls = await Promise.all(results); content += urls.join('\n'); content +="\n#EXT-X-ENDLIST"; return content; }; var ndIqyAsync = async function() { var vTracks = playerObject._player.package.engine.adproxy.engine.movieinfo.current.vidl.filter(a=>a.isUsable && a.realArea.width).sort((a,b)=>b.vsize-a.vsize); let info = vTracks[0]; if(vTracks.length > 1) {let p =""; vTracks.forEach(function (item, index) {p += %60\r\n[${index}]: [${item.realArea.width}x${item.realArea.height}]_${(item.vsize / 1024 / 1024).toFixed(2)}MB%60; }); let _input = prompt("请选择视频" + p); info = vTracks[Number(_input)]; } var title = ""; try{title = document.querySelector('h1.player-title a.title-link[title]')['title'] +"_"+ document.querySelector('h1.player-title em').innerText +"_"+ info.realArea.width +"_"+ info.realArea.height +"_"+ formatTime(info.duration) +"_"+ (info.vsize / 1024 / 1024).toFixed(2) +"MB"; } catch(err){title = document.title +"_"+ info.realArea.width +"_"+ info.realArea.height +"_"+ formatTime(info.duration) +"_"+ (info.vsize / 1024 / 1024).toFixed(2) +"MB"; } var m3u8Content =""; if(typeof info.playlist == "string" && info.playlist.length>0){m3u8Content = info.playlist;}else if(typeof info.playlist == "object" && !info.playlist.drm){m3u8Content = "#EXTM3U\n" + info.playlist.urls.map((u,i)=>"#EXTINF:"+info.playlist.durations[i]+",\nhttps:"+u+info.playlist.qdp[/\/(\w{10,})/g.exec(u)[1]]).join('\n') + "\n#EXT-X-ENDLIST"; }else if(typeof info.playlist == "object" && info.playlist.drm){let keyServer = info.playlist.drm.keySystemServer; let aTrack1 = info.playlist.m3u8.audio_track1; let vTrack1 = info.playlist.m3u8.video_track1; /* 生成 audio m3u8 */ let aM3u8 = "#EXTM3U\n"; aM3u8 += %60#EXT-X-MAP:URI=\"init.m4a\"\n%60; aM3u8 += "#EXT-X-KEY:METHOD=PLZ-KEEP-RAW,URI=\"None\"\n"; let aUrl = aTrack1.files[0].file_name; for (let i = 0; i < aTrack1.files[0].seekable.time.length-1; i++) {let _start = aTrack1.files[0].seekable.pos[i]; let _end = aTrack1.files[0].seekable.pos[i+1]; let _dur = aTrack1.files[0].seekable.time[i+1]-aTrack1.files[0].seekable.time[i]; aM3u8 += %60#EXTINF:${_dur.toFixed(2)},\n%60; aM3u8 += %60${aUrl}&start=${_start}&end=${_end}\n%60; } aM3u8 += "\n#EXT-X-ENDLIST"; /* 生成 video m3u8 */ let vM3u8 = "#EXTM3U\n"; vM3u8 += %60#EXT-X-MAP:URI=\"init.mp4\"\n%60; vM3u8 += "#EXT-X-KEY:METHOD=PLZ-KEEP-RAW,URI=\"None\"\n"; vM3u8 += vTrack1.files.map((u)=>%60#EXTINF:${u.duration_second.toFixed(2)},\n${u.file_name}&start=${u.seekable.pos_start}&end=${u.seekable.pos_end}%60).join('\n'); vM3u8 += "\n#EXT-X-ENDLIST"; /* 引入 JSZip */ await importJsZipAsync(); /* zip 打包 */ var zip = new JSZip(); /* 塞入文件 */ zip.file("init.m4a",aTrack1.codec_init, {base64: true}); zip.file("init.mp4",vTrack1.codec_init, {base64: true}); zip.file("m4a.m3u8",aM3u8); zip.file("mp4.m3u8",vM3u8); zip.file("license_url.txt",keyServer); zip.file("pssh.txt",findPssh(vTrack1.codec_init)); zip.generateAsync({type:"blob"}).then(function(content) {download(content, title + ".zip", "application/octet-stream"); }); }else{await importCmd5xAsync(); m3u8Content = await fetchFlvAsync(info); } if(m3u8Content!="") download(m3u8Content, title +".m3u8"); }; ndIqyAsync();
使用方法:
- 在爱奇艺网页版找到你想下载的视频,打开播放页面,然后点击刚刚新建的网址收藏标签,会有一个弹窗(如下图)
- 在弹窗中输入你要下载视频的分辨率,点击确定即可下载一个 .m3u8 文件
- 配合工具 N_m3u8DL-CLI: 点击下载
- 打开 N_m3u8DL-CLI-SimpleG.exe,刚刚在爱奇艺下载的.m3u8 文件拖入 M3U8 地址,然后选择好存储路径,点击GO 即可开始下载啦
微信扫描下方的二维码阅读本文