Comparing version 0.5.0 to 0.5.1
#!/usr/bin/env node | ||
import{a as r,b,c as w}from"./chunk-TDJJNDZB.js";import x from"cli-progress";import y from"meow";import $ from"fs";import S from"path";import m from"chalk";var c=y(`USAGE | ||
import{a as o,b,c as w}from"./chunk-TDJJNDZB.js";import x from"cli-progress";import y from"meow";import $ from"fs";import v from"path";import d from"chalk";var m=y(` | ||
USAGE | ||
$ imgdl <url> ... [OPTIONS] | ||
@@ -33,8 +34,8 @@ | ||
$ imgdl https://example.com/image.jpg --header="User-Agent: Mozilla/5.0" --header="Cookie: foo=bar" | ||
`,{importMeta:import.meta,booleanDefault:void 0,flags:{dir:{shortFlag:"d",type:"string"},ext:{shortFlag:"e",type:"string"},header:{shortFlag:"H",type:"string",isMultiple:!0},increment:{shortFlag:"i",type:"boolean"},interval:{type:"number"},start:{type:"number"},end:{type:"number"},name:{shortFlag:"n",type:"string"},maxRetry:{type:"number"},silent:{type:"boolean"},step:{type:"number"},timeout:{shortFlag:"t",type:"number"}}}),T=m.bold.green,g=m.bold.red,v=m.yellow,s=m.dim;async function D(){let t=c.input,{flags:e}=c;if(t.length||c.showHelp(),e.increment){if(t.length>1)throw new r("Only one URL is allowed in increment mode");let n=t[0];if(!n.includes("{i}"))throw new r("The URL must contain {i} placeholder for the index");if(!e.end)throw new r("The end index is required in increment mode");if(e.start&&e.start>e.end)throw new r("The start index cannot be greater than the end index");let{start:i=0,end:l}=e;t=[];for(let p=i;p<=l;p+=1)t.push(n.replace("{i}",p.toString()))}e.silent||console.log(` | ||
`,{importMeta:import.meta,booleanDefault:void 0,flags:{dir:{shortFlag:"d",type:"string"},ext:{shortFlag:"e",type:"string"},header:{shortFlag:"H",type:"string",isMultiple:!0},increment:{shortFlag:"i",type:"boolean"},interval:{type:"number"},start:{type:"number"},end:{type:"number"},name:{shortFlag:"n",type:"string"},maxRetry:{type:"number"},silent:{type:"boolean"},step:{type:"number"},timeout:{shortFlag:"t",type:"number"},version:{shortFlag:"v",type:"boolean"}}}),S=d.bold.green,c=d.bold.red,T=d.yellow,s=d.dim;async function D(){let t=m.input,{flags:e}=m;if(e.version&&m.showVersion(),t.length||m.showHelp(),e.increment){if(t.length>1)throw new o("Only one URL is allowed in increment mode");let n=t[0];if(!n.includes("{i}"))throw new o("The URL must contain {i} placeholder for the index");if(!e.end)throw new o("The end index is required in increment mode");if(e.start&&e.start>e.end)throw new o("The start index cannot be greater than the end index");let{start:i=0,end:l}=e;t=[];for(let g=i;g<=l;g+=1)t.push(n.replace("{i}",g.toString()))}e.silent||console.log(` | ||
${s("Downloading...")} | ||
${v("Press Ctrl+C to abort")}`);let d=s("|"),a=new x.SingleBar({format:`{percentage}% [{bar}] {value}/{total} ${d} ${T("\u2705 {success}")} ${d} ${g("\u274C {errorCount}")} ${d} ETA: {eta_formatted} ${s("/ {duration_formatted}")}`,hideCursor:null,barsize:24}),h=0,o=0;!e.silent&&t.length>1&&a.start(t.length,0,{success:h,errorCount:o});let u={};e.header&&e.header.forEach(n=>{let[i,l]=n.split(":");if(!i||!l)throw new r("Invalid header format");u[i.trim()]=l.trim()});let f=new AbortController;process.on("SIGINT",()=>{a.stop(),console.log(s(` | ||
Aborting...`)),f.abort()}),await w(t.length===1?t[0]:t,{directory:e.dir,name:e.name,extension:e.ext,headers:u,interval:e.interval,onSuccess:()=>{e.silent||(h+=1,a.increment({success:h}))},onError:(n,i)=>{if(o+=1,e.silent||a.increment({errorCount:o}),n instanceof r||n instanceof b)throw n;$.appendFileSync(S.resolve(e.dir||process.cwd(),"error.log"),`${new Date().toISOString()} failed download from ${i}, ${n.name}: ${n.message} | ||
`)},maxRetry:e.maxRetry,step:e.step,timeout:e.timeout,signal:f.signal}),e.silent||(a.stop(),console.log(s("Done!")),o&&console.log(g(`${o} image${o>1?"s":""} failed to download. See ./error.log for details.`)))}D().catch(t=>{console.error(g(` | ||
${T("Press Ctrl+C to abort")}`);let h=s("|"),a=new x.SingleBar({format:`{percentage}% [{bar}] {value}/{total} ${h} ${S("\u2705 {success}")} ${h} ${c("\u274C {errorCount}")} ${h} ETA: {eta_formatted} ${s("/ {duration_formatted}")}`,hideCursor:null,barsize:24}),p=0,r=0;!e.silent&&t.length>1&&a.start(t.length,0,{success:p,errorCount:r});let u={};e.header&&e.header.forEach(n=>{let[i,l]=n.split(":");if(!i||!l)throw new o("Invalid header format");u[i.trim()]=l.trim()});let f=new AbortController;process.on("SIGINT",()=>{a.stop(),console.log(s(` | ||
Aborting...`)),f.abort()}),await w(t.length===1?t[0]:t,{directory:e.dir,name:e.name,extension:e.ext,headers:u,interval:e.interval,onSuccess:()=>{e.silent||(p+=1,a.increment({success:p}))},onError:(n,i)=>{if(r+=1,e.silent||a.increment({errorCount:r}),n instanceof o||n instanceof b)throw n;$.appendFileSync(v.resolve(e.dir||process.cwd(),"error.log"),`${new Date().toISOString()} failed download from ${i}, ${n.name}: ${n.message} | ||
`)},maxRetry:e.maxRetry,step:e.step,timeout:e.timeout,signal:f.signal}),e.silent||(a.stop(),console.log(s("Done!")),r&&console.log(c(`${r} image${r>1?"s":""} failed to download. See ./error.log for details.`)))}D().catch(t=>{console.error(c(` | ||
${t.name}: ${t.message}`)),process.exit(1)}); | ||
//# sourceMappingURL=cli.js.map |
{ | ||
"name": "img-dl", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "Download image(s), by command or programmatically", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
48888
188