Skip to content
transmission torrent RPC client.
JavaScript
Find file
Latest commit 8ab8e54 Mar 13, 2016 @btn-stuff btn-stuff Bump
Failed to load latest commit information.
bin fixed #35 + code cleanup Mar 7, 2016
lib From pull request #31 Mar 13, 2016
test fixed #35 + code cleanup Mar 6, 2016
.gitignore test with mocha and jshint Oct 23, 2014
.jshintignore test with mocha and jshint Oct 23, 2014
.jshintrc test with mocha and jshint Oct 23, 2014
README.md Update README.md Mar 5, 2016
example.js Updated demo torrent Feb 7, 2015
package.json Bump Mar 13, 2016

README.md

node-transmission

transmission-daemon wrapper script written in node.js

Install

npm install transmission

How to Use

Transmission = require 'transmission'
transmission = new Transmission
  host: 'localhost'  # default 'localhost'
  port: 9091         # default 9091
  username: 'username'   # default blank
  password: 'password'   # default blank
  url: '/my/other/url'   # default '/transmission/rpc'

Definition

Status

RPC returned torrent status with integer 0-7.

Using transmission.status for inspect status.

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

Methods

transmission.set([ids], callback)

Set torrent's properties.

transmission.set(id, options, function(err, arg){});

You must provide one or more ids. According to the rpc-spec, transmission will not respond a success argument. Only error.

transmission.addFile(filePath, callback)

Add torrents to transmission-daemon.

transmission.addFile('path', function(err, arg){});

OR

The options object would be the arguments passed to transmission. If you want to set the download directory of the torrent you would pass in "download-dir":"/my/path"

transmission.addFile('path', options, function(err, arg){});

transmission.addUrl(url, callback)

Add torrents to transmission-daemon.

transmission.addUrl('url', function(err, arg){});

OR

The options object would be the arguments passed to transmission. If you want to set the download directory of the torrent you would pass in "download-dir":"/my/path"

transmission.addUrl('url', options, function(err, arg){});

transmission.remove(ids, del, callback)

Remove torrents.

Remove also local data when del is true.

transmission.remove(ids, function(err, arg){});

transmission.active(callback)

List of active torrents. Callback is not needed and will fire the active event.

transmission.active(function(err, arg){});

transmission.get([ids], callback)

Get torrents info that optional ids.

If omit ids, get all torrents.

transmission.get(ids, function(err, arg){
  if err
    console.error err
  else{
    for torrent in arg.torrents
      console.log arg.torrents
   }
});

# Get all torrents and remove it if status is stopped.
transmission.get(function(err, arg){
  if err
    console.error err
  else{
    for torrent in arg.torrents
      if torrent.status is transmission.status.STOPPED
        transmission.remove ([torrent.id], function (err){
          console.error err if err
        });
  }
});

transmission.stop(ids, callback)

Stop working torrents.

transmission.stop(ids, function(err, arg){});

transmission.start(ids, callback)

Start working torrents.

transmission.start(ids, function(err, arg){});

transmission.startNow(ids, callback)

Bypass the download queue, start working torrents immediately.

transmission.startNow(ids, function(err, arg){});

transmission.verify(ids, callback)

Verify torrent data.

transmission.verify(ids,function(err, arg){});

transmission.reannounce(ids, callback)

Reannounce to the tracker, ask for more peers.

transmission.reannounce(ids, function(err, arg){});

transmission.session(callback)

Get client session infomation.

transmission.session (function(err, arg){});

transmission.session({}, callback)

Set session infomation.

transmission.session({'download-dir':'/my/path'}, function(err, arg){});

transmission.sessionStats(callback)

Get client session stats.

transmission.sessionStats(function(err, arg){});

All together.

'use strict';

var Transmission = require('transmission');
var transmission = new Transmission({
    port: 9091,         // DEFAULT : 9091
    host: 192.168.1.34,         // DEAFULT : 127.0.0.1
    username: 'username',   // DEFAULT : BLANK
    password: 'password'    // DEFAULT : BLANK
});

// Get details of all torrents currently queued in transmission app
function getTransmissionStats(){
    transmission.sessionStats(function(err, result){
        if(err){
            console.log(err);
        } else {
            console.log(result);
        }
    });
}

// Add a torrent by passing a URL to .torrent file or a magnet link
function addTorrent(url){
    transmission.addUrl(url, {
        "download-dir" : "~/transmission/torrents"
    }, function(err, result) {
        if (err) {
            return console.log(err);
        }
        var id = result.id;
        console.log('Just added a new torrent.');
        console.log('Torrent ID: ' + id);
    });
}

// Get various stats about a torrent in the queue
function getTorrentDetails(id) {
    transmission.get(id, function(err, result) {
        if (err) {
            throw err;
        }
        if(result.torrents.length > 0){
            // console.log(result.torrents[0]);         // Gets all details
            console.log("Name = "+ result.torrents[0].name);
            console.log("Download Rate = "+ result.torrents[0].rateDownload/1000);
            console.log("Upload Rate = "+ result.torrents[0].rateUpload/1000);
            console.log("Completed = "+ result.torrents[0].percentDone*100);
            console.log("ETA = "+ result.torrents[0].eta/3600);
            console.log("Status = "+ getStatusType(result.torrents[0].status));
        }
    });
}

function deleteTorrent(id){
    transmission.remove(id, true, function(err, result){
        if (err){
            console.log(err);
        } else {
            console.log(result);// Read this output to get more details which can be accessed as shown below.
            // Extra details
            console.log('bt.get returned ' + result.torrents.length + ' torrents');
            result.torrents.forEach(function(torrent) {
                console.log('hashString', torrent.hashString)
            });
            removeTorrent(id);
        }
    });
}

// To start a paused / stopped torrent which is still in queue
function startTorrent(id){
    transmission.start(id, function(err, result){});
}

// To get list of all torrents currently in queue (downloading + paused)
// NOTE : This may return null if all torrents are in paused state 
function getAllActiveTorrents(){
    transmission.active(function(err, result){
    if (err){
        console.log(err);
    }
    else {
        for (var i=0; i< result.torrents.length; i++){
            console.log(result.torrents[i].id);
            console.log(result.torrents[i].name);
        }
    }
    });
}

// Pause / Stop a torrent
function stopTorrent(id){
    transmission.stop(id, function(err, result){});
}

// Pause / Stop all torrent
function stopAllActiveTorrents(){
    transmission.active(function(err, result){
    if (err){
        console.log(err);
    }
    else {
        for (var i=0; i< result.torrents.length; i++){
            stopTorrents(result.torrents[i].id);
        }
    }
    });
}

// Remove a torrent from download queue
// NOTE : This does not trash torrent data i.e. does not remove it from disk
function removeTorrent(id) {
    transmission.remove(id, function(err) {
        if (err) {
            throw err;
        }
        console.log('torrent was removed');
    });
}

// Get torrent state
function getStatusType(type){
    if(type === 0){
        return 'STOPPED';
    } else if(type === 1){
        return 'CHECK_WAIT';
    } else if(type === 2){
        return 'CHECK';
    } else if(type === 3){
        return 'DOWNLOAD_WAIT';
    } else if(type === 4){
        return 'DOWNLOAD';
    } else if(type === 5){
        return 'SEED_WAIT';
    } else if(type === 6){
        return 'SEED';
    } else if(type === 7){
        return 'ISOLATED';
    }
}
Something went wrong with that request. Please try again.