X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FWebService%2FStrike.pm;h=f4b6cf14efcfdfa94e8b63c6ea0421ff773d7206;hb=988e8747c4c73d1f0adea3ddd10e64d377cefb10;hp=0b32f1170b3ced717e871b15c9f79f30171bae98;hpb=9e0675f39353e2de39f7f27d6f572cecdf5e2a64;p=webservice-strike.git diff --git a/lib/WebService/Strike.pm b/lib/WebService/Strike.pm index 0b32f11..f4b6cf1 100644 --- a/lib/WebService/Strike.pm +++ b/lib/WebService/Strike.pm @@ -5,17 +5,17 @@ use strict; use warnings; use parent qw/Exporter/; -our @EXPORT = qw/strike strike_search/; ## no critic (ProhibitAutomaticExportation) -our @EXPORT_OK = qw/strike_query strike strike_search/; -our $VERSION = '0.002'; -our $BASE_URL = 'http://getstrike.net/api/torrents/'; +our @EXPORT = qw/strike strike_search strike_imdb/; +our @EXPORT_OK = (@EXPORT, 'strike_query'); +our $VERSION = '0.005'; +our $BASE_URL = 'https://getstrike.net/api/v2'; use JSON::MaybeXS qw/decode_json/; use HTTP::Tiny; use Sort::ByExample qw/sbe/; use WebService::Strike::Torrent; -sub _ht { HTTP::Tiny->new(agent => "WebService-Strike/$VERSION") } +sub _ht { HTTP::Tiny->new(agent => "WebService-Strike/$VERSION", verify_SSL => 1) } sub _query { my ($url) = @_; @@ -25,13 +25,15 @@ sub _query { die $response unless $response->{success}; ## no critic (RequireCarping) $response = decode_json $response->{content}; - die $response unless ref $response eq 'ARRAY'; ## no critic (RequireCarping) - map { WebService::Strike::Torrent->new($_) } @{$response->[1]}; + map { WebService::Strike::Torrent->new($_) } @{$response->{torrents}}; } sub strike_query { my (@hashes) = @_; - my $url = "$BASE_URL/info/?hashes=" . join ',', map { uc } @hashes; + if (@hashes > 50) { + return strike_query (@hashes[0 .. 49]), strike_query (@hashes[50 .. $#hashes]); + } + my $url = "$BASE_URL/torrents/info/?hashes=" . join ',', map { uc } @hashes; my $sorter = sbe(\@hashes, {xform => sub { $_[0]->hash }}); my @torrents = $sorter->(_query $url); @@ -40,8 +42,8 @@ sub strike_query { sub strike_search { my ($query, $full, %args) = @_; - $args{q} = $query; - my $url = "$BASE_URL/search/?" . HTTP::Tiny->www_form_urlencode(\%args); + $args{phrase} = $query; + my $url = "$BASE_URL/torrents/search/?" . HTTP::Tiny->www_form_urlencode(\%args); my @torrents = _query $url; @torrents = $torrents[0] unless wantarray; @@ -49,6 +51,16 @@ sub strike_search { wantarray ? @torrents : $torrents[0] } +sub strike_imdb { + my ($id) = @_; + my $url = "$BASE_URL/media/imdb/?imdbid=$id"; + my $response = _ht->get($url); + return unless $response->{success}; + my %imdb = %{decode_json $response->{content}}; + $imdb{lc $_} = delete $imdb{$_} for keys %imdb; ## no critic (ProhibitUselessTopic) + \%imdb +} + BEGIN { *strike = \&strike_query } 1; @@ -58,7 +70,7 @@ __END__ =head1 NAME -WebService::Strike - Get torrent info from getstrike.net API +WebService::Strike - [OBSOLETE] Get torrent info from the now-discontinued getstrike.net API =head1 SYNOPSIS @@ -73,12 +85,19 @@ WebService::Strike - Get torrent info from getstrike.net API say 'Found ' . @debian . ' torrents matching "Debian"'; say 'First torrent has info hash ' . $debian[0]->hash; - my $mp = strike_search 'Modern perl', 1; + my $mp = strike_search 'Modern perl', 1, category => 'Books'; say 'Torrent has ' . $mp->count . ' files. They are:'; say join ' ', @{$mp->file_names}; + my $info = strike_imdb 'tt1520211'; + say 'IMDB ID ', $info->{imdbid}, ' is ', $info->{title}, ' (', $info->{year}, ')'; + say 'Plot (short): ', $info->{shortplot}; + =head1 DESCRIPTION +B + Strike API is a service for getting information about a torrent given its info hash. WebService::Strike is a wrapper for this service. @@ -94,9 +113,9 @@ error. Alias for B. Not exported by default. -=item B(I<$search_term>, [I<$full>]) +=item B(I<$phrase>, [I<$full>, [ key => value ... ]]) -Searches for torrents given a search term. Returns a list of +Searches for torrents given a phrase. Returns a list of L objects in list context or the first such object in scalar context. @@ -107,11 +126,21 @@ return undef. If I<$full> is true, B will be called with the info hashes of the found torrents, thus obtaining complete objects. +You can filter the search by appending key => value pairs to the call. +For example: + + strike_search 'windows', 0, category => 'Applications', sub_category => 'Windows'; + +=item B(I<$imdb_id>) + +Get informaton about a movie from IMDB. Takes an IMDB ID and returns a +hashref of unspecified format. All keys are lowercased. + =back =head1 SEE ALSO -L, L, L +L, L, L =head1 AUTHOR @@ -119,7 +148,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,