X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FWebService%2FStrike%2FTorrent.pm;h=7dc1d0b295ec169f48e741485f0f393a0a12a8eb;hb=9597641fbbde773352ac497d3bb0948dba18e936;hp=1f0dae5e359b9c883dc31fba5738a4b43fc8ced5;hpb=95b1c120488fa6a756ab596060099f85921dae73;p=webservice-strike.git diff --git a/lib/WebService/Strike/Torrent.pm b/lib/WebService/Strike/Torrent.pm index 1f0dae5..7dc1d0b 100644 --- a/lib/WebService/Strike/Torrent.pm +++ b/lib/WebService/Strike/Torrent.pm @@ -5,13 +5,14 @@ use strict; use warnings; use parent qw/Class::Accessor::Fast/; -our $VERSION = '0.002'; +our $VERSION = 0.006; -use Date::Parse qw/str2time/; use JSON::MaybeXS qw/decode_json/; +use MIME::Base64; +use URI::Escape; 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 magnet_uri/); +__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/); BEGIN { *hash = *torrent_hash; @@ -22,37 +23,45 @@ BEGIN { *uploader = *uploader_username; *names = *file_names; *lengths = *file_lengths; - *magnet = *magnet_uri; }; +sub magnet{ + my ($self) = @_; + my $hash = uri_escape $self->hash; # uri_escape is not exactly needed here + my $title = uri_escape $self->title; + "magnet:?xt=urn:btih:$hash&dn=$title" +} + sub new{ my ($self, @args) = @_; $self = $self->SUPER::new(@args); $self->{torrent_hash} = uc $self->hash; - $self->{upload_date} = str2time $self->date, 'UTC'; if ($self->file_info) { $self->{file_names} = $self->file_info->{file_names}; $self->{file_lengths} = $self->file_info->{file_lengths}; } + $self->{imdb_id} = $self->{imdbid} if $self->{imdbid}; $self } sub torrent{ - my ($self, $file) = @_; - my $url = $WebService::Strike::BASE_URL . '/download/?hash=' . $self->hash; + die "This API call was removed in Strike API V2.1\n" +} + +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}; - $response = decode_json $response->{content}; - $url = $response->{message}; - - if (defined $file) { - $response = $ht->mirror($url, $file); - return $response->{success} - } else { - $response = $ht->get($url); - return $response->{success} && $response->{content} - } + $self->{description} = decode_base64 $response->{content} +} + +sub imdb { + my ($self) = @_; + return if !$self->imdb_id || $self->imdb_id eq 'none'; + $self->{imdb} //= WebService::Strike::strike_imdb ($self->imdb_id) } 1; @@ -62,7 +71,7 @@ __END__ =head1 NAME -WebService::Strike::Torrent - Class representing information about a torrent +WebService::Strike::Torrent - [OBSOLETE] Class representing information about a torrent =head1 SYNOPSIS @@ -81,11 +90,20 @@ WebService::Strike::Torrent - Class representing information about a torrent say @{$t->names}; # archlinux-2015.01.01-dual.iso say @{$t->lengths}; # 615514112 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 +B + WebService::Strike::Torrent is a class that represents information about a torrent. @@ -147,17 +165,35 @@ Magnet link for the torrent. =item B([I<$filename>]) +B. Therefore, it simply +dies. Below is the previous documentation of the method. + Downloads the torrent from Strike. With no arguments, returns the contents of the torrent file. With an argument, stores the torrent in 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 @@ -165,7 +201,7 @@ Marius Gavrilescu, Emarius@ieval.roE =head1 COPYRIGHT AND LICENSE -Copyright (C) 2015 by Marius Gavrilescu +Copyright (C) 2015-2016 by Marius Gavrilescu This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.20.2 or,