]>
iEval git - webservice-strike.git/blob - Strike.pm
bf51deb54147c0fef1128d832a1032b417b88534
1 package WebService
::Strike
;
6 use parent qw
/Exporter/;
8 our @EXPORT = qw
/strike strike_search/; ## no critic (ProhibitAutomaticExportation)
9 our @EXPORT_OK = qw
/strike_query strike strike_search/;
10 our $VERSION = '0.003';
11 our $BASE_URL = 'http://getstrike.net/api/v2/torrents';
13 use JSON
::MaybeXS qw
/decode_json/;
15 use Sort
::ByExample qw
/sbe/;
16 use WebService
::Strike
::Torrent
;
18 sub _ht
{ HTTP
::Tiny
->new(agent
=> "WebService-Strike/$VERSION") }
24 my $response = $ht->get($url);
25 die $response unless $response->{success
}; ## no critic (RequireCarping)
26 $response = decode_json
$response->{content
};
28 map { WebService
::Strike
::Torrent
->new($_) } @
{$response->{torrents
}};
34 return strike_query
(@hashes[0 .. 49]), strike_query
(@hashes[50 .. $#hashes]);
36 my $url = "$BASE_URL/info/?hashes=" . join ',', map { uc } @hashes;
38 my $sorter = sbe
(\
@hashes, {xform
=> sub { $_[0]->hash }});
39 my @torrents = $sorter->(_query
$url);
40 wantarray ?
@torrents : $torrents[0]
44 my ($query, $full, %args) = @_;
45 $args{phrase
} = $query;
46 my $url = "$BASE_URL/search/?" . HTTP
::Tiny
->www_form_urlencode(\
%args);
48 my @torrents = _query
$url;
49 @torrents = $torrents[0] unless wantarray;
50 @torrents = strike_query
map { $_->hash } @torrents if $full;
51 wantarray ?
@torrents : $torrents[0]
54 BEGIN { *strike
= \
&strike_query
}
63 WebService::Strike - Get torrent info from getstrike.net API
67 use WebService::Strike;
68 my $t = strike 'B425907E5755031BDA4A8D1B6DCCACA97DA14C04';
69 say $t->title; # Arch Linux 2015.01.01 (x86\/x64)
70 say $t->magnet; # Returns a magnet link
71 my $torrent = $t->torrent; # Returns the torrent file
72 $t->torrent('file.torrent'); # Downloads the torrent file to 'file.torrent'
74 my @debian = strike_search 'Debian';
75 say 'Found ' . @debian . ' torrents matching "Debian"';
76 say 'First torrent has info hash ' . $debian[0]->hash;
78 my $mp = strike_search 'Modern perl', 1, category => 'Books';
79 say 'Torrent has ' . $mp->count . ' files. They are:';
80 say join ' ', @{$mp->file_names};
84 Strike API is a service for getting information about a torrent given
85 its info hash. WebService::Strike is a wrapper for this service.
89 =item B<strike>(I<@info_hashes>)
91 Returns a list of L<WebService::Strike::Torrent> objects in list
92 context or the first such object in scalar context. Dies in case of
97 Alias for B<strike>. Not exported by default.
99 =item B<strike_search>(I<$phrase>, [I<$full>, [ key => value ... ]])
101 Searches for torrents given a phrase. Returns a list of
102 L<WebService::Strike::Torrent> objects in list context or the first
103 such object in scalar context.
105 If I<$full> is false (default), the returned objects will be
106 incomplete: their B<file_names> and B<file_lengths> accessors will
109 If I<$full> is true, B<strike> will be called with the info hashes of
110 the found torrents, thus obtaining complete objects.
112 You can filter the search by appending key => value pairs to the call.
115 strike_search 'windows', 0, category => 'Applications', sub_category => 'Windows';
121 L<WebService::Strike::Torrent>, L<http://getstrike.net/api/>, L<WWW::Search::Torrentz>
125 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
127 =head1 COPYRIGHT AND LICENSE
129 Copyright (C) 2015 by Marius Gavrilescu
131 This library is free software; you can redistribute it and/or modify
132 it under the same terms as Perl itself, either Perl version 5.20.2 or,
133 at your option, any later version of Perl 5 you may have available.
This page took 0.052014 seconds and 3 git commands to generate.