Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

img-dl

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

img-dl - npm Package Compare versions

Comparing version 0.7.3 to 0.7.4

14

dist/cli.js
#!/usr/bin/env node
import{a as i,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(`
import{a as r,b,c as w}from"./chunk-HVSPWQG2.js";import x from"cli-progress";import $ from"meow";import v from"fs";import S from"path";import g from"chalk";function y(e,i){if(!i.increment)return e;if(e.length!==1)throw new r("Only one URL is allowed in increment mode");if(!e[0].includes("{i}"))throw new r("The URL must contain {i} placeholder for the index");let{start:a=0,end:n=0}=i;if(a<0)throw new r("Start value must be greater than or equal to 0");if(a>n)throw new r("Start value must be less than or equal to end value");let l=[];for(let t=a;t<=n;t+=1)l.push(e[0].replace("{i}",t.toString()));return l}var d=$(`
USAGE

@@ -13,3 +13,3 @@ $ imgdl <url> ... [OPTIONS]

-d, --dir=<path> The output directory. Default: current working directory
--end=<number> The end index. Required in increment mode
--end=<number> The end index for increment mode. Default: 0
-e, --ext=<ext> The file extension. Default: original extension or jpg

@@ -35,8 +35,8 @@ -h, --help Show this help message

$ 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=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 i("Only one URL is allowed in increment mode");let s=t[0];if(!s.includes("{i}"))throw new i("The URL must contain {i} placeholder for the index");if(!e.end)throw new i("The end index is required in increment mode");if(e.start&&e.start>e.end)throw new i("The start index cannot be greater than the end index");let{start:o=0,end:n}=e;t=[];for(let r=o;r<=n;r+=1)t.push(s.replace("{i}",r.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"}}}),D=g.bold.green,h=g.bold.red,T=g.yellow,m=g.dim;async function E(){let{flags:e}=d,i=y(d.input,e);e.version&&d.showVersion(),i.length||d.showHelp(0),e.silent||console.log(`
${m("Downloading...")}
${T("Press Ctrl+C to abort")}`);let h=m("|"),l=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,a=0;!e.silent&&t.length>1&&l.start(t.length,0,{success:g,errorCount:a});let u={};e.header&&e.header.forEach(s=>{let[o,n]=s.split(":").map(r=>r.trim());if(!o||!n)throw new i("Invalid header format");u[o]=n});let f=new AbortController;process.on("SIGINT",()=>{l.stop(),console.log(m(`
Aborting...`)),f.abort()}),await new Promise((s,o)=>{w(t,{directory:e.dir,name:e.name,extension:e.ext,headers:u,interval:e.interval,onSuccess:()=>{g+=1,e.silent||l.increment({success:g})},onError:(n,r)=>{if(a+=1,e.silent||l.increment({errorCount:a}),n instanceof i||n instanceof b)return o(n);$.appendFileSync(v.resolve(e.dir||process.cwd(),"error.log"),`${new Date().toISOString()} failed download from ${r}, ${n.name}: ${n.message}
`)},maxRetry:e.maxRetry,step:e.step,timeout:e.timeout,signal:f.signal}).then(s,o)}),e.silent||(l.stop(),console.log(m("Done!")),a&&console.log(c(`${a} image${a>1?"s":""} failed to download. See error.log for details.`)))}D().catch(t=>{console.error(c(`
${t.name}: ${t.message}`))});
${T("Press Ctrl+C to abort")}`);let a=m("|"),n=new x.SingleBar({format:`{percentage}% [{bar}] {value}/{total} ${a} ${D("\u2705 {success}")} ${a} ${h("\u274C {errorCount}")} ${a} ETA: {eta_formatted} ${m("/ {duration_formatted}")}`,hideCursor:null,barsize:24}),l=0,t=0;!e.silent&&i.length>1&&n.start(i.length,0,{success:l,errorCount:t});let u={};e.header&&e.header.forEach(p=>{let[s,o]=p.split(":").map(c=>c.trim());if(!s||!o)throw new r("Invalid header format");u[s]=o});let f=new AbortController;process.on("SIGINT",()=>{n.stop(),console.log(m(`
Aborting...`)),f.abort()});try{await new Promise((p,s)=>{w(i,{directory:e.dir,name:e.name,extension:e.ext,headers:u,interval:e.interval,onSuccess:()=>{l+=1,e.silent||n.increment({success:l})},onError:(o,c)=>{if(o instanceof r||o instanceof b)return s(o);t+=1,e.silent||n.increment({errorCount:t}),v.appendFileSync(S.resolve(e.dir||process.cwd(),"error.log"),`${new Date().toISOString()} failed download from ${c}, ${o.name}: ${o.message}
`)},maxRetry:e.maxRetry,step:e.step,timeout:e.timeout,signal:f.signal}).then(p,s)})}finally{e.silent||(n.stop(),console.log(m("Done!")),t&&console.log(h(`${t} image${t>1?"s":""} failed to download. See error.log for details.`)))}}E().catch(e=>{console.error(h(`
${e.name}: ${e.message}`))});
//# sourceMappingURL=cli.js.map
{
"name": "img-dl",
"version": "0.7.3",
"version": "0.7.4",
"description": "Download image(s), by command or programmatically",

@@ -5,0 +5,0 @@ "type": "module",

@@ -79,3 +79,3 @@ # img-dl

-d, --dir=<path> The output directory. Default: current working directory
--end=<number> The end index. Required in increment mode
--end=<number> The end index for increment mode. Default: 0
-e, --ext=<ext> The file extension. Default: original extension or jpg

@@ -82,0 +82,0 @@ -h, --help Show this help message

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc