line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Strike; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
46049
|
use 5.014000; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
66
|
|
4
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
61
|
|
5
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
54
|
|
6
|
2
|
|
|
2
|
|
550
|
use parent qw/Exporter/; |
|
2
|
|
|
|
|
269
|
|
|
2
|
|
|
|
|
11
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @EXPORT = qw/strike strike_search strike_imdb/; ## no critic (ProhibitAutomaticExportation) |
9
|
|
|
|
|
|
|
our @EXPORT_OK = (@EXPORT, 'strike_query'); |
10
|
|
|
|
|
|
|
our $VERSION = '0.004002'; |
11
|
|
|
|
|
|
|
our $BASE_URL = 'https://getstrike.net/api/v2'; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
671
|
use JSON::MaybeXS qw/decode_json/; |
|
2
|
|
|
|
|
4423
|
|
|
2
|
|
|
|
|
219
|
|
14
|
2
|
|
|
2
|
|
1579
|
use HTTP::Tiny; |
|
2
|
|
|
|
|
105048
|
|
|
2
|
|
|
|
|
110
|
|
15
|
2
|
|
|
2
|
|
1646
|
use Sort::ByExample qw/sbe/; |
|
2
|
|
|
|
|
21282
|
|
|
2
|
|
|
|
|
14
|
|
16
|
2
|
|
|
2
|
|
882
|
use WebService::Strike::Torrent; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
29
|
|
17
|
|
|
|
|
|
|
|
18
|
10
|
|
|
10
|
|
100
|
sub _ht { HTTP::Tiny->new(agent => "WebService-Strike/$VERSION", verify_SSL => 1) } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _query { |
21
|
7
|
|
|
7
|
|
13
|
my ($url) = @_; |
22
|
|
|
|
|
|
|
|
23
|
7
|
|
|
|
|
29
|
my $ht = _ht; |
24
|
7
|
|
|
|
|
724
|
my $response = $ht->get($url); |
25
|
7
|
100
|
|
|
|
1379036
|
die $response unless $response->{success}; ## no critic (RequireCarping) |
26
|
5
|
|
|
|
|
2061
|
$response = decode_json $response->{content}; |
27
|
|
|
|
|
|
|
|
28
|
5
|
|
|
|
|
44
|
map { WebService::Strike::Torrent->new($_) } @{$response->{torrents}}; |
|
205
|
|
|
|
|
546
|
|
|
5
|
|
|
|
|
21
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub strike_query { |
32
|
4
|
|
|
4
|
1
|
4564
|
my (@hashes) = @_; |
33
|
4
|
50
|
|
|
|
15
|
if (@hashes > 50) { |
34
|
0
|
|
|
|
|
0
|
return strike_query (@hashes[0 .. 49]), strike_query (@hashes[50 .. $#hashes]); |
35
|
|
|
|
|
|
|
} |
36
|
4
|
|
|
|
|
60
|
my $url = "$BASE_URL/torrents/info/?hashes=" . join ',', map { uc } @hashes; |
|
6
|
|
|
|
|
28
|
|
37
|
|
|
|
|
|
|
|
38
|
4
|
|
|
5
|
|
38
|
my $sorter = sbe(\@hashes, {xform => sub { $_[0]->hash }}); |
|
5
|
|
|
|
|
6517
|
|
39
|
4
|
|
|
|
|
168
|
my @torrents = $sorter->(_query $url); |
40
|
3
|
100
|
|
|
|
177
|
wantarray ? @torrents : $torrents[0] |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub strike_search { |
44
|
3
|
|
|
3
|
1
|
7059
|
my ($query, $full, %args) = @_; |
45
|
3
|
|
|
|
|
9
|
$args{phrase} = $query; |
46
|
3
|
|
|
|
|
30
|
my $url = "$BASE_URL/torrents/search/?" . HTTP::Tiny->www_form_urlencode(\%args); |
47
|
|
|
|
|
|
|
|
48
|
3
|
|
|
|
|
204
|
my @torrents = _query $url; |
49
|
2
|
100
|
|
|
|
4138
|
@torrents = $torrents[0] unless wantarray; |
50
|
2
|
100
|
|
|
|
10
|
@torrents = strike_query map { $_->hash } @torrents if $full; |
|
1
|
|
|
|
|
6
|
|
51
|
2
|
100
|
|
|
|
50
|
wantarray ? @torrents : $torrents[0] |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub strike_imdb { |
55
|
1
|
|
|
1
|
1
|
6
|
my ($id) = @_; |
56
|
1
|
|
|
|
|
6
|
my $url = "$BASE_URL/media/imdb/?imdbid=$id"; |
57
|
1
|
|
|
|
|
6
|
my $response = _ht->get($url); |
58
|
1
|
50
|
|
|
|
149471
|
return unless $response->{success}; |
59
|
1
|
|
|
|
|
3081
|
decode_json $response->{content} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
2
|
|
1011
|
BEGIN { *strike = \&strike_query } |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
__END__ |