]>
iEval git - webservice-strike.git/blob - Strike/Torrent.pm
1 package WebService
::Strike
::Torrent
;
6 use parent qw
/Class::Accessor::Fast/;
10 use JSON
::MaybeXS qw
/decode_json/;
13 use WebService
::Strike
;
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/);
18 *hash
= *torrent_hash
;
19 *title
= *torrent_title
;
20 *category
= *torrent_category
;
23 *uploader
= *uploader_username
;
25 *lengths
= *file_lengths
;
30 my $hash = uri_escape
$self->hash; # uri_escape is not exactly needed here
31 my $title = uri_escape
$self->title;
32 "magnet:?xt=urn:btih:$hash&dn=$title"
36 my ($self, @args) = @_;
37 $self = $self->SUPER::new
(@args);
38 $self->{torrent_hash
} = uc $self->hash;
39 if ($self->file_info) {
40 $self->{file_names
} = $self->file_info->{file_names
};
41 $self->{file_lengths
} = $self->file_info->{file_lengths
};
43 $self->{imdb_id
} = $self->{imdbid
} if $self->{imdbid
};
48 die "This API call was removed in Strike API V2.1\n"
53 return $self->{description
} if $self->{description
};
54 my $url = $WebService::Strike
::BASE_URL
. '/torrents/descriptions/?hash=' . $self->hash;
55 my $ht = WebService
::Strike
::_ht
(); ## no critic (ProtectPrivate)
56 my $response = $ht->get($url);
57 return unless $response->{success
};
58 $self->{description
} = decode_base64
$response->{content
}
63 return if !$self->imdb_id || $self->imdb_id eq 'none';
64 $self->{imdb
} //= WebService
::Strike
::strike_imdb
($self->imdb_id)
74 WebService::Strike::Torrent - Class representing information about a torrent
78 use WebService::Strike;
79 my $t = strike 'B425907E5755031BDA4A8D1B6DCCACA97DA14C04';
80 say $t->hash; # B425907E5755031BDA4A8D1B6DCCACA97DA14C04
81 say $t->title; # Arch Linux 2015.01.01 (x86/x64)
82 say $t->category; # Applications
83 say $t->sub_category; # '' (empty string)
87 say $t->size; # 615514112
88 say $t->date; # 1420502400
89 say $t->uploader; # The_Doctor-
90 say @{$t->names}; # archlinux-2015.01.01-dual.iso
91 say @{$t->lengths}; # 615514112
92 say $t->magnet; # magnet:?xt=urn:btih:B425907E5755031BDA4A8D1B6DCCACA97DA14C04&dn=Arch%20Linux%202015.01.01%20%28x86%2Fx64%29
93 say $t->description; # <HTML fragment describing Arch Linux>
95 $t = strike 'ED70C185E3E3246F30B2FDB08D504EABED5EEA3F';
96 say $t->title; # The Walking Dead S04E15 HDTV x264-2HD
97 say $t->imdb_id; # tt1520211
99 say $i->{title}, ' (', $i->{year}, ')'; # The Walking Dead (2010)
100 say $i->{genre}; # Drama, Horror, Thriller
104 WebService::Strike::Torrent is a class that represents information
111 =item B<hash>, B<torrent_hash>
113 The info_hash of the torrent.
115 =item B<title>, B<torrent_title>
117 The title of the torrent.
119 =item B<category>, B<torrent_category>
121 The category of the torrent.
123 =item B<sub_category>
125 The subcategory of the torrent.
129 The number of seeders.
133 The number of leechers.
135 =item B<count>, B<file_count>
137 The number of files contained in the torrent.
141 The total size of the files in the torrent in bytes.
143 =item B<date>, B<upload_date>
145 Unix timestamp when the torrent was uploaded, with precision of one day.
147 =item B<uploader>, B<uploader_username>
149 Username of the user who uploaded the torrent.
153 Arrayref of paths of files in the torrent.
155 =item B<file_lengths>
157 Arrayref of lengths of files in the torrent, in bytes.
159 =item B<magnet>, B<magnet_uri>
161 Magnet link for the torrent.
163 =item B<torrent>([I<$filename>])
165 B<THIS METHOD WAS REMOVED IN STRIKE API V2.1>. Therefore, it simply
166 dies. Below is the previous documentation of the method.
168 Downloads the torrent from Strike. With no arguments, returns the
169 contents of the torrent file. With an argument, stores the torrent in
172 Both forms return a true value for success and false for failure.
176 The description of the torrent. This method sends an extra request to
177 Strike. Successful responses are cached.
181 The IMDB ID of the torrent, or undef if the torrent has no associated
186 Calls B<strike_imdb> from L<WebService::Strike> on B<imdb_id>. Caches
187 the response. Returns undef if the torrent has no associated IMDB ID.
193 L<WebService::Strike>, L<https://getstrike.net/api/>
197 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
199 =head1 COPYRIGHT AND LICENSE
201 Copyright (C) 2015-2016 by Marius Gavrilescu
203 This library is free software; you can redistribute it and/or modify
204 it under the same terms as Perl itself, either Perl version 5.20.2 or,
205 at your option, any later version of Perl 5 you may have available.
This page took 0.058753 seconds and 4 git commands to generate.