Bilibili-Evolved/min/download-video-package.min.js
2019-11-07 22:00:20 +08:00

1 line
1.8 KiB
JavaScript

(()=>{return(t,e)=>{class i{constructor(t={}){this.config=t;this.entries=[];if(this.config.titleList===undefined){this.config.titleList=[]}}download(t,e){const n=document.createElement("a");const s=URL.createObjectURL(e);if(i.lastPackageUrl){URL.revokeObjectURL(i.lastPackageUrl)}i.lastPackageUrl=s;n.setAttribute("href",s);n.setAttribute("download",t);document.body.appendChild(n);n.click();n.remove()}add(t,e){if(e===null||e===undefined){return}this.entries.push({name:t,data:e})}async preEmit(){const t=this.entries.filter(t=>[".flv",".mp4"].some(e=>t.name.endsWith(e)));console.log(t,this.config);if(this.config.ffmpeg!==undefined&&t.length>=2){if(this.config.ffmpeg==="文件列表"||this.config.ffmpeg==="文件列表+脚本"){if(!this.config.batchItems){this.entries.push({name:"ffmpeg-files.txt",data:t.map(t=>`file '${t.name}'`).join("\n")})}else{this.config.batchItems.forEach(t=>{this.entries.push({name:`${t.originalName}.txt`,data:t.fragmentNames.map(t=>`file '${t}'`).join("\n")})})}}if(this.config.ffmpeg==="文件列表+脚本"){const t=`ffmpeg -f concat -i ffmpeg-files.txt -c copy ""`;this.entries.push({name:"ffmpeg.bat",data:t},{name:"ffmpeg.sh",data:t.replace(/"/g,"'")})}}}async blob(){await this.preEmit();if(this.entries.length===0){return null}if(this.entries.length===1){const t=this.entries[0].data;return typeof t==="string"?new Blob([t]):t}const t=new JSZip;this.entries.forEach(({name:e,data:i})=>{t.file(e,i)});return await t.generateAsync({type:"blob"})}async emit(t){if(this.entries.length===0){return}if(!t||this.entries.length===1){t=this.entries[0].name}const e=await this.blob();if(!e){return}return this.download(t,e)}static async single(t,e,n={}){const s=new i(n);s.add(t,e);return await s.emit()}}i.lastPackageUrl="";return{export:{DownloadVideoPackage:i}}}})();