Comparing version 0.7.0 to 0.7.2
#!/usr/bin/env node | ||
import{a as o,b,c as w}from"./chunk-EQYZCP6A.js";import x from"cli-progress";import y from"meow";import $ from"fs";import v from"path";import d from"chalk";var m=y(` | ||
import{a as r,b,c as w}from"./chunk-HVSPWQG2.js";import x from"cli-progress";import y from"meow";import $ from"fs";import v from"path";import p from"chalk";var d=y(` | ||
USAGE | ||
@@ -34,8 +34,8 @@ $ imgdl <url> ... [OPTIONS] | ||
$ 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"},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(0),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...")} | ||
${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)}); | ||
`,{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=p.bold.green,c=p.bold.red,T=p.yellow,m=p.dim;async function D(){let t=d.input,{flags:e}=d;if(e.version&&d.showVersion(),t.length||d.showHelp(0),e.increment){if(t.length>1)throw new r("Only one URL is allowed in increment mode");let l=t[0];if(!l.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:a=0,end:n}=e;t=[];for(let o=a;o<=n;o+=1)t.push(l.replace("{i}",o.toString()))}e.silent||console.log(` | ||
${m("Downloading...")} | ||
${T("Press Ctrl+C to abort")}`);let h=m("|"),s=new x.SingleBar({format:`{percentage}% [{bar}] {value}/{total} ${h} ${S("\u2705 {success}")} ${h} ${c("\u274C {errorCount}")} ${h} ETA: {eta_formatted} ${m("/ {duration_formatted}")}`,hideCursor:null,barsize:24}),g=0,i=0;!e.silent&&t.length>1&&s.start(t.length,0,{success:g,errorCount:i});let u={};e.header&&e.header.forEach(l=>{let[a,n]=l.split(":").map(o=>o.trim());if(!a||!n)throw new r("Invalid header format");u[a]=n});let f=new AbortController;process.on("SIGINT",()=>{s.stop(),console.log(m(` | ||
Aborting...`)),f.abort()}),await new Promise((l,a)=>{w(t,{directory:e.dir,name:e.name,extension:e.ext,headers:u,interval:e.interval,onSuccess:()=>{g+=1,e.silent||s.increment({success:g})},onError:(n,o)=>{if(i+=1,e.silent||s.increment({errorCount:i}),n instanceof r||n instanceof b)return a(n);$.appendFileSync(v.resolve(e.dir||process.cwd(),"error.log"),`${new Date().toISOString()} failed download from ${o}, ${n.name}: ${n.message} | ||
`)},maxRetry:e.maxRetry,step:e.step,timeout:e.timeout,signal:f.signal})}),e.silent||(s.stop(),console.log(m("Done!")),i&&console.log(c(`${i} image${i>1?"s":""} failed to download. See error.log for details.`)))}D().catch(t=>{console.error(c(` | ||
${t.name}: ${t.message}`))}); | ||
//# sourceMappingURL=cli.js.map |
@@ -1,2 +0,2 @@ | ||
import{c as a}from"./chunk-EQYZCP6A.js";export{a as default}; | ||
import{c as a}from"./chunk-HVSPWQG2.js";export{a as default}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "img-dl", | ||
"version": "0.7.0", | ||
"version": "0.7.2", | ||
"description": "Download image(s), by command or programmatically", | ||
@@ -14,11 +14,2 @@ "type": "module", | ||
], | ||
"scripts": { | ||
"lint": "eslint . && prettier --check .", | ||
"lint:fix": "eslint . --fix && prettier --write .", | ||
"test": "vitest run", | ||
"test:watch": "vitest", | ||
"test:cov": "vitest run --coverage", | ||
"build": "tsup src/index.ts src/cli.ts --format esm -d dist --clean --dts src/index.ts --sourcemap --minify", | ||
"prepublish": "npm run build" | ||
}, | ||
"repository": { | ||
@@ -65,3 +56,11 @@ "type": "git", | ||
"sanitize-filename": "^1.6.3" | ||
}, | ||
"scripts": { | ||
"lint": "eslint . && prettier --check .", | ||
"lint:fix": "eslint . --fix && prettier --write .", | ||
"test": "vitest run", | ||
"test:watch": "vitest", | ||
"test:cov": "vitest run --coverage", | ||
"build": "tsup src/index.ts src/cli.ts --format esm -d dist --clean --dts src/index.ts --sourcemap --minify" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51912