X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FWebService%2FStrike%2FTorrent.pm;h=eae9a89c5e277438a1d16a8026d8f877afc9e19d;hb=5b506549c8953f3fd781b66a0ef3f61a07a43503;hp=82179fba3f57e4432737bc36af9f2810ada9b6c4;hpb=9373f0ade1d99182c2ef4205a94e2e054903cb0c;p=webservice-strike.git diff --git a/lib/WebService/Strike/Torrent.pm b/lib/WebService/Strike/Torrent.pm index 82179fb..eae9a89 100644 --- a/lib/WebService/Strike/Torrent.pm +++ b/lib/WebService/Strike/Torrent.pm @@ -5,14 +5,14 @@ use strict; use warnings; use parent qw/Class::Accessor::Fast/; -our $VERSION = '0.001002'; +our $VERSION = '0.004001'; use Date::Parse qw/str2time/; use JSON::MaybeXS qw/decode_json/; -use URI::Escape qw/uri_escape/; +use MIME::Base64; use WebService::Strike; -__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/); +__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 magnet_uri imdb_id/); BEGIN { *hash = *torrent_hash; @@ -23,6 +23,7 @@ BEGIN { *uploader = *uploader_username; *names = *file_names; *lengths = *file_lengths; + *magnet = *magnet_uri; }; sub new{ @@ -31,20 +32,15 @@ sub new{ $self->{torrent_hash} = uc $self->hash; $self->{upload_date} = str2time $self->date, 'UTC'; if ($self->file_info) { - $self->{file_names} = $self->file_info->[0]->{file_names}; - $self->{file_lengths} = $self->file_info->[0]->{file_lengths}; + $self->{file_names} = $self->file_info->{file_names}; + $self->{file_lengths} = $self->file_info->{file_lengths}; } $self } -sub magnet{ - my ($self) = @_; - 'magnet:?xt=urn:btih:' . $self->hash . '&dn=' . uri_escape $self->title -} - sub torrent{ my ($self, $file) = @_; - my $url = $WebService::Strike::BASE_URL . '/downloads/?hash=' . $self->hash; + my $url = $WebService::Strike::BASE_URL . '/torrents/download/?hash=' . $self->hash; my $ht = WebService::Strike::_ht(); ## no critic (ProtectPrivate) my $response = $ht->get($url); return unless $response->{success}; @@ -60,6 +56,22 @@ sub torrent{ } } +sub description{ + my ($self) = @_; + return $self->{description} if $self->{description}; + my $url = $WebService::Strike::BASE_URL . '/torrents/descriptions/?hash=' . $self->hash; + my $ht = WebService::Strike::_ht(); ## no critic (ProtectPrivate) + my $response = $ht->get($url); + return unless $response->{success}; + $self->{description} = decode_base64 $response->{content} +} + +sub imdb { + my ($self) = @_; + return unless $self->imdb_id; + $self->{imdb} //= WebService::Strike::strike_imdb ($self->imdb_id) +} + 1; __END__ @@ -80,7 +92,7 @@ WebService::Strike::Torrent - Class representing information about a torrent say $t->seeds; say $t->leeches; say $t->count; # 1 - say $t->size; # 587 MB + say $t->size; # 615514112 say $t->date; # 1420502400 say $t->uploader; # The_Doctor- say @{$t->names}; # archlinux-2015.01.01-dual.iso @@ -88,6 +100,14 @@ WebService::Strike::Torrent - Class representing information about a torrent say $t->magnet; # magnet:?xt=urn:btih:B425907E5755031BDA4A8D1B6DCCACA97DA14C04&dn=Arch%20Linux%202015.01.01%20%28x86%2Fx64%29 my $tor = $t->torrent; # $torrent contains the torrent file contents $t->torrent('x.torrent'); # Download torrent file to x.torrent + say $t->description; # + + $t = strike 'ED70C185E3E3246F30B2FDB08D504EABED5EEA3F'; + say $t->title; # The Walking Dead S04E15 HDTV x264-2HD + say $t->imdb_id; # tt1520211 + my $i = $t->imdb; + say $i->{title}, ' (', $i->{year}, ')'; # The Walking Dead (2010) + say $i->{genre}; # Drama, Horror, Thriller =head1 DESCRIPTION @@ -128,8 +148,7 @@ The number of files contained in the torrent. =item B -The total size of the files in the torrent as a human-readable string. -See B for exact sizes. +The total size of the files in the torrent in bytes. =item B, B @@ -147,7 +166,7 @@ Arrayref of paths of files in the torrent. Arrayref of lengths of files in the torrent, in bytes. -=item B +=item B, B Magnet link for the torrent. @@ -159,11 +178,26 @@ I<$filename>. Both forms return a true value for success and false for failure. +=item B + +The description of the torrent. This method sends an extra request to +Strike. Successful responses are cached. + +=item B + +The IMDB ID of the torrent, or undef if the torrent has no associated +IMDB ID. + +=item B + +Calls B from L on B. Caches +the response. Returns undef if the torrent has no associated IMDB ID. + =back =head1 SEE ALSO -L, L +L, L =head1 AUTHOR