File Coverage

blib/lib/WebService/Strike/Torrent.pm
Criterion Covered Total %
statement 50 54 92.5
branch 5 10 50.0
condition 0 6 0.0
subroutine 12 14 85.7
pod 5 5 100.0
total 72 89 80.9


line stmt bran cond sub pod time code
1             package WebService::Strike::Torrent;
2              
3 2     2   22156 use 5.014000;
  2         7  
4 2     2   10 use strict;
  2         3  
  2         53  
5 2     2   8 use warnings;
  2         4  
  2         61  
6 2     2   767 use parent qw/Class::Accessor::Fast/;
  2         314  
  2         11  
7              
8             our $VERSION = 0.005;
9              
10 2     2   17559 use JSON::MaybeXS qw/decode_json/;
  2         104304  
  2         161  
11 2     2   2059 use MIME::Base64;
  2         1865  
  2         162  
12 2     2   2010 use URI::Escape;
  2         5473  
  2         162  
13 2     2   684 use WebService::Strike;
  2         5  
  2         307  
14              
15             __PACKAGE__->mk_ro_accessors(qw/torrent_hash torrent_title torrent_category sub_category seeds leeches file_count size upload_date uploader_username file_info file_names file_lengths imdb_id/);
16              
17             BEGIN {
18 2     2   7 *hash = *torrent_hash;
19 2         4 *title = *torrent_title;
20 2         5 *category = *torrent_category;
21 2         2 *count = *file_count;
22 2         4 *date = *upload_date;
23 2         4 *uploader = *uploader_username;
24 2         4 *names = *file_names;
25 2         740 *lengths = *file_lengths;
26             };
27              
28             sub magnet{
29 1     1 1 5264 my ($self) = @_;
30 1         6 my $hash = uri_escape $self->hash; # uri_escape is not exactly needed here
31 1         46 my $title = uri_escape $self->title;
32 1         48 "magnet:?xt=urn:btih:$hash&dn=$title"
33             }
34              
35             sub new{
36 104     104 1 286 my ($self, @args) = @_;
37 104         392 $self = $self->SUPER::new(@args);
38 104         2332 $self->{torrent_hash} = uc $self->hash;
39 104 100       945 if ($self->file_info) {
40 4         50 $self->{file_names} = $self->file_info->{file_names};
41 4         35 $self->{file_lengths} = $self->file_info->{file_lengths};
42             }
43 104 50       833 $self->{imdb_id} = $self->{imdbid} if $self->{imdbid};
44 104         472 $self
45             }
46              
47             sub torrent{
48 0     0 1 0 die "This API call was removed in Strike API V2.1\n"
49             }
50              
51             sub description{
52 1     1 1 5119 my ($self) = @_;
53 1 50       5 return $self->{description} if $self->{description};
54 1         7 my $url = $WebService::Strike::BASE_URL . '/torrents/descriptions/?hash=' . $self->hash;
55 1         10 my $ht = WebService::Strike::_ht(); ## no critic (ProtectPrivate)
56 1         104 my $response = $ht->get($url);
57 1 50       175463 return unless $response->{success};
58             $self->{description} = decode_base64 $response->{content}
59 1         48 }
60              
61             sub imdb {
62 0     0 1   my ($self) = @_;
63 0 0 0       return if !$self->imdb_id || $self->imdb_id eq 'none';
64 0   0       $self->{imdb} //= WebService::Strike::strike_imdb ($self->imdb_id)
65             }
66              
67             1;
68             __END__