npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

transmission-promise

v1.1.7

Published

An API client for Transmission that uses promises

Downloads

67

Readme

transmission-promise

A transmission-daemon wrapper using promises.

This was adapted from FLYBYME's node-transmission (transmission package on npm). It contains the same functionality, but is an es6 class and it uses promises instead of callbacks.

Installation

npm i --save transmission-promise

Initialization

const Transmission = require('transmission-promise')
const transmission = new Transmission({
  host: 'localhost', // default 'localhost'
  port: 9091, // default 9091
  username: 'username', // default blank
  password: 'password', // default blank
  ssl: true, // default false use https
  url: '/my/other/url', // default '/transmission/rpc'
})

Definition

Status

RPC returns torrent status with an integer from 0 to 7.

Use transmission.status to check the status with a human-readable variable.

transmission.status = {
  STOPPED       : 0,  // Torrent is stopped
  CHECK_WAIT    : 1,  // Queued to check files
  CHECK         : 2,  // Checking files
  DOWNLOAD_WAIT : 3,  // Queued to download
  DOWNLOAD      : 4,  // Downloading
  SEED_WAIT     : 5,  // Queued to seed
  SEED          : 6,  // Seeding
  ISOLATED      : 7   // Torrent can't find peers
}

Functions

Functions that have an ids parameter can usually be passed either a single integer or an array of integers.

The add functions take a second options parameter that would be the arguments passed to Transmission. For example, if you want to set the download directory of the torrent you would pass in "download-dir": "/my/path". See the rpc-spec for more information.

option key           | value type & description
---------------------+-------------------------------------------------
"cookies"            | string      pointer to a string of one or more cookies.
"download-dir"       | string      path to download the torrent to
"filename"           | string      filename or URL of the .torrent file
"metainfo"           | string      base64-encoded .torrent content
"paused"             | boolean     if true, don't start the torrent
"peer-limit"         | number      maximum number of peers
"bandwidthPriority"  | number      torrent's bandwidth tr_priority_t
"files-wanted"       | array       indices of file(s) to download
"files-unwanted"     | array       indices of file(s) to not download
"priority-high"      | array       indices of high-priority file(s)
"priority-low"       | array       indices of low-priority file(s)
"priority-normal"    | array       indices of normal-priority file(s)

addFile(filePath, options = {})

Add torrents to Transmission using a torrent file.

// With just the path
transmission.addFile('path').then(res => ...)

// Include additional options
transmission.addFile('path', {
  'download-dir': '/a/path/different/than/my/settings'
}).then(res => ...)

addUrl(url, options = {})

Alias: add()

Add torrents to Transmission via a magnet link or a url to a torrent file.

transmission.addUrl('url').then(res => ...)

transmission.add('url', options).then(res => ...)

addBase64(string, options = {})

Adds a torrent with a base64 encoded string of a torrent file contents.

transmission.addBase64(myString, options).then(res => ...)

set(ids)

Set a torrent's properties. See the spec for valid options.

transmission.set(id, options).then(() => ...)

You must provide one or more ids. According to the spec, transmission will not respond with a success argument, only an error.

remove(ids, deleteLocalData = false)

Remove torrents. Remove local data by passing true as the second argument.

// Removes the torrent, but keeps local data
transmission.remove(ids).then(res => ...)

// Removes the torrent and downloaded data
transmission.remove(ids, true).then(res => ...)

active()

List of active torrents.

transmission.active().then(res => ...)

get(ids, fields = [])

Gets torrent information. If ids is falsy, it will get all the torrents. The fields array is the desired fields from the spec. By default it will be retrieve all fields.

// A selection of torrents (one or many)
transmission.get(ids).then(res => {
  for (const torrent of res.torrents) {
    //
  }
})

// All torrents and only the upload ratio
transmission.get(false, ['uploadRatio']).then(res => {
  for (const torrent of res.torrents) {
    // torrent.uploadRatio
  }
})

// Get all torrents and remove it if status is stopped.
transmission.get().then(res => {
  for (const torrent of res.torrents) {
    if (torrent.status === transmission.status.STOPPED) {
      transmission.remove(torrent.id).then(() => {
        console.log(`${torrent.name} removed!`)
      })
    }
  }
}).catch(err => console.error(err))

waitForState(id, targetState)

Polls the server and waits for the target state.

State options: STOPPED, CHECK_WAIT, CHECK, DOWNLOAD_WAIT, DOWNLOAD, SEED_WAIT, SEED, ISOLATED

transmission.waitForState(id, 'DOWNLOAD').then(res => {
  // Torrent is downloading!
})

stop(ids)

Stop working torrents.

// Stops a selection of torrents
transmission.stop(ids).then(res => ...)

// Stops all torrents
transmission.stop().then(res => ...)
// or
transmission.stopAll().then(res => ...)

start(ids)

Start working torrents.

// Starts a selection of torrents
transmission.start(ids).then(res => ...)

// Starts all torrents
transmission.start().then(res => ...)
// or
transmission.startAll().then(res => ...)

startNow(ids)

Bypass the download queue, start working torrents immediately.

transmission.startNow(ids).then(res => ...)

verify(ids)

Verify torrent data.

transmission.verify(id).then(res => ...)

rename(ids, path, name)

Renames a file or folder in a torrent. The path argument is the current relative file path that you get from the file information of get(), and name is the new name.

// Get the file information first
transmission.get(id, ['files']).then(res => {
  // Assume it's just one torrent...
  const torrent = res.torrents[0]

  // Iterate over the files
  // Renames all the files to something new
  for (const file of torrent.files) {
    const newName = makeNewName()

    transmission.rename(torrent.id, file.name, newName)
  }

  // Changes the torrent directory name
  const p = require('path')
  const directory = p.dirname(torrent.files[0])

  transmission.rename(torrent.id, directory, makeNewName())
})

reannounce(ids)

Reannounce to the tracker, ask for more peers.

transmission.reannounce(ids).then(res => ...)

session()

Get client session infomation.

transmission.session().then(res => ...)

session(options)

Set session infomation. See the spec for possible options.

transmission.session({ 'download-dir':'/my/path' }).then(res => ...)

sessionStats()

Get client session stats. See the spec for results.

transmission.sessionStat().then(res => ...)

freeSpace(path)

Get free space available on the server for the specified directory.

transmission.freeSpace(path).then(res => ...)

License

MIT