xl1 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-K6N7T6UC.js +1 -0
- package/dist/jsd1/index.js +2 -2
- package/dist/ssdl/index.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkNEJSZOZXjs = require('./chunk-NEJSZOZX.js');var S=_chunkNEJSZOZXjs.b.call(void 0, (j,f)=>{var d=_chunkNEJSZOZXjs.a.call(void 0, "axios"),x=_chunkNEJSZOZXjs.a.call(void 0, "cheerio"),l=_chunkNEJSZOZXjs.a.call(void 0, "fs"),r=_chunkNEJSZOZXjs.a.call(void 0, "path"),{format:u}=_chunkNEJSZOZXjs.a.call(void 0, "date-fns"),w=_chunkNEJSZOZXjs.a.call(void 0, "pptxgenjs"),m=_chunkNEJSZOZXjs.a.call(void 0, "winston"),g=m.createLogger({level:"info",format:m.format.combine(m.format.timestamp(),m.format.printf(({timestamp:n,level:t,message:e})=>`${n} [${t}]: ${e}`)),transports:[new m.transports.Console,new m.transports.File({filename:"combined.log"})]});function b(n,t){let e=new w;l.readdirSync(n).filter(i=>/\.(jpg|jpeg|png)$/.test(i)).forEach(i=>{let a=e.addSlide(),o=r.join(n,i);a.addImage({path:o,x:0,y:0,w:"100%",h:"100%"})}),e.writeFile(t)}var p=class{constructor(){this.url="",this.filename="",this.title="",this.images=[],this.meta={}}urlParse(t){(t.startsWith("'")&&t.endsWith("'")||t.startsWith('"')&&t.endsWith('"'))&&(t=t.slice(1,-1)),!t.startsWith("http://")&&!t.startsWith("https://")&&(t="https://"+t);let e=t.split("/").slice(3,5).join("_").replace(/[^0-9a-zA-Z]+/g,"-");return e.trim()===""&&(g.debug("Something wrong to get filename from URL, fallback to result.pdf"),e="output"),{url:t,filename:e}}isExists(t,e,s,i){let{url:a,filename:o}=this.urlParse(t),h=r.join(e,`${s?s+o:o}.${i}`);return l.existsSync(h)&&console.log("file exist!",h),l.existsSync(h)}async startParse(t,e){let{url:s,filename:i}=this.urlParse(t);this.url=s,this.filename=e?e+i:i;let o=(await d.get(this.url)).data,h=x.load(o);return this.title=`pdf_images_${u(new Date,"yyyy/MM/dd_HH:mm:ss")}`,this.images=h('img[data-testid="vertical-slide-image"]').toArray(),g.debug(this.images),this.getMeta(h)}async startDownload(t,e){if(!this.images||this.images.length===0){g.debug("no image to download");return}let s=r.resolve(r.join(t,this.filename));l.existsSync(s)||l.mkdirSync(s,{recursive:!0});for(let i of this.images){g.debug(i);let a=i.attribs.srcset.split(",").pop().split(" ")[1];g.debug(a),await this.saveFile(a,s)}e.includes("pdf")&&createPDF(s,r.join(t,`${this.filename}.pdf`)),e.includes("pptx")&&b(s,r.join(t,`${this.filename}.pptx`)),console.log("Download completed!",r.join(t,`${this.filename}.pptx`))}async saveFile(t,e){let s=r.join(e,r.basename(t));if(l.existsSync(s)){g.debug(`file exist! ${s}`);return}(await d.get(t,{responseType:"stream"})).data.pipe(l.createWriteStream(s))}clean(t){return String(t).trim()}getTitle(t){try{return this.clean(t("span.j-title-breadcrumb").text())}catch (e2){return""}}getDesc(t){try{return t("ol.transcripts").children("li").toArray().map(s=>this.clean(t(s).text()))}catch (e3){return[]}}getSummary(t){try{return this.clean(t("#slideshow-description-paragraph").text())}catch (e4){return""}}getAuthor(t){try{return this.clean(t('span[itemprop="name"]').text())}catch (e5){return""}}getPublish(t){try{return this.clean(t('time[itemprop="datePublished"]').text())}catch (e6){return""}}getMeta(t){return this.meta={url:this.url,name:this.filename,title:this.getTitle(t),summary:this.getSummary(t),publish:this.getPublish(t),desc:this.getDesc(t),author:this.getAuthor(t),created_at:u(new Date,"yyyy/MM/dd HH:mm:ss")},this.meta}};async function P(n,t,e,s=["pptx"],i=!1){let a=new p;if(a.isExists(n,t,e,s))return;let o=await a.startParse(n,e);await a.startDownload(t,s),i&&console.log(JSON.stringify(o,null,2))}f.exports={startDownloadSlideShare:P}});exports.a = S;
|
package/dist/jsd1/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
"use strict";var _chunkNEJSZOZXjs = require('../chunk-NEJSZOZX.js');var
|
|
3
|
-
`;
|
|
2
|
+
"use strict";var _chunkK6N7T6UCjs = require('../chunk-K6N7T6UC.js');var _chunkNEJSZOZXjs = require('../chunk-NEJSZOZX.js');var b=_chunkNEJSZOZXjs.b.call(void 0, (F,x)=>{var u=_chunkNEJSZOZXjs.a.call(void 0, "fs"),i=_chunkNEJSZOZXjs.a.call(void 0, "path"),k=_chunkNEJSZOZXjs.a.call(void 0, "axios"),_=_chunkNEJSZOZXjs.a.call(void 0, "marked"),$=_chunkNEJSZOZXjs.a.call(void 0, "glob"),j=_chunkNEJSZOZXjs.a.call(void 0, "https");async function v(e,n,p=!1){try{let a=await k({url:e,method:"GET",responseType:"stream",httpsAgent:new j.Agent({rejectUnauthorized:p})}),r=u.createWriteStream(n);return a.data.pipe(r),new Promise((m,h)=>{r.on("finish",m),r.on("error",h)})}catch(a){console.log("download error",e,n,a)}}async function E(e,n,p,a,r){let m=u.readFileSync(p,"utf-8"),h=_.lexer(m),w=o=>{let s=[];return o.forEach(t=>{t.type==="link"&&s.push(t),t.type==="table"&&t.rows.forEach(c=>{c.forEach(d=>{d.tokens&&(s=s.concat(w(d.tokens)))})}),t.tokens&&(s=s.concat(w(t.tokens))),t.items&&t.items.forEach(c=>{s=s.concat(w(c.tokens))})}),s};for(let o of w(h)){let s=[".mp3",".mp4",".pdf",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".epub",".mobi",".zip",".rar",".7z",".tar",".gz"].find(t=>o.href.endsWith(t)||o.text.endsWith(t));if(o.type==="link"){let t=o.href,c=i.basename(p).replace(".md",""),d=i.join(e,n,c);if(u.existsSync(d)||u.mkdirSync(d,{recursive:!0}),o.href.startsWith("https://www.slideshare.net")){let f=c+"_"+o.text.replace(/[<>:"/\\|?*\n\r]+/g,"_").replace(".pptx","")+"_";_chunkK6N7T6UCjs.a.call(void 0, ).startDownloadSlideShare(o.href,d,f,["pptx"],!1)}else if(s){let f=c+"_"+o.text.replace(/[<>:"/\\|?*\n\r]+/g,"_").replace(s,"")+"_"+i.basename(decodeURIComponent(t));f.endsWith(s)||(f+=s);let y=i.join(d,f);if(!u.existsSync(y)&&(console.log(`Downloading ${t} to ${y}`),await v(t,y,r),a)){let D=new Date().toISOString(),S=`${n},${c},${f},${t},${D}
|
|
3
|
+
`;u.appendFileSync(a,S)}}}}}function O(e){let n=e.docsDir||i.join(process.cwd(),"docs"),p=e.downloadDir||i.join(process.cwd(),"download");$.sync(`${n}/**/*.md`).forEach(r=>{let m=i.relative(n,r),h=i.dirname(m);E(p,h,r,e.csv,e.insecure).catch(console.error)})}var W={command:"*",describe:"jsd1",builder:{docs:{alias:"d",describe:"docs directory",demandOption:!1,default:"docs",type:"string"},output:{alias:"o",describe:"output directory",demandOption:!1,default:"download",type:"string"},csv:{alias:"c",describe:"csv log file",demandOption:!1,default:"output.csv",type:"string"},insecure:{alias:"k",describe:"allow insecure server connections",demandOption:!1,default:!1,type:"boolean"}},handler(e){(async()=>O({docsDir:e.docs,downloadDir:e.output,csv:e.csv,insecure:!e.insecure}))()}};x.exports=W});var z=()=>{let e=_chunkNEJSZOZXjs.a.call(void 0, "yargs").scriptName("jsd1");e.command(b());let n=e.parse()};z();
|
package/dist/ssdl/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
"use strict";var
|
|
2
|
+
"use strict";var _chunkK6N7T6UCjs = require('../chunk-K6N7T6UC.js');var _chunkNEJSZOZXjs = require('../chunk-NEJSZOZX.js');var{startDownloadSlideShare:d}=_chunkK6N7T6UCjs.a.call(void 0, ),n={command:"*",describe:"ssdl",builder:{url:{alias:"u",describe:"URL",demandOption:!0,type:"string"},dir:{alias:"d",describe:"Save directory",demandOption:!1,default:"./download",type:"string"},filename:{alias:"f",describe:"filename",demandOption:!1,type:"string"}},handler(e){(async()=>d(e.url,e.dir,e.filename,["pptx"],!1))()}},i=()=>{let e=_chunkNEJSZOZXjs.a.call(void 0, "yargs").scriptName("ssdl");e.command(n);let r=e.parse()};i();
|