This file is indexed.

/usr/share/perl5/Transmission/Torrent.pm is in libtransmission-client-perl 0.0805-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
# ex:ts=4:sw=4:sts=4:et
package Transmission::Torrent;
# See Transmission::Client for copyright statement.

=head1 NAME

Transmission::Torrent - Transmission torrent object

=head1 DESCRIPTION

See "3.2 Torrent Mutators" and "3.3 Torrent accessors" from
L<https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt>

This class handles data related to a torrent known to Transmission.

=head1 SEE ALSO

L<Transmission::AttributeRole>

=cut

use Moose;
use List::MoreUtils qw(uniq);
use Transmission::Torrent::File;
use Transmission::Types ':all';

BEGIN {
    with 'Transmission::AttributeRole';
}

=head1 ATTRIBUTES

=head2 id

 $id = $self->id;

Returns the id that identifies this torrent in transmission.

=cut

has id => (
    is => 'ro',
    isa => 'Int',
    writer => '_set_id',
    required => 1,
);

=head2 bandwidth_priority

 $self->bandwidth_priority($num);

This torrent's bandwidth.

=head2 download_limit

 $self->download_limit($num);

Maximum download speed (in K/s).

=head2 download_limited

 $self->download_limited($bool);

True if "downloadLimit" is honored.

=head2 honors_session_limits

 $self->honors_session_limits($bool);

True if session upload limits are honored.

=head2 location

 $self->location($str);

New location of the torrent's content

=head2 peer_limit

 $self->peer_limit($num);

Maximum number of peers

=head2 seed_ratio_limit

 $self->seed_ratio_limit($num);

Session seeding ratio.

=head2 seed_ratio_mode

 $self->seed_ratio_mode($num);

Which ratio to use. See tr_ratiolimit.

=head2 upload_limit

 $self->upload_limit($num);

Maximum upload speed (in K/s)

=head2 upload_limited

 $self->upload_limited($bool);

True if "upload_limit" is honored

=head2 activity_date

 $num = $self->activity_date;

=head2 added_date

 $num = $self->added_date;

=head2 bandwidth_priority

 $num = $self->bandwidth_priority;

=head2 comment

 $str = $self->comment;

=head2 corrupt_ever

 $num = $self->corrupt_ever;

=head2 creator

 $str = $self->creator;

=head2 date_created

 $num = $self->date_created;

=head2 desired_available

 $num = $self->desired_available;

=head2 done_date

 $num = $self->done_date;

=head2 download_dir

 $str = $self->download_dir;

=head2 downloaded_ever

 $num = $self->downloaded_ever;

=head2 downloaders

 $num = $self->downloaders;

=head2 download_limit

 $num = $self->download_limit;

=head2 download_limited

 $bool = $self->download_limited;

=head2 error

 $num = $self->error;

=head2 error_string

 $str = $self->error_string;

=head2 eta

 $num = $self->eta;

=head2 hash_str

 $str = $self->hash_string;

=head2 have_unchecked

 $num = $self->have_unchecked;

=head2 have_valid

 $num = $self->have_valid;

=head2 honors_session_limits

 $bool = $self->honors_session_limits;

=head2 is_private

 $bool = $self->is_private;

=head2 leechers

 $num = $self->leechers;

=head2 left_until_done

 $num = $self->left_until_done;

=head2 manual_announce_time

 $num = $self->manual_announce_time;

=head2 max_connected_peers

 $num = $self->max_connected_peers;

=head2 name

 $str = $self->name;

=head2 peer

 $num = $self->peer;

=head2 peers_connected

 $num = $self->peers_connected;

=head2 peers_getting_from_us

 $num = $self->peers_getting_from_us;

=head2 peers_known

 $num = $self->peers_known;

=head2 peers_sending_to_us

 $num = $self->peers_sending_to_us;

=head2 percent_done

 $num = $self->percent_done;

=head2 pieces

 $str = $self->pieces;

=head2 piece_count

 $num = $self->piece_count;

=head2 piece_size

 $num = $self->piece_size;

=head2 rate_download

 $num = $self->rate_download;

=head2 rate_upload

 $num = $self->rate_upload;

=head2 recheck_progress

 $num = $self->recheck_progress;

=head2 seeders

 $num = $self->seeders;

=head2 seed_ratio_limit

 $num = $self->seed_ratio_limit;

=head2 seed_ratio_mode

 $num = $self->seed_ratio_mode;

=head2 size_when_done

 $num = $self->size_when_done;

=head2 start_date

 $num = $self->start_date;

=head2 status

 $str = $self->status;

=head2 swarm_speed

 $num = $self->swarm_speed;

=head2 times_completed

 $num = $self->times_completed;

=head2 total_size

 $num = $self->total_size;

=head2 torrent_file

 $str = $self->torrent_file;

=head2 uploaded_ever

 $num = $self->uploaded_ever;

=head2 upload_limit

 $num = $self->upload_limit;

=head2 upload_limited

 $bool = $self->upload_limited;

=head2 upload_ratio

 $num = $self->upload_ratio;

=head2 webseeds_sending_to_us

 $num = $self->webseeds_sending_to_us;

=cut

BEGIN {
    my $create_setter = sub {
        my $camel = $_[0];

        return sub {
            return if($_[0]->lazy_write);
            $_[0]->client->rpc('torrent-set' =>
                ids => [ $_[0]->id ], $camel => $_[1],
            );
        };
    };

    my $create_getter = sub {
        my $camel = $_[0];

        return sub {
            my $data = $_[0]->client->rpc('torrent-get' =>
                            ids => [ $_[0]->id ],
                            fields => [ $camel ],
                        );

            return unless($data);
            return $data->{'torrents'}[0]{$camel};
        };
    };

    my %SET = (
        #'files-wanted'          => array,
        #'files-unwanted'        => array,
        'location'              => string,
        'peer-limit'            => number,
        #'priority-high'         => array,
        #'priority-low'          => array,
        #'priority-normal'       => array,
    );
    our %BOTH = ( # meant for internal usage
        bandwidthPriority     => number,
        downloadLimit         => number,
        downloadLimited       => boolean,
        honorsSessionLimits   => boolean,
        seedRatioLimit        => double,
        seedRatioMode         => number,
        uploadLimit           => number,
        uploadLimited         => boolean,
    );
    our %READ = ( # meant for internal usage
        activityDate                => number,
        addedDate                   => number,
        comment                     => string,
        corruptEver                 => number,
        creator                     => string,
        dateCreated                 => number,
        desiredAvailable            => number,
        doneDate                    => number,
        downloadDir                 => string,
        downloadedEver              => number,
        downloaders                 => number,
        error                       => number,
        errorString                 => string,
        eta                         => number,
        hashString                  => string,
        haveUnchecked               => number,
        haveValid                   => number,
        isPrivate                   => boolean,
        leechers                    => number,
        leftUntilDone               => number,
        manualAnnounceTime          => number,
        maxConnectedPeers           => number,
        name                        => string,
        peersConnected              => number,
        peersGettingFromUs          => number,
        peersKnown                  => number,
        peersSendingToUs            => number,
        percentDone                 => double,
        pieceCount                  => number,
        pieceSize                   => number,
        rateDownload                => number,
        rateUpload                  => number,
        recheckProgress             => double,
        seeders                     => number,
        sizeWhenDone                => number,
        startDate                   => number,
        status                      => string,
        swarmSpeed                  => number,
        timesCompleted              => number,
        totalSize                   => number,
        torrentFile                 => string,
        uploadedEver                => number,
        uploadRatio                 => double,
        webseedsSendingToUs         => number,
    );
        #peers                       => array,
        #peersFrom                   => object,
        #pieces                      => string,
        #priorities                  => array,
        #trackers                    => array,
        #trackerStats                => array,
        #wanted                      => array,
        #webseeds                    => array,

    for my $camel (keys %SET) {
        my $name = __PACKAGE__->_camel2Normal($camel);
        my $setter = $create_setter->($camel);

        __PACKAGE__->meta->add_method("write_$name" => $setter);

        has $name => (
            is => 'rw',
            isa => $SET{$camel},
            coerce => 1,
            trigger => $setter,
        );
    }

    for my $camel (keys %BOTH) {
        my $name = __PACKAGE__->_camel2Normal($camel);
        my $setter = $create_setter->($camel);
        my $getter = $create_getter->($camel);

        __PACKAGE__->meta->add_method("write_$name" => $setter);

        has $name => (
            is => 'rw',
            isa => $BOTH{$camel},
            coerce => 1,
            lazy => 1,
            trigger => $setter,
            default => $getter,
        );
    }

    for my $camel (keys %READ) {
        my $name = __PACKAGE__->_camel2Normal($camel);
        my $getter = $create_getter->($camel);

        has $name => (
            is => 'ro',
            isa => $READ{$camel},
            coerce => 1,
            writer => "_set_$name",
            lazy => 1,
            default => $getter,
        );
    }

    __PACKAGE__->meta->add_method(read => sub {
        my $self = shift;
        my @fields = uniq(@_, 'id'); # id should always be requested
        my $lazy = $self->lazy_write;
        my $data;

        $data = $self->client->rpc('torrent-get' =>
                    ids => [ $self->id ],
                    fields => [ @fields ],
                ) or return;

        $data = $data->{'torrents'}[0] or return;

        # prevent from fireing off trigger in attributes
        $self->lazy_write(1);

        for my $camel (keys %$data) {
            my $name = __PACKAGE__->_camel2Normal($camel);
            my $writer = $READ{$camel} ? "_set_$name" : $name;

            $self->$writer($data->{$camel});
        }

        # reset lazy_write
        $self->lazy_write($lazy);

        return 1;
    });

    __PACKAGE__->meta->add_method(read_all => sub {
        my $self = shift;
        return $self->read(keys %BOTH, keys %READ);
    });

    $READ{'id'} = 'Int'; # this is required to be read
}

=head2 files

 $array_ref = $self->files;
 $self->clear_files;

Returns an array of L<Transmission::Torrent::File>s.

=cut

has files => (
    is => 'ro',
    isa => 'ArrayRef',
    lazy_build => 1,
);

sub _build_files {
    my $self = shift;
    my $files = [];
    my $stats = [];
    my $id = 0;
    my $data;

    $data = $self->client->rpc('torrent-get' =>
                ids => [ $self->id ],
                fields => [ qw/ files fileStats / ],
            );

    return [] unless($data);

    $files = $data->{'torrents'}[0]{'files'};
    $stats = $data->{'torrents'}[0]{'fileStats'};

    # this has to be true: @$files == @$stats
    while(@$stats) {
        my $stats = shift @$stats or last;
        my $file = shift @$files;

        push @$files,
            Transmission::Torrent::File->new(id => $id, %$stats, %$file);

        $id++;
    }

    return $files;
}

=head1 METHODS

=head2 BUILDARGS

 $hash_ref = $self->BUILDARGS(\%args);

Convert keys in C<%args> from "CamelCase" to "camel_case".

=cut

sub BUILDARGS {
    my $self = shift;
    my $args = $self->SUPER::BUILDARGS(@_);

    $self->_camel2Normal($args);

    return $args;
}

=head2 read

 $bool = $self->read('id', 'name', 'eta');

This method will refresh all requested attributes in one RPC request, while
calling one and one attribute, results in one-and-one request.

=head2 read_all

 $bool = $self->read_all;

Similar to L</read>, but requests all attributes.

=head2 start

See L<Transmission::Client::start()>.

=head2 stop

See L<Transmission::Client::stop()>.

=head2 verify

See L<Transmission::Client::verify()>.

=cut

{
    for my $name (qw/ start stop verify /) {
        __PACKAGE__->meta->add_method($name => sub {
            $_[0]->client->$name(ids => $_[0]->id);
        });
    }
}

=head2 move

 $bool = $self->move($path);

Will move the torrent content to C<$path>.

=cut

sub move {
    my $self = shift;
    my $path = shift;

    unless($path) {
        $self->client_error("Required argument 'path' is missing");
        return;
    }

    return $self->client->move(
        ids => [$self->id],
        location => $path,
        move => 1,
    );
}

=head2 write_wanted

 $bool = $self->write_wanted;

Will write "wanted" information from L</files> to transmission.

=cut

sub write_wanted {
    my $self = shift;
    my %wanted = ( wanted => [], unwanted => [] );
    my $ok;

    for my $file (@{ $self->files }) {
        push @{ $wanted{ $file->wanted ? 'wanted' : 'unwanted' } }, $file->id;
    }

    for my $key (qw/wanted unwanted/) {
        # Transmission interpret an empty list to mean all files
        next unless @{$wanted{$key}};

        $self->client->rpc('torrent-set' =>
            ids => [ $self->id ], "files-$key" => $wanted{$key}
        ) or return;
    }

    return 1;
}

=head2 write_priority

 $bool = $self->write_priority;

Will write "priorty" information from L</files> to transmission.

=cut

sub write_priority {
    my $self = shift;
    my %priority = ( low => [], normal => [], high => [] );
    my %map = ( -1 => 'low', 0 => 'normal', 1 => 'high' );

    for my $file (@{ $self->files }) {
        my $key = $map{ $file->priority } || 'normal';
        push @{ $priority{$key} }, $file->id;
    }

    for my $key (qw/low normal high/) {
        $self->client->rpc('torrent-set' =>
            ids => [ $self->id ], "priority-$key" => $priority{$key}
        ) or return;
    }

    return 1;
}

=head1 LICENSE

=head1 AUTHOR

See L<Transmission::Client>.

=cut

1;