Giter Club home page Giter Club logo

naria2's Introduction

naria2

version version version CI

Convenient BitTorrent Client based on the aria2 JSON RPC Interface and aria2c CLI application with Web UI.

  • Download aria2 according to your platform
  • Convenient BitTorrent downloading API
  • Event bus used for watching progress, state change
  • Vite plugin which helps you develop aria2 client application
  • Web UI for aria2c (more features is working in progress)

home

Cross-platform aria2c

It is used in the same way as aria2c.

$ npm i -g naria2c

$ naria2c --version
naria2c/0.0.23
--------------
...

$ naria2c --help

You can also launch a Web UI to manage aria2 using the --ui option. This feature is provided by this package, not the original aria2.

$ naria2c --ui
...
10/29 21:22:46 [NOTICE] WebUI is listening on the http://127.0.0.1:6801?port=6800&secret=123456
...

Installation

Browser

npm i naria2

Using WebSocket:

import { createClient } from 'naria2'

const client = await createClient(
  new WebSocket('ws://localhost:6800/jsonrpc')
)

Using HTTP:

import { createClient } from 'naria2'
import { createHTTP } from 'naria2/transport'

const client = await createClient(
  createHTTP('http://localhost:6800/jsonrpc')
)

Node.js standalone

If you want to use naria2 in the Node.js standalone, you can install @naria2/node. It has included a prebuilt aria2 binary according to your architecture, so that there is no need to install a aria2 on your own.

npm i naria2 @naria2/node

You can use the createChildProcess API to spawn an aria2 child process, and connect to it in WebScoket under the hood.

import { createClient } from 'naria2'
import { createChildProcess } from '@naria2/node'

const client = await createClient(createChildProcess())

Warning

You should close the client on your own, otherwise the aria2 process may not be killed even if your program finished or crashed.

See my blog post (in Chinese) or The Death of a Node.js Process (in English) on how to handle the exit of a Node.js process.

Usage

import { createClient } from 'naria2'

// Initialize a client
const client = await createClient(
  new WebSocket('ws://localhost:6800/jsonrpc')
)

// Start downloading a magnet
const torrent = await client.downloadTorrent('...')

// Watch metadata progress
await torrent.watch((torrent) => {
  console.log(`Downloading [MEATADATA]`)
})
// Watch torrent progress
await torrent.watchFollowedBy((torrent) => {
  console.log(`Downloading ${torrent.name}`)
})

// Shutdown client
await client.shutdown()

Due to the implementation of aria2, the downloading progress of a magnet uri includes two steps:

  1. Download the torrent metadata which contains only a special file named [METADATA];
  2. Download the torrent content itself.

So that, in the above code, you should first wait for downloading metadata, and then wait for downloading the followed by task which is the torrent content itself.

You can find an example using Node.js here.

Credits

  • aria2: A lightweight multi-protocol & multi-source, cross platform download utility operated in command-line
  • @hydrati made maria2
  • Motrix: Build aria2 binaries for different platforms

License

MIT License ยฉ 2023 XLor

naria2's People

Contributors

hydrati avatar renovate[bot] avatar yjl9903 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

hydrati

naria2's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency @types/serve-static to ^1.15.7
  • chore(deps): update dependency autoprefixer to ^10.4.19
  • chore(deps): update dependency postcss to ^8.4.38
  • chore(deps): update dependency tailwindcss to ^3.4.3
  • chore(deps): update iconify (@iconify-json/carbon, @iconify-json/fluent, @iconify-json/material-symbols, @iconify-json/mdi)
  • chore(deps): update pnpm to v8.15.7
  • chore(deps): update react monorepo (@types/react, @types/react-dom)
  • fix(deps): update dependency @formkit/auto-animate to ^0.8.2
  • fix(deps): update dependency react-router-dom to ^6.22.3
  • fix(deps): update dependency tailwind-merge to ^2.2.2
  • fix(deps): update dependency zustand to ^4.5.2
  • chore(deps): update dependency @types/node to ^20.12.7
  • chore(deps): update dependency express to ^4.19.2
  • chore(deps): update dependency turbo to ^1.13.2
  • chore(deps): update dependency typescript to ^5.4.5
  • chore(deps): update dependency vite to ^5.2.8
  • chore(deps): update dependency vitest to ^1.5.0
  • fix(deps): update dependency date-fns to ^3.6.0
  • fix(deps): update dependency open to ^10.1.0
  • fix(deps): update dependency react-hook-form to ^7.51.3
  • fix(deps): update dependency http-proxy-middleware to v3
  • chore(deps): lock file maintenance
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v4@b4ffde65f46336ab88eb53be808477a3936bae11
  • pnpm/action-setup v3.0.0
  • actions/setup-node v4
.github/workflows/release.yml
  • actions/checkout v4@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/setup-node v4
nodenv
.node-version
npm
package.json
  • @types/cli-progress ^3.11.5
  • @types/node ^20.11.20
  • @types/ws ^8.5.10
  • cli-progress ^3.12.0
  • execa ^8.0.1
  • turbo ^1.12.4
  • typescript ^5.3.3
  • unbuild ^2.0.0
  • vite ^5.1.4
  • vitest ^1.3.1
  • ws ^8.16.0
  • pnpm 8.15.4
packages/app/package.json
  • @formkit/auto-animate ^0.8.1
  • @hookform/resolvers ^3.3.4
  • @radix-ui/react-alert-dialog ^1.0.5
  • @radix-ui/react-label ^2.0.2
  • @radix-ui/react-menubar ^1.0.4
  • @radix-ui/react-navigation-menu ^1.1.4
  • @radix-ui/react-progress ^1.0.3
  • @radix-ui/react-scroll-area ^1.0.5
  • @radix-ui/react-slot ^1.0.2
  • @radix-ui/react-switch ^1.0.3
  • @radix-ui/react-toast ^1.1.5
  • @tanstack/react-query ^5.22.2
  • class-variance-authority ^0.7.0
  • clsx ^2.1.0
  • date-fns ^3.3.1
  • localforage ^1.10.0
  • lucide-react ^0.336.0
  • match-sorter ^6.3.4
  • react ^18.2.0
  • react-dom ^18.2.0
  • react-hook-form ^7.50.1
  • react-router-dom ^6.22.1
  • sort-by ^1.2.0
  • tailwind-merge ^2.2.1
  • zod ^3.22.4
  • zustand ^4.5.1
  • @egoist/tailwindcss-icons ^1.7.4
  • @iconify-json/carbon ^1.1.30
  • @iconify-json/fluent ^1.1.48
  • @iconify-json/ic ^1.1.17
  • @iconify-json/material-symbols ^1.1.73
  • @iconify-json/mdi ^1.1.64
  • @iconify-json/solar ^1.1.9
  • @tanstack/react-query-devtools ^5.24.0
  • @types/fs-extra ^11.0.4
  • @types/react ^18.2.58
  • @types/react-dom ^18.2.19
  • @vitejs/plugin-react-swc ^3.6.0
  • autoprefixer ^10.4.17
  • fs-extra ^11.2.0
  • postcss ^8.4.35
  • shadcn-ui ^0.8.0
  • tailwindcss ^3.4.1
  • tailwindcss-animate ^1.0.7
  • vite ^5.1.4
  • vite-plugin-info ^0.4.1
  • vite-plugin-top-level-await ^1.4.1
packages/binary/darwin-arm64/package.json
packages/binary/darwin-x64/package.json
packages/binary/linux-arm64/package.json
packages/binary/linux-x64/package.json
packages/binary/win32-ia32/package.json
packages/binary/win32-x64/package.json
packages/naria2/package.json
  • maria2 ^0.3.2
  • mitt ^3.0.1
  • type-fest ^4.10.2
  • @types/ws ^8.5.10
  • vitest ^1.3.1
  • ws ^8.16.0
packages/naria2c/package.json
  • @breadc/color ^0.9.7
  • @breadc/death ^0.9.7
  • open ^10.0.3
  • portfinder ^1.0.32
packages/node/package.json
  • @breadc/color ^0.9.7
  • @breadc/death ^0.9.7
  • execa ^8.0.1
  • finalhandler ^1.2.0
  • http-proxy-middleware ^2.0.6
  • maria2 ^0.3.2
  • open ^10.0.3
  • portfinder ^1.0.32
  • serve-static ^1.15.0
  • type-fest ^4.10.2
  • ws ^8.16.0
  • @types/express ^4.17.21
  • @types/finalhandler ^1.2.3
  • @types/serve-static ^1.15.5
  • express ^4.18.2
packages/options/package.json
  • maria2 ^0.3.2
  • type-fest ^4.10.2
  • vitest ^1.3.1
packages/vite-plugin-naria2/package.json
  • @breadc/color ^0.9.7
  • type-fest ^4.10.2
  • vite ^5.1.4
  • vitest ^1.3.1

  • Check this box to trigger a request for Renovate to run again on this repository

Can you provide support for node v18๏ผŸ

Clear and concise description of the problem

I'm using @naria2/node for my electron applications to automatically build the system version for cross-platform use. However, even the latest stable version of electron does not have node versions up to V20, and there are still many bugs to be fixed in 26, 27, and 28, so node V18 is still a very high share of electron applications. Is it possible to support @naria2/node over v18?

Suggested solution

No response

Additional context

No response

Some values appear to be abnormal when downloading over http

Describe the bug

downloadSpeed and progress are not available for http downloads. They both have values of 0. Are they bugs or not currently supported?

The watchFollowedBy method was also not found

const downloadUri =
  "https://cloudflare-ipfs.com/ipfs/QmYvVLJeW2FiTPtC19WWh7fnhZeMzMmK16QcBd6ervq7TD";

const client = await createClient(createChildProcess());

const p = await client.downloadUri(downloadUri, {
  dir: ".",
});

await p.watch((t) => {
  console.log(t.progress);
});

// not found function
// await p.watchFollowedBy((t) => {
//     console.log(t)
// })

Reproduction

No response

System Info

No response

Used Package Manager

None

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.