transmission-daemon wrapper script written in node.js
npm install transmission
Transmission = require 'transmission'
transmission = new Transmission
host: 'localhost' # default 'localhost'
port: 9091 # default 9091
username: 'hoge' # default blank
password: 'fuga' # default blank
url: '/my/other/url' # default '/transmission/rpc'
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
Set torrent's properties.
transmission.set [1, 6], options, (err) ->
You must provide one or more ids. According to the rpc-spec, transmission will not respond a success argument. Only error.
Add torrents to transmission-daemon.
transmission.addFile 'path', (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, (err, arg) ->
Add torrents to transmission-daemon.
transmission.addUrl 'url', (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, (err, arg) ->
Remove torrents.
Remove also local data when del
is true
.
transmission.remove [1, 7], true, (err, arg) ->
List of active torrents. Callback is not needed and will fire the active
event.
transmission.active (err, arg) ->
Get torrents info that optional ids
.
If omit ids
, get all torrents.
# Get torrents with id #1 and #7
transmission.get [1, 7], (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 (err, arg) ->
if err
console.error err
else
for torrent in arg.torrents
if torrent.status is transmission.status.STOPPED
transmission.remove [torrent.id], (err) ->
console.error err if err
Stop working torrents.
transmission.stop [1, 7], (err, arg) ->
Start working torrents.
transmission.start [1, 7], (err, arg) ->
Bypass the download queue, start working torrents immediately.
transmission.startNow [1, 7], (err, arg) ->
Verify torrent data.
transmission.verify [1, 7], (err, arg) ->
Reannounce to the tracker, ask for more peers.
transmission.reannounce [1, 7], (err, arg) ->
Get client session infomation.
transmission.session (err, arg) ->
Set session infomation.
transmission.session {'download-dir':'/my/path'}, (err, arg) ->
Get client session stats.
transmission.sessionStats (err, arg) ->
var Transmission = require('./')
var transmission = new Transmission({
port : 9091,
host : '127.0.0.1'
})
function getTorrent(id) {
transmission.get(id, function(err, result) {
if (err) {
throw err
}
console.log('bt.get returned ' + result.torrents.length + ' torrents')
result.torrents.forEach(function(torrent) {
console.log('hashString', torrent.hashString)
})
removeTorrent(id)
})
}
function removeTorrent(id) {
transmission.remove(id, function(err) {
if (err) {
throw err
}
console.log('torrent was removed')
})
}
transmission.addUrl('http://cdimage.debian.org/debian-cd/7.1.0/i386/bt-cd/debian-7.1.0-i386-netinst.iso.torrent', {
"download-dir" : "/home/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)
getTorrent(id)
})