X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FWebService%2FStrike%2FTorrent.pm;fp=lib%2FWebService%2FStrike%2FTorrent.pm;h=4f08520e0b9a8c1a2e2b1a815c39e24be343fc9f;hb=94cc52f9de9a84a6db48bc92466103e4f8b1a78c;hp=0ac15da98ab7571ed27bde46d2dc4e29664ad8f7;hpb=baf841c01522daf9b3e4c65698244d0eef48773e;p=webservice-strike.git diff --git a/lib/WebService/Strike/Torrent.pm b/lib/WebService/Strike/Torrent.pm index 0ac15da..4f08520 100644 --- a/lib/WebService/Strike/Torrent.pm +++ b/lib/WebService/Strike/Torrent.pm @@ -7,12 +7,12 @@ use parent qw/Class::Accessor::Fast/; our $VERSION = '0.004002'; -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 imdb_id/); +__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; @@ -23,14 +23,19 @@ 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}; @@ -40,21 +45,7 @@ sub new{ } sub torrent{ - my ($self, $file) = @_; - 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}; - $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} - } + die "This API call was removed in Strike API V2.1\n" } sub description{ @@ -69,7 +60,7 @@ sub description{ sub imdb { my ($self) = @_; - return unless $self->imdb_id; + return if !$self->imdb_id || $self->imdb_id eq 'none'; $self->{imdb} //= WebService::Strike::strike_imdb ($self->imdb_id) } @@ -99,8 +90,6 @@ 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'; @@ -173,6 +162,9 @@ 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>.