Class: Transmission
- Inherits:
-
Object
- Object
- Transmission
- Includes:
- Enumerable
- Defined in:
- ext/r_transmission.c,
lib/transmission.rb,
ext/r_transmission.c
Overview
Summary
The Transmission class represent a bittorrent session. You can use an instance of this class to open a torrent and start its downloading process.
Defined Under Namespace
Classes: DuplicateError, ParseError, Torrent, TorrentError, TransmissionError, UnsupportedError
Constant Summary collapse
- VERSION =
rb_obj_freeze(rb_str_new2(VERSION))
Class Method Summary collapse
-
.pref_directory ⇒ String
Returns the full path to a directory which can be used to store preferences.
Instance Method Summary collapse
-
#bind_port=(port) ⇒ Object
Sets a “starting” bind port.
-
#copy(path) ⇒ Object
Opens a torrent file at ‘path’ just as in Transmission#open, but creates an internal copy of it.
-
#download_limit=(limit) ⇒ Object
Sets download limit in Kb.
-
#each {|torrent| ... } ⇒ Object
Iterate through all opened torrents.
-
#size ⇒ Integer
Returns the count of open torrents.
-
#open(path) ⇒ Object
Opens and parses torrent file at ‘path’.
-
#open_saved(hash) ⇒ Object
Opens a previously saved torrent by its hash string.
-
#rates ⇒ Array
Returns total download and upload rates.
-
#size ⇒ Integer
Returns the count of open torrents.
-
#upload_limit=(limit) ⇒ Object
Sets upload limit in Kb.
Class Method Details
.pref_directory ⇒ String
Returns the full path to a directory which can be used to store preferences.
87 88 89 90 91 |
# File 'ext/r_transmission.c', line 87
static VALUE
r_transmission_pref_dir(VALUE self)
{
return rb_str_new2(tr_getPrefsDirectory());
}
|
Instance Method Details
#bind_port=(port) ⇒ Object
Sets a “starting” bind port. Everytime a torrent is started, the library tries to bind this port, then the next one and so on until it is successful.
101 102 103 104 105 106 107 108 109 |
# File 'ext/r_transmission.c', line 101
static VALUE
r_transmission_set_bind_port(VALUE self, VALUE port)
{
r_transmission_t *transmission;
Data_Get_Struct(self, r_transmission_t, transmission);
tr_setBindPort(transmission->handle, FIX2INT(port));
return port;
}
|
#copy(path) ⇒ Object
Opens a torrent file at ‘path’ just as in Transmission#open, but creates an internal copy of it. Later you can open this torrent with Transmission#open_saved by passing it Torrent#hash_string value.
9 10 11 |
# File 'lib/transmission.rb', line 9 def copy(path) open(path, true) end |
#download_limit=(limit) ⇒ Object
Sets download limit in Kb.
281 282 283 284 285 286 287 288 |
# File 'ext/r_transmission.c', line 281
static VALUE
r_transmission_set_download_limit(VALUE self, VALUE limit)
{
r_transmission_t *transmission;
Data_Get_Struct(self, r_transmission_t, transmission);
tr_setDownloadLimit(transmission->handle, FIX2INT(limit));
return limit;
}
|
#each {|torrent| ... } ⇒ Object
Iterate through all opened torrents.
233 234 235 236 237 238 239 240 241 |
# File 'ext/r_transmission.c', line 233
static VALUE
r_transmission_each(VALUE self)
{
r_transmission_t *transmission;
Data_Get_Struct(self, r_transmission_t, transmission);
tr_torrentIterate(transmission->handle, r_transmission_each_i, (void *)transmission);
return self;
}
|
#size ⇒ Integer
Returns the count of open torrents.
192 193 194 195 196 197 198 |
# File 'ext/r_transmission.c', line 192
static VALUE
r_transmission_size(VALUE self)
{
r_transmission_t *transmission;
Data_Get_Struct(self, r_transmission_t, transmission);
return INT2FIX(tr_torrentCount(transmission->handle));
}
|
#open(path) ⇒ Object
Opens and parses torrent file at ‘path’. If the file exists and is a valid torrent file, returns a Torrent instance and adds it to the list of torrents (but doesn’t start it).
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'ext/r_transmission.c', line 137
static VALUE
r_transmission_open(int argc, VALUE *argv, VALUE self)
{
VALUE file, save = Qnil, saved = Qnil, excp, result;
r_transmission_t *transmission;
tr_torrent_t *torrent_h;
r_torrent_t *torrent;
int flags = 0;
int error = 0;
rb_scan_args(argc, argv, "12", &file, &save, &saved);
if( RTEST(save) && !RTEST(saved))
flags = TR_FSAVEPRIVATE;
Data_Get_Struct(self, r_transmission_t, transmission);
torrent_h = RTEST(saved) ?
tr_torrentInitSaved(transmission->handle, StringValuePtr(file), flags, &error) :
tr_torrentInit(transmission->handle, StringValuePtr(file), flags, &error);
if(torrent_h == NULL) {
switch(error)
{
case TR_EINVALID:
excp = eParseError;
break;
case TR_EUNSUPPORTED:
excp = eUnsupportedError;
break;
case TR_EDUPLICATE:
excp = eDuplicateError;
case TR_EOTHER:
default:
excp = eTorrentError;
}
rb_raise(excp, "Failed to open torrent file");
}
torrent = ALLOC(r_torrent_t);
torrent->transmission = self;
torrent->handle = torrent_h;
torrent->flags = 0;
result = Data_Wrap_Struct(cTorrent, r_torrent_mark, r_torrent_free, torrent);
rb_ary_push(transmission->torrents, result);
if(r_torrent_get_folder(result) == Qnil)
r_torrent_set_folder(result, rb_str_new2("."));
return result;
}
|
#open_saved(hash) ⇒ Object
Opens a previously saved torrent by its hash string.
16 17 18 |
# File 'lib/transmission.rb', line 16 def open_saved(hash) open(hash, false, true) end |
#rates ⇒ Array
Returns total download and upload rates.
249 250 251 252 253 254 255 256 257 258 |
# File 'ext/r_transmission.c', line 249
static VALUE
r_transmission_rates(VALUE self)
{
r_transmission_t *transmission;
float down, up;
Data_Get_Struct(self, r_transmission_t, transmission);
tr_torrentRates(transmission->handle, &down, &up);
return rb_ary_new3(2, rb_float_new(down), rb_float_new(up));
}
|
#size ⇒ Integer
Returns the count of open torrents.
192 193 194 195 196 197 198 |
# File 'ext/r_transmission.c', line 192
static VALUE
r_transmission_size(VALUE self)
{
r_transmission_t *transmission;
Data_Get_Struct(self, r_transmission_t, transmission);
return INT2FIX(tr_torrentCount(transmission->handle));
}
|
#upload_limit=(limit) ⇒ Object
Sets upload limit in Kb.
266 267 268 269 270 271 272 273 |
# File 'ext/r_transmission.c', line 266
static VALUE
r_transmission_set_upload_limit(VALUE self, VALUE limit)
{
r_transmission_t *transmission;
Data_Get_Struct(self, r_transmission_t, transmission);
tr_setUploadLimit(transmission->handle, FIX2INT(limit));
return limit;
}
|