line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ex:ts=4:sw=4:sts=4:et |
2
|
|
|
|
|
|
|
package Transmission::Torrent; |
3
|
|
|
|
|
|
|
# See Transmission::Client for copyright statement. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Transmission::Torrent - Transmission torrent object |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 DESCRIPTION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
See "3.2 Torrent Mutators" and "3.3 Torrent accessors" from |
12
|
|
|
|
|
|
|
L<https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt> |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
This class handles data related to a torrent known to Transmission. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SEE ALSO |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
L<Transmission::AttributeRole> |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
|
80121
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use List::MoreUtils qw(uniq); |
24
|
|
|
|
|
|
|
use Transmission::Torrent::File; |
25
|
|
|
|
|
|
|
use Transmission::Types ':all'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
BEGIN { |
28
|
|
|
|
|
|
|
with 'Transmission::AttributeRole'; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 id |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$id = $self->id; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Returns the id that identifies this torrent in transmission. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has id => ( |
42
|
|
|
|
|
|
|
is => 'ro', |
43
|
|
|
|
|
|
|
isa => 'Int', |
44
|
|
|
|
|
|
|
writer => '_set_id', |
45
|
|
|
|
|
|
|
required => 1, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 bandwidth_priority |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$self->bandwidth_priority($num); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
This torrent's bandwidth. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 download_limit |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$self->download_limit($num); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Maximum download speed (in K/s). |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 download_limited |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$self->download_limited($bool); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
True if "downloadLimit" is honored. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 honors_session_limits |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$self->honors_session_limits($bool); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
True if session upload limits are honored. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 location |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$self->location($str); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
New location of the torrent's content |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 peer_limit |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$self->peer_limit($num); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Maximum number of peers |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 seed_ratio_limit |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$self->seed_ratio_limit($num); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Session seeding ratio. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 seed_ratio_mode |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$self->seed_ratio_mode($num); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Which ratio to use. See tr_ratiolimit. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 upload_limit |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$self->upload_limit($num); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Maximum upload speed (in K/s) |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 upload_limited |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
$self->upload_limited($bool); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
True if "upload_limit" is honored |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 activity_date |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
$num = $self->activity_date; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 added_date |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
$num = $self->added_date; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 bandwidth_priority |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
$num = $self->bandwidth_priority; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 comment |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
$str = $self->comment; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 corrupt_ever |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
$num = $self->corrupt_ever; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 creator |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
$str = $self->creator; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 date_created |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
$num = $self->date_created; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 desired_available |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
$num = $self->desired_available; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 done_date |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
$num = $self->done_date; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 download_dir |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
$str = $self->download_dir; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 downloaded_ever |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
$num = $self->downloaded_ever; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 downloaders |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
$num = $self->downloaders; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 download_limit |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
$num = $self->download_limit; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 download_limited |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
$bool = $self->download_limited; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 error |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
$num = $self->error; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 error_string |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
$str = $self->error_string; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 eta |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
$num = $self->eta; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 hash_str |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
$str = $self->hash_string; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 have_unchecked |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
$num = $self->have_unchecked; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 have_valid |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
$num = $self->have_valid; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head2 honors_session_limits |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
$bool = $self->honors_session_limits; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head2 is_private |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
$bool = $self->is_private; |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 leechers |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
$num = $self->leechers; |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head2 left_until_done |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
$num = $self->left_until_done; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 manual_announce_time |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
$num = $self->manual_announce_time; |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head2 max_connected_peers |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
$num = $self->max_connected_peers; |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head2 name |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
$str = $self->name; |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head2 peer |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
$num = $self->peer; |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head2 peers_connected |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
$num = $self->peers_connected; |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head2 peers_getting_from_us |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
$num = $self->peers_getting_from_us; |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head2 peers_known |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
$num = $self->peers_known; |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head2 peers_sending_to_us |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
$num = $self->peers_sending_to_us; |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head2 percent_done |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
$num = $self->percent_done; |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head2 pieces |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
$str = $self->pieces; |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head2 piece_count |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
$num = $self->piece_count; |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head2 piece_size |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
$num = $self->piece_size; |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head2 rate_download |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
$num = $self->rate_download; |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head2 rate_upload |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
$num = $self->rate_upload; |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head2 recheck_progress |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
$num = $self->recheck_progress; |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=head2 seeders |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
$num = $self->seeders; |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=head2 seed_ratio_limit |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
$num = $self->seed_ratio_limit; |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=head2 seed_ratio_mode |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
$num = $self->seed_ratio_mode; |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=head2 size_when_done |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
$num = $self->size_when_done; |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=head2 start_date |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
$num = $self->start_date; |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=head2 status |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
$str = $self->status; |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=head2 swarm_speed |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
$num = $self->swarm_speed; |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=head2 times_completed |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
$num = $self->times_completed; |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
=head2 total_size |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
$num = $self->total_size; |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=head2 torrent_file |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
$str = $self->torrent_file; |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=head2 uploaded_ever |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
$num = $self->uploaded_ever; |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
=head2 upload_limit |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
$num = $self->upload_limit; |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
=head2 upload_limited |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
$bool = $self->upload_limited; |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
=head2 upload_ratio |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
$num = $self->upload_ratio; |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
=head2 webseeds_sending_to_us |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
$num = $self->webseeds_sending_to_us; |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
=cut |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
BEGIN { |
327
|
|
|
|
|
|
|
my $create_setter = sub { |
328
|
|
|
|
|
|
|
my $camel = $_[0]; |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
return sub { |
331
|
|
|
|
|
|
|
return if($_[0]->lazy_write); |
332
|
|
|
|
|
|
|
$_[0]->client->rpc('torrent-set' => |
333
|
|
|
|
|
|
|
ids => [ $_[0]->id ], $camel => $_[1], |
334
|
|
|
|
|
|
|
); |
335
|
|
|
|
|
|
|
}; |
336
|
|
|
|
|
|
|
}; |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
my $create_getter = sub { |
339
|
|
|
|
|
|
|
my $camel = $_[0]; |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
return sub { |
342
|
|
|
|
|
|
|
my $data = $_[0]->client->rpc('torrent-get' => |
343
|
|
|
|
|
|
|
ids => [ $_[0]->id ], |
344
|
|
|
|
|
|
|
fields => [ $camel ], |
345
|
|
|
|
|
|
|
); |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
return unless($data); |
348
|
|
|
|
|
|
|
return $data->{'torrents'}[0]{$camel}; |
349
|
|
|
|
|
|
|
}; |
350
|
|
|
|
|
|
|
}; |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
my %SET = ( |
353
|
|
|
|
|
|
|
#'files-wanted' => array, |
354
|
|
|
|
|
|
|
#'files-unwanted' => array, |
355
|
|
|
|
|
|
|
'location' => string, |
356
|
|
|
|
|
|
|
'peer-limit' => number, |
357
|
|
|
|
|
|
|
#'priority-high' => array, |
358
|
|
|
|
|
|
|
#'priority-low' => array, |
359
|
|
|
|
|
|
|
#'priority-normal' => array, |
360
|
|
|
|
|
|
|
); |
361
|
|
|
|
|
|
|
our %BOTH = ( # meant for internal usage |
362
|
|
|
|
|
|
|
bandwidthPriority => number, |
363
|
|
|
|
|
|
|
downloadLimit => number, |
364
|
|
|
|
|
|
|
downloadLimited => boolean, |
365
|
|
|
|
|
|
|
honorsSessionLimits => boolean, |
366
|
|
|
|
|
|
|
seedRatioLimit => double, |
367
|
|
|
|
|
|
|
seedRatioMode => number, |
368
|
|
|
|
|
|
|
uploadLimit => number, |
369
|
|
|
|
|
|
|
uploadLimited => boolean, |
370
|
|
|
|
|
|
|
); |
371
|
|
|
|
|
|
|
our %READ = ( # meant for internal usage |
372
|
|
|
|
|
|
|
activityDate => number, |
373
|
|
|
|
|
|
|
addedDate => number, |
374
|
|
|
|
|
|
|
comment => string, |
375
|
|
|
|
|
|
|
corruptEver => number, |
376
|
|
|
|
|
|
|
creator => string, |
377
|
|
|
|
|
|
|
dateCreated => number, |
378
|
|
|
|
|
|
|
desiredAvailable => number, |
379
|
|
|
|
|
|
|
doneDate => number, |
380
|
|
|
|
|
|
|
downloadDir => string, |
381
|
|
|
|
|
|
|
downloadedEver => number, |
382
|
|
|
|
|
|
|
downloaders => number, |
383
|
|
|
|
|
|
|
error => number, |
384
|
|
|
|
|
|
|
errorString => string, |
385
|
|
|
|
|
|
|
eta => number, |
386
|
|
|
|
|
|
|
hashString => string, |
387
|
|
|
|
|
|
|
haveUnchecked => number, |
388
|
|
|
|
|
|
|
haveValid => number, |
389
|
|
|
|
|
|
|
isPrivate => boolean, |
390
|
|
|
|
|
|
|
leechers => number, |
391
|
|
|
|
|
|
|
leftUntilDone => number, |
392
|
|
|
|
|
|
|
manualAnnounceTime => number, |
393
|
|
|
|
|
|
|
maxConnectedPeers => number, |
394
|
|
|
|
|
|
|
name => string, |
395
|
|
|
|
|
|
|
peersConnected => number, |
396
|
|
|
|
|
|
|
peersGettingFromUs => number, |
397
|
|
|
|
|
|
|
peersKnown => number, |
398
|
|
|
|
|
|
|
peersSendingToUs => number, |
399
|
|
|
|
|
|
|
percentDone => double, |
400
|
|
|
|
|
|
|
pieceCount => number, |
401
|
|
|
|
|
|
|
pieceSize => number, |
402
|
|
|
|
|
|
|
rateDownload => number, |
403
|
|
|
|
|
|
|
rateUpload => number, |
404
|
|
|
|
|
|
|
recheckProgress => double, |
405
|
|
|
|
|
|
|
seeders => number, |
406
|
|
|
|
|
|
|
sizeWhenDone => number, |
407
|
|
|
|
|
|
|
startDate => number, |
408
|
|
|
|
|
|
|
status => string, |
409
|
|
|
|
|
|
|
swarmSpeed => number, |
410
|
|
|
|
|
|
|
timesCompleted => number, |
411
|
|
|
|
|
|
|
totalSize => number, |
412
|
|
|
|
|
|
|
torrentFile => string, |
413
|
|
|
|
|
|
|
uploadedEver => number, |
414
|
|
|
|
|
|
|
uploadRatio => double, |
415
|
|
|
|
|
|
|
webseedsSendingToUs => number, |
416
|
|
|
|
|
|
|
); |
417
|
|
|
|
|
|
|
#peers => array, |
418
|
|
|
|
|
|
|
#peersFrom => object, |
419
|
|
|
|
|
|
|
#pieces => string, |
420
|
|
|
|
|
|
|
#priorities => array, |
421
|
|
|
|
|
|
|
#trackers => array, |
422
|
|
|
|
|
|
|
#trackerStats => array, |
423
|
|
|
|
|
|
|
#wanted => array, |
424
|
|
|
|
|
|
|
#webseeds => array, |
425
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
for my $camel (keys %SET) { |
427
|
|
|
|
|
|
|
my $name = __PACKAGE__->_camel2Normal($camel); |
428
|
|
|
|
|
|
|
my $setter = $create_setter->($camel); |
429
|
|
|
|
|
|
|
|
430
|
|
|
|
|
|
|
__PACKAGE__->meta->add_method("write_$name" => $setter); |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
has $name => ( |
433
|
|
|
|
|
|
|
is => 'rw', |
434
|
|
|
|
|
|
|
isa => $SET{$camel}, |
435
|
|
|
|
|
|
|
coerce => 1, |
436
|
|
|
|
|
|
|
trigger => $setter, |
437
|
|
|
|
|
|
|
); |
438
|
|
|
|
|
|
|
} |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
for my $camel (keys %BOTH) { |
441
|
|
|
|
|
|
|
my $name = __PACKAGE__->_camel2Normal($camel); |
442
|
|
|
|
|
|
|
my $setter = $create_setter->($camel); |
443
|
|
|
|
|
|
|
my $getter = $create_getter->($camel); |
444
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
__PACKAGE__->meta->add_method("write_$name" => $setter); |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
has $name => ( |
448
|
|
|
|
|
|
|
is => 'rw', |
449
|
|
|
|
|
|
|
isa => $BOTH{$camel}, |
450
|
|
|
|
|
|
|
coerce => 1, |
451
|
|
|
|
|
|
|
lazy => 1, |
452
|
|
|
|
|
|
|
trigger => $setter, |
453
|
|
|
|
|
|
|
default => $getter, |
454
|
|
|
|
|
|
|
); |
455
|
|
|
|
|
|
|
} |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
for my $camel (keys %READ) { |
458
|
|
|
|
|
|
|
my $name = __PACKAGE__->_camel2Normal($camel); |
459
|
|
|
|
|
|
|
my $getter = $create_getter->($camel); |
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
has $name => ( |
462
|
|
|
|
|
|
|
is => 'ro', |
463
|
|
|
|
|
|
|
isa => $READ{$camel}, |
464
|
|
|
|
|
|
|
coerce => 1, |
465
|
|
|
|
|
|
|
writer => "_set_$name", |
466
|
|
|
|
|
|
|
lazy => 1, |
467
|
|
|
|
|
|
|
default => $getter, |
468
|
|
|
|
|
|
|
); |
469
|
|
|
|
|
|
|
} |
470
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
__PACKAGE__->meta->add_method(read => sub { |
472
|
|
|
|
|
|
|
my $self = shift; |
473
|
|
|
|
|
|
|
my @fields = uniq(@_, 'id'); # id should always be requested |
474
|
|
|
|
|
|
|
my $lazy = $self->lazy_write; |
475
|
|
|
|
|
|
|
my $data; |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
$data = $self->client->rpc('torrent-get' => |
478
|
|
|
|
|
|
|
ids => [ $self->id ], |
479
|
|
|
|
|
|
|
fields => [ @fields ], |
480
|
|
|
|
|
|
|
) or return; |
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
$data = $data->{'torrents'}[0] or return; |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
# prevent from fireing off trigger in attributes |
485
|
|
|
|
|
|
|
$self->lazy_write(1); |
486
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
for my $camel (keys %$data) { |
488
|
|
|
|
|
|
|
my $name = __PACKAGE__->_camel2Normal($camel); |
489
|
|
|
|
|
|
|
my $writer = $READ{$camel} ? "_set_$name" : $name; |
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
$self->$writer($data->{$camel}); |
492
|
|
|
|
|
|
|
} |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
# reset lazy_write |
495
|
|
|
|
|
|
|
$self->lazy_write($lazy); |
496
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
return 1; |
498
|
|
|
|
|
|
|
}); |
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
__PACKAGE__->meta->add_method(read_all => sub { |
501
|
|
|
|
|
|
|
my $self = shift; |
502
|
|
|
|
|
|
|
return $self->read(keys %BOTH, keys %READ); |
503
|
|
|
|
|
|
|
}); |
504
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
$READ{'id'} = 'Int'; # this is required to be read |
506
|
|
|
|
|
|
|
} |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
=head2 files |
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
$array_ref = $self->files; |
511
|
|
|
|
|
|
|
$self->clear_files; |
512
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
Returns an array of L<Transmission::Torrent::File>s. |
514
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
=cut |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
has files => ( |
518
|
|
|
|
|
|
|
is => 'ro', |
519
|
|
|
|
|
|
|
isa => 'ArrayRef', |
520
|
|
|
|
|
|
|
lazy_build => 1, |
521
|
|
|
|
|
|
|
); |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
sub _build_files { |
524
|
|
|
|
|
|
|
my $self = shift; |
525
|
|
|
|
|
|
|
my $files = []; |
526
|
|
|
|
|
|
|
my $stats = []; |
527
|
|
|
|
|
|
|
my $id = 0; |
528
|
|
|
|
|
|
|
my $data; |
529
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
$data = $self->client->rpc('torrent-get' => |
531
|
|
|
|
|
|
|
ids => [ $self->id ], |
532
|
|
|
|
|
|
|
fields => [ qw/ files fileStats / ], |
533
|
|
|
|
|
|
|
); |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
return [] unless($data); |
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
$files = $data->{'torrents'}[0]{'files'}; |
538
|
|
|
|
|
|
|
$stats = $data->{'torrents'}[0]{'fileStats'}; |
539
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
# this has to be true: @$files == @$stats |
541
|
|
|
|
|
|
|
while(@$stats) { |
542
|
|
|
|
|
|
|
my $stats = shift @$stats or last; |
543
|
|
|
|
|
|
|
my $file = shift @$files; |
544
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
push @$files, |
546
|
|
|
|
|
|
|
Transmission::Torrent::File->new(id => $id, %$stats, %$file); |
547
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
$id++; |
549
|
|
|
|
|
|
|
} |
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
return $files; |
552
|
|
|
|
|
|
|
} |
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
=head1 METHODS |
555
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
=head2 BUILDARGS |
557
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
$hash_ref = $self->BUILDARGS(\%args); |
559
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
Convert keys in C<%args> from "CamelCase" to "camel_case". |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
=cut |
563
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
sub BUILDARGS { |
565
|
|
|
|
|
|
|
my $self = shift; |
566
|
|
|
|
|
|
|
my $args = $self->SUPER::BUILDARGS(@_); |
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
$self->_camel2Normal($args); |
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
return $args; |
571
|
|
|
|
|
|
|
} |
572
|
|
|
|
|
|
|
|
573
|
|
|
|
|
|
|
=head2 read |
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
$bool = $self->read('id', 'name', 'eta'); |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
This method will refresh all requested attributes in one RPC request, while |
578
|
|
|
|
|
|
|
calling one and one attribute, results in one-and-one request. |
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
=head2 read_all |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
$bool = $self->read_all; |
583
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
Similar to L</read>, but requests all attributes. |
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
=head2 start |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
See L<Transmission::Client::start()>. |
589
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
=head2 stop |
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
See L<Transmission::Client::stop()>. |
593
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
=head2 verify |
595
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
See L<Transmission::Client::verify()>. |
597
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
=cut |
599
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
{ |
601
|
|
|
|
|
|
|
for my $name (qw/ start stop verify /) { |
602
|
|
|
|
|
|
|
__PACKAGE__->meta->add_method($name => sub { |
603
|
|
|
|
|
|
|
$_[0]->client->$name(ids => $_[0]->id); |
604
|
|
|
|
|
|
|
}); |
605
|
|
|
|
|
|
|
} |
606
|
|
|
|
|
|
|
} |
607
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
=head2 move |
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
$bool = $self->move($path); |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
Will move the torrent content to C<$path>. |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
=cut |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
sub move { |
617
|
|
|
|
|
|
|
my $self = shift; |
618
|
|
|
|
|
|
|
my $path = shift; |
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
unless($path) { |
621
|
|
|
|
|
|
|
$self->client_error("Required argument 'path' is missing"); |
622
|
|
|
|
|
|
|
return; |
623
|
|
|
|
|
|
|
} |
624
|
|
|
|
|
|
|
|
625
|
|
|
|
|
|
|
return $self->client->move( |
626
|
|
|
|
|
|
|
ids => [$self->id], |
627
|
|
|
|
|
|
|
location => $path, |
628
|
|
|
|
|
|
|
move => 1, |
629
|
|
|
|
|
|
|
); |
630
|
|
|
|
|
|
|
} |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
=head2 write_wanted |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
$bool = $self->write_wanted; |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
Will write "wanted" information from L</files> to transmission. |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
=cut |
639
|
|
|
|
|
|
|
|
640
|
|
|
|
|
|
|
sub write_wanted { |
641
|
|
|
|
|
|
|
my $self = shift; |
642
|
|
|
|
|
|
|
my %wanted = ( wanted => [], unwanted => [] ); |
643
|
|
|
|
|
|
|
my $ok; |
644
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
for my $file (@{ $self->files }) { |
646
|
|
|
|
|
|
|
push @{ $wanted{ $file->wanted ? 'wanted' : 'unwanted' } }, $file->id; |
647
|
|
|
|
|
|
|
} |
648
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
for my $key (qw/wanted unwanted/) { |
650
|
|
|
|
|
|
|
# Transmission interpret an empty list to mean all files |
651
|
|
|
|
|
|
|
next unless @{$wanted{$key}}; |
652
|
|
|
|
|
|
|
|
653
|
|
|
|
|
|
|
$self->client->rpc('torrent-set' => |
654
|
|
|
|
|
|
|
ids => [ $self->id ], "files-$key" => $wanted{$key} |
655
|
|
|
|
|
|
|
) or return; |
656
|
|
|
|
|
|
|
} |
657
|
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
return 1; |
659
|
|
|
|
|
|
|
} |
660
|
|
|
|
|
|
|
|
661
|
|
|
|
|
|
|
=head2 write_priority |
662
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
$bool = $self->write_priority; |
664
|
|
|
|
|
|
|
|
665
|
|
|
|
|
|
|
Will write "priorty" information from L</files> to transmission. |
666
|
|
|
|
|
|
|
|
667
|
|
|
|
|
|
|
=cut |
668
|
|
|
|
|
|
|
|
669
|
|
|
|
|
|
|
sub write_priority { |
670
|
|
|
|
|
|
|
my $self = shift; |
671
|
|
|
|
|
|
|
my %priority = ( low => [], normal => [], high => [] ); |
672
|
|
|
|
|
|
|
my %map = ( -1 => 'low', 0 => 'normal', 1 => 'high' ); |
673
|
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
for my $file (@{ $self->files }) { |
675
|
|
|
|
|
|
|
my $key = $map{ $file->priority } || 'normal'; |
676
|
|
|
|
|
|
|
push @{ $priority{$key} }, $file->id; |
677
|
|
|
|
|
|
|
} |
678
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
for my $key (qw/low normal high/) { |
680
|
|
|
|
|
|
|
$self->client->rpc('torrent-set' => |
681
|
|
|
|
|
|
|
ids => [ $self->id ], "priority-$key" => $priority{$key} |
682
|
|
|
|
|
|
|
) or return; |
683
|
|
|
|
|
|
|
} |
684
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
return 1; |
686
|
|
|
|
|
|
|
} |
687
|
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
=head1 LICENSE |
689
|
|
|
|
|
|
|
|
690
|
|
|
|
|
|
|
=head1 AUTHOR |
691
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
See L<Transmission::Client>. |
693
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
=cut |
695
|
|
|
|
|
|
|
|
696
|
|
|
|
|
|
|
1; |