From: Marius Gavrilescu Date: Sat, 23 Jan 2016 18:44:40 +0000 (+0000) Subject: Update for API V2.1 X-Git-Tag: 0.005~1 X-Git-Url: http://git.ieval.ro/?p=webservice-strike.git;a=commitdiff_plain;h=94cc52f9de9a84a6db48bc92466103e4f8b1a78c Update for API V2.1 * ->torrent method now dies as the API call was removed * ->magnet method implemented manually * Date::Parse no longer needed * Some tests disabled as the API seems broken --- diff --git a/Makefile.PL b/Makefile.PL index ef212a1..b55510f 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -16,12 +16,12 @@ WriteMakefile( PREREQ_PM => { qw/HTTP::Tiny 0.014 Class::Accessor::Fast 0 - Date::Parse 0 IO::Socket::SSL 1.56 JSON::MaybeXS 0 Mozilla::CA 0 Net::SSLeay 1.49 - Sort::ByExample 0/, + Sort::ByExample 0 + URI::Escape 0/, }, META_ADD => { dynamic_config => 0, diff --git a/lib/WebService/Strike.pm b/lib/WebService/Strike.pm index 58d43c2..1b2be6f 100644 --- a/lib/WebService/Strike.pm +++ b/lib/WebService/Strike.pm @@ -5,7 +5,7 @@ use strict; use warnings; use parent qw/Exporter/; -our @EXPORT = qw/strike strike_search strike_imdb/; ## no critic (ProhibitAutomaticExportation) +our @EXPORT = qw/strike strike_search strike_imdb/; our @EXPORT_OK = (@EXPORT, 'strike_query'); our $VERSION = '0.004003'; our $BASE_URL = 'https://getstrike.net/api/v2'; 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>. diff --git a/t/WebService-Strike-Torrent.t b/t/WebService-Strike-Torrent.t index cde5c7f..16e5fe9 100644 --- a/t/WebService-Strike-Torrent.t +++ b/t/WebService-Strike-Torrent.t @@ -16,10 +16,9 @@ my %data = ( file_names => [ 'archlinux-2015.01.01-dual.iso' ], file_lengths => [ 615514112 ], }, - upload_date => 'Jan 6, 2015', + upload_date => 1420502400, seeds => 645, uploader_username => 'The_Doctor-', - magnet_uri => 'magnet:?xt=urn:btih:B425907E5755031BDA4A8D1B6DCCACA97DA14C04&dn=Arch+Linux+2015.01.01+%28x86%2Fx64%29&tr=udp://open.demonii.com:1337&tr=udp://tracker.coppersurfer.tk:6969&tr=udp://tracker.leechers-paradise.org:6969&tr=udp://exodus.desync.com:6969', torrent_title => 'Arch Linux 2015.01.01 (x86/x64)' ); @@ -37,4 +36,4 @@ is $t->date, 1420502400,'date'; is $t->uploader, 'The_Doctor-', 'uploader'; is $t->names->[0], 'archlinux-2015.01.01-dual.iso', 'names'; is $t->lengths->[0], 615514112, 'lengths'; -is $t->magnet, 'magnet:?xt=urn:btih:B425907E5755031BDA4A8D1B6DCCACA97DA14C04&dn=Arch+Linux+2015.01.01+%28x86%2Fx64%29&tr=udp://open.demonii.com:1337&tr=udp://tracker.coppersurfer.tk:6969&tr=udp://tracker.leechers-paradise.org:6969&tr=udp://exodus.desync.com:6969', 'magnet'; +is $t->magnet, 'magnet:?xt=urn:btih:B425907E5755031BDA4A8D1B6DCCACA97DA14C04&dn=Arch%20Linux%202015.01.01%20%28x86%2Fx64%29', 'magnet'; diff --git a/t/WebService-Strike.t b/t/WebService-Strike.t index 19e4162..69c7596 100644 --- a/t/WebService-Strike.t +++ b/t/WebService-Strike.t @@ -4,28 +4,27 @@ use warnings; use Data::Dumper qw/Dumper/; use Test::RequiresInternet qw/getstrike.net 443/; -use Test::More tests => 11; +use Test::More tests => 8; use Try::Tiny; BEGIN { use_ok('WebService::Strike') }; my ($t1, $t2, $t3); try { - ($t1, $t2, $t3) = strike qw/B425907E5755031BDA4A8D1B6DCCACA97DA14C04 5D4FD5A64E436A831383773F85FB38B888B9ECC9 ED70C185E3E3246F30B2FDB08D504EABED5EEA3F/; + ($t1, $t2, $t3) = strike qw/66FC47BF95D1AA5ECA358F12C70AF3BA5C7E8F9A 5D4FD5A64E436A831383773F85FB38B888B9ECC9 B425907E5755031BDA4A8D1B6DCCACA97DA14C04/; } catch { diag 'Error while calling strike:', "\n", Dumper $_ }; subtest 'order' => sub { plan tests => 3; - is $t1->hash, 'B425907E5755031BDA4A8D1B6DCCACA97DA14C04', 'hash #1'; + is $t1->hash, '66FC47BF95D1AA5ECA358F12C70AF3BA5C7E8F9A', 'hash #1'; is $t2->hash, '5D4FD5A64E436A831383773F85FB38B888B9ECC9', 'hash #2'; - is $t3->hash, 'ED70C185E3E3246F30B2FDB08D504EABED5EEA3F', 'hash #3' + is $t3->hash, 'B425907E5755031BDA4A8D1B6DCCACA97DA14C04', 'hash #3' }; -is $t1->date, 1420502400, 'date'; +is $t1->date, 1439319419, 'date'; is $t2->title, 'FreeBSD 7.1 i386.DVD.iso', 'title'; -like $t1->torrent, qr/^d/, 'torrent file starts with d'; -like $t1->description, qr#GNU/Linux#, 'description contains GNU/Linux'; +like $t2->description, qr#FreeBSD#, 'description contains FreeBSD'; try { strike 'aaa'; @@ -41,8 +40,13 @@ try { is $_->{status}, 404, "search for nosuchstring$$ returned 404" }; -my $p = strike_search 'Perl', 1; -is @{$p->file_names}, $p->count, 'file_names has count elements'; +# Test disabled as it fails due to the API returning bad results +#my $p = strike_search 'Perl', 1; +#say STDERR $p->hash; +# +#is @{$p->file_names}, $p->count, 'file_names has count elements'; -my $imdb = strike('ED70C185E3E3246F30B2FDB08D504EABED5EEA3F')->imdb; -is $imdb->{title}, 'The Walking Dead', 'imdb title'; +# Test disabled as I can't find a torrent with an IMDB ID. Presumably +# this feature of the API is broken. +#my $imdb = strike('ED70C185E3E3246F30B2FDB08D504EABED5EEA3F')->imdb; +#is $imdb->{title}, 'The Walking Dead', 'imdb title';