]> iEval git - webservice-strike.git/blobdiff - lib/WebService/Strike.pm
Bump version and update Changes
[webservice-strike.git] / lib / WebService / Strike.pm
index 426a1131ce739d436df34dc737792b21caab7dde..fc8040672c0bda8779c1f3b34c882cb2ab958fcb 100644 (file)
@@ -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/v2/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) = @_;
@@ -33,7 +33,7 @@ sub strike_query {
        if (@hashes > 50) {
                return strike_query (@hashes[0 .. 49]), strike_query (@hashes[50 .. $#hashes]);
        }
-       my $url = "$BASE_URL/info/?hashes=" . join ',', map { uc } @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);
@@ -43,7 +43,7 @@ sub strike_query {
 sub strike_search {
        my ($query, $full, %args) = @_;
        $args{phrase} = $query;
-       my $url = "$BASE_URL/search/?" . HTTP::Tiny->www_form_urlencode(\%args);
+       my $url = "$BASE_URL/torrents/search/?" . HTTP::Tiny->www_form_urlencode(\%args);
 
        my @torrents = _query $url;
        @torrents = $torrents[0] unless wantarray;
@@ -51,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;
@@ -79,6 +89,10 @@ WebService::Strike - Get torrent info from getstrike.net API
   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
 
 Strike API is a service for getting information about a torrent given
@@ -114,11 +128,16 @@ For example:
 
   strike_search 'windows', 0, category => 'Applications', sub_category => 'Windows';
 
+=item B<strike_imdb>(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<WebService::Strike::Torrent>, L<http://getstrike.net/api/>, L<WWW::Search::Torrentz>
+L<WebService::Strike::Torrent>, L<https://getstrike.net/api/>, L<WWW::Search::Torrentz>
 
 =head1 AUTHOR
 
@@ -126,7 +145,7 @@ Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
 
 =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,
This page took 0.027752 seconds and 4 git commands to generate.