4chan-downloader 中文文档教程

发布于 10年前 浏览 23 更新于 3年前

4chan-downloader

下载 4chan 线程中的所有文件。

Install

npm install -g 4chan-downloader

CLI

帮助输出:

Usage: 4chan [options] <url> [<dir>]

Examples:
  4chan <url>                Download all files in a thread into {cwd}.
  4chan <url> foo            Download all files in a thread into {cwd}/foo.
  4chan <url> foo/bar        Download all files in a thread into {cwd}/foo/bar.
  4chan -w <url>             Download all and watch for new files.
  4chan -w -i 20 <url>       Download all and check for new files every 20 seconds.
  4chan -f gif,webm <url>    Download all gif and webm files.
  4chan -s 200x100 <url>     Download all files bigger than 200x100 pixels.
  4chan -s 100 <url>         Download all files bigger than 100x100 pixels.


Options:
  -w, --watch     Watch for new files.
  -i, --interval  Watching interval in seconds.     [default: 10]
  -f, --filter    Filter specific file types.       [default: "jpg,gif,png,webm"]
  -o, --override  Override existing files.
  -n, --names     Save with original file names.
  -s, --size      Smallest files to download.       [default: "100x100"]
  -t, --threads   Limit of simultaneous downloads.  [default: 1]
  -v, --version   Show version.
  -h, --help      Show help.

API

var FortuneDownloader = require('4chan-downloader');
var thread = new FortuneDownloader('http://boards...')
    .threads(4)
    .watch()
    .downloadTo('foo/bar');
// ...
thread.stop();

FortuneDownloader(url)

构造函数。 new 关键字是可选的。 所有方法都是链接的。

#threads(count)

设置下载线程数。

#watch([interval])

让实例监视新文件。

interval Integer 以毫秒为单位的观看间隔。 默认值:10000

#filter(fun)

过滤掉特定文件的自定义函数。 当应该下载文件时,函数返回 true,否则返回 false

函数参数:

  1. file Object File description object: js { url: 'http://i.4cdn.org/g/1407348528901.jpg', prettysize: '650 KB', width: 1920, height: 1080, name: 'Original file name.jpg', idname: '1407348528901.jpg', type: 'jpg', size: 0, // set when file stars downloading completed: 0, // updated during downloading progress: 0 // updated during downloading }

#namer(fun)

返回保存文件时使用的名称的自定义函数。

函数参数:

  1. file Object File description object: js { url: 'http://i.4cdn.org/g/1407348528901.jpg', prettysize: '650 KB', width: 1920, height: 1080, name: 'Original file name.jpg', idname: '1407348528901.jpg', type: 'jpg', size: 0, // set when file stars downloading completed: 0, // updated during downloading progress: 0 // updated during downloading }

#override(state)

设置实例是否应该覆盖已经存在的文件。 默认行为是 false

  • state Boolean

#destination(path)

保存文件的位置。 默认情况下,文件保存在当前工作目录中。

  • path String

#download()

开始下载。

#downloadTo(path)

简写:

FortuneDownloader(url)
    .destination('foo/bar')
    .download();

#stop()

清除当前下载队列,并在进行中取消观看。

不会取消正在进行的下载流。

在调用 #stop() 并且正在进行的下载完成后,将触发 end 事件。 如果没有正在进行的下载,end 将被立即触发。

Properties

url

输入<代码>字符串。 主题网址。

queue

键入数组。 要下载的文件数组(文件描述符对象)。 文件在 file:start 事件之前从此处删除。

finished

键入数组。 下载的文件 URL 数组。 当 watching 处于活动状态时,任何后续下载都将过滤掉此数组中的文件。

active

输入<代码>整数。 当前正在进行的活动下载线程数。

Events

FortuneDownloader 实例是一个事件发射器。

parse

当页面已被解析且 #queue 数组已填充即将下载的文件时触发。

error

发生下载取消错误时触发。 当此事件触发时,end 事件不会。

回调参数:

  1. error Error

end

当下载实例完成所有文件的下载,并且未启用监视时触发。

当调用 #stop() 并且所有正在进行的下载完成时也会触发。

file:start

文件开始下载时触发​​。

回调参数:

  1. file Object File descriptor object: js { url: 'http://i.4cdn.org/g/1407348528901.jpg', prettysize: '650 KB', width: 1920, height: 1080, name: 'Original file name.jpg', idname: '1407348528901.jpg', type: 'jpg', size: 665600, // available now completed: 0, progress: 0 }

file:chunk

收到文件块时触发。

回调参数:

  1. chunk Buffer
  2. file Object File descriptor object: js { url: 'http://i.4cdn.org/g/1407348528901.jpg', prettysize: '650 KB', width: 1920, height: 1080, name: 'Original file name.jpg', idname: '1407348528901.jpg', type: 'jpg', size: 665600, completed: 40253, // sum of all chunks till now progress: 0.06139871873093349603416717510677 // completed / size }

file:progress

与 chunk 相同,但没有 chunk 参数:

  1. file Object File descriptor object: js { url: 'http://i.4cdn.org/g/1407348528901.jpg', prettysize: '650 KB', width: 1920, height: 1080, name: 'Original file name.jpg', idname: '1407348528901.jpg', type: 'jpg', size: 665600, completed: 40253, // sum of all chunks till now progress: 0.06139871873093349603416717510677 // completed / size }

file:error

当文件下载发生错误时触发。 这些错误不会停止下载过程。

回调参数:

  1. error Error
  2. file Object File descriptor object.

file:end

文件下载完成时触发。

回调参数:

  1. file Object File descriptor object.

License

MIT

4chan-downloader

Downloads all files in 4chan threads.

Install

npm install -g 4chan-downloader

CLI

Help output:

Usage: 4chan [options] <url> [<dir>]

Examples:
  4chan <url>                Download all files in a thread into {cwd}.
  4chan <url> foo            Download all files in a thread into {cwd}/foo.
  4chan <url> foo/bar        Download all files in a thread into {cwd}/foo/bar.
  4chan -w <url>             Download all and watch for new files.
  4chan -w -i 20 <url>       Download all and check for new files every 20 seconds.
  4chan -f gif,webm <url>    Download all gif and webm files.
  4chan -s 200x100 <url>     Download all files bigger than 200x100 pixels.
  4chan -s 100 <url>         Download all files bigger than 100x100 pixels.


Options:
  -w, --watch     Watch for new files.
  -i, --interval  Watching interval in seconds.     [default: 10]
  -f, --filter    Filter specific file types.       [default: "jpg,gif,png,webm"]
  -o, --override  Override existing files.
  -n, --names     Save with original file names.
  -s, --size      Smallest files to download.       [default: "100x100"]
  -t, --threads   Limit of simultaneous downloads.  [default: 1]
  -v, --version   Show version.
  -h, --help      Show help.

API

var FortuneDownloader = require('4chan-downloader');
var thread = new FortuneDownloader('http://boards...')
    .threads(4)
    .watch()
    .downloadTo('foo/bar');
// ...
thread.stop();

FortuneDownloader(url)

Consturctor. new keyword is optional. All methods are chaining.

#threads(count)

Set number of downloading threads.

#watch([interval])

Make instance watch for new files.

interval Integer Watching interval in millisecods. Default: 10000

#filter(fun)

Custom function that filters out specific files. Function returns true when the file should be downloaded and false otherwise.

Function arguments:

  1. file Object File description object: js { url: 'http://i.4cdn.org/g/1407348528901.jpg', prettysize: '650 KB', width: 1920, height: 1080, name: 'Original file name.jpg', idname: '1407348528901.jpg', type: 'jpg', size: 0, // set when file stars downloading completed: 0, // updated during downloading progress: 0 // updated during downloading }

#namer(fun)

Custom function that returns the name to be used when saving files.

Function arguments:

  1. file Object File description object: js { url: 'http://i.4cdn.org/g/1407348528901.jpg', prettysize: '650 KB', width: 1920, height: 1080, name: 'Original file name.jpg', idname: '1407348528901.jpg', type: 'jpg', size: 0, // set when file stars downloading completed: 0, // updated during downloading progress: 0 // updated during downloading }

#override(state)

Set whether instance should override already existing files. Default behavior is false.

  • state Boolean

#destination(path)

Where to save files. By default files are saved into current working directory.

  • path String

#download()

Starts downloading.

#downloadTo(path)

Shorthand for:

FortuneDownloader(url)
    .destination('foo/bar')
    .download();

#stop()

Clears current download queue, and cancels watching when in progress.

It does not cancel ongoing download streams.

After #stop() has been called and ongoing downloads finished, end event will be fired. If there were no ongoing downloads, end will be fired immediately.

Properties

url

Type String. Thread URL.

queue

Type Array. Array of files (file descriptor objects) to be downloaded. File is removed from here right before file:start event.

finished

Type Array. Array of downloaded file URLs. When watching is active, any subsequent download will filter out files in this array.

active

Type Integer. Number of currently active download threads in progress.

Events

FortuneDownloader instance is an event emitter.

parse

Triggered when page has been parsed, and #queue array has been populated with files soon to be downloaded.

error

Triggered when download canceling error has happened. When this event fires, end event won't.

Callback arguments:

  1. error Error

end

Triggered when download instance has finished downloading all files, and watching is not enabled.

Also fires when #stop() is called and all ongoing downloads finish.

file:start

Triggered when file starts downloading.

Callback arguments:

  1. file Object File descriptor object: js { url: 'http://i.4cdn.org/g/1407348528901.jpg', prettysize: '650 KB', width: 1920, height: 1080, name: 'Original file name.jpg', idname: '1407348528901.jpg', type: 'jpg', size: 665600, // available now completed: 0, progress: 0 }

file:chunk

Triggered when chunk of a file has been received.

Callback arguments:

  1. chunk Buffer
  2. file Object File descriptor object: js { url: 'http://i.4cdn.org/g/1407348528901.jpg', prettysize: '650 KB', width: 1920, height: 1080, name: 'Original file name.jpg', idname: '1407348528901.jpg', type: 'jpg', size: 665600, completed: 40253, // sum of all chunks till now progress: 0.06139871873093349603416717510677 // completed / size }

file:progress

Same as chunk, but without the chunk argument:

  1. file Object File descriptor object: js { url: 'http://i.4cdn.org/g/1407348528901.jpg', prettysize: '650 KB', width: 1920, height: 1080, name: 'Original file name.jpg', idname: '1407348528901.jpg', type: 'jpg', size: 665600, completed: 40253, // sum of all chunks till now progress: 0.06139871873093349603416717510677 // completed / size }

file:error

Triggered when file downloading error has happened. These errors don't stop the downloading process.

Callback arguments:

  1. error Error
  2. file Object File descriptor object.

file:end

Triggered when file has finished with downloading.

Callback arguments:

  1. file Object File descriptor object.

License

MIT

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文