simple-aria2
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

simple-aria2


UseEnvironment

  1. The nodejs version is greater than 12
  2. Support for browsers and nodejs
  3. Please ensure that aria2 is enabled on your computer environment before use, otherwise it cannot be used normally

Introduction

Please ensure that aria2 is enabled on your computer environment before use, otherwise it cannot be used normally

Hello, my name is fuzhu, you can call me blue, here is my email 1774880816@qq.com

This dependency only provides the most basic download, get the download list, delete the task, suspend the task operation, other operations please send according to the project send or send_async two methods.

The dependency package was originally intended to be used by itself, and found that it was more comfortable to use after packaging, and directly open source.

Install

The installation method is very simple, you just need to enter these two lines of command in the command line

npm i simple-aria2

or

yarn add simple-aria2

The next step is to use it directly on nodejs

const Aria2 = require('simple-aria2').default

or

import Aria2 from 'simple-aria2'

UseExample

First

First we need to define an aria2 object, and here I'll use es6 module as an example

import Aria2 from 'simple-aria2'
// The aria2 address here is defined by you, using the websocket protocol
const mAria2 = new Aria2('ws://localhost:6800/jsonrpc')

Example

Get all downloads

This is a listening function that gets the download every 3 seconds and returns a time type. You can stop this function using the clearInterval method

mAria2.active(list => {
  console.log(list)
  // Can use stop callback
  // clearInterval(mTimer)
}, 3000)

Return example

[{"bitfield":"ffffffffffffffffffffff80","completedLength":"92999832","connections":"0","dir":"C:\\Users\\17748\\Desktop\\node-aria2","downloadSpeed":"0","errorCode":"0","files":[{"completedLength":"92999832","index":"1","length":"92999832","path":"C:/Users/17748/Desktop/node-aria2/dasd","selected":"true","uris":[{"status":"used","uri":"https://webcdn.m.qq.com/spcmgr/download/VSCodeUserSetup-x64-1.79.2.exe"},{"status":"used","uri":"https://webcdn.m.qq.com/spcmgr/download/VSCodeUserSetup-x64-1.79.2.exe"},{"status":"used","uri":"https://webcdn.m.qq.com/spcmgr/download/VSCodeUserSetup-x64-1.79.2.exe"},{"status":"waiting","uri":"https://webcdn.m.qq.com/spcmgr/download/VSCodeUserSetup-x64-1.79.2.exe"},{"status":"waiting","uri":"https://webcdn.m.qq.com/spcmgr/download/VSCodeUserSetup-x64-1.79.2.exe"}]}],"gid":"d9e82441075b4d17","numPieces":"89","pieceLength":"1048576","status":"complete","totalLength":"92999832","uploadLength":"0","uploadSpeed":"0"}]

Download file

The download url can be a seed or a magnetic or a normal url

This is a promise example that only returns the gid of the download list, which can be used to manipulate the download status, and more Gids can be viewed from the list

mAria2.add(
  'http://xxxx.xxxx',
  {
    dir: '',
    out: '',
    'split': 5,
    'max-connection-per-server': 1,
    'seed-ratio': 1
  }
).then(res => {
  console.log(res)
  // { id: 1, jsonrpc: '2.0', result: '3b096f6a4f0b322a' }
})

Paused, Continue, Remove

Pause, continue, the removal method is the same, just need to pass the corresponding gid line, gid please use the active function to get from the list

// Pause
mAria2.pause(['3b096f6a4f0b322a'])
.then(res => console.log(res))

// continue
mAria2.continue(['3b096f6a4f0b322a'])
.then(res => console.log(res))

// Remove
mAria2.remove(['3b096f6a4f0b322a'])
.then(res => console.log(res))

custom

This method allows you to customize some data to be sent

// use callback
mAria2.send({ method: 'aria2.tellActive' }, res => {
  console.log(res)
})

// use promise
mAria2.send_async({ method: 'aria2.tellActive' }).then(res => {
  console.log(res)
})

Package Sidebar

Install

npm i simple-aria2

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

10.9 kB

Total Files

4

Last publish

Collaborators

  • fuzhu