qw/Class::Accessor::Fast 0
Date::Parse 0
JSON::MaybeXS 0
- Sort::ByExample 0
- URI::Escape 0/,
+ Sort::ByExample 0/,
},
META_ADD => {
dynamic_config => 0,
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 $BASE_URL = 'http://getstrike.net/api/v2/torrents';
use JSON::MaybeXS qw/decode_json/;
use HTTP::Tiny;
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 {
sub strike_search {
my ($query, $full, %args) = @_;
- $args{q} = $query;
+ $args{phrase} = $query;
my $url = "$BASE_URL/search/?" . HTTP::Tiny->www_form_urlencode(\%args);
my @torrents = _query $url;
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};
Alias for B<strike>. Not exported by default.
-=item B<strike_search>(I<$search_term>, [I<$full>])
+=item B<strike_search>(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<WebService::Strike::Torrent> objects in list context or the first
such object in scalar context.
If I<$full> is true, B<strike> 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';
+
=back
=head1 SEE ALSO
use Date::Parse qw/str2time/;
use JSON::MaybeXS qw/decode_json/;
-use URI::Escape qw/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/);
+__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/);
BEGIN {
*hash = *torrent_hash;
*uploader = *uploader_username;
*names = *file_names;
*lengths = *file_lengths;
+ *magnet = *magnet_uri;
};
sub new{
$self->{torrent_hash} = uc $self->hash;
$self->{upload_date} = str2time $self->date, 'UTC';
if ($self->file_info) {
- $self->{file_names} = $self->file_info->[0]->{file_names};
- $self->{file_lengths} = $self->file_info->[0]->{file_lengths};
+ $self->{file_names} = $self->file_info->{file_names};
+ $self->{file_lengths} = $self->file_info->{file_lengths};
}
$self
}
-sub magnet{
- my ($self) = @_;
- 'magnet:?xt=urn:btih:' . $self->hash . '&dn=' . uri_escape $self->title
-}
-
sub torrent{
my ($self, $file) = @_;
- my $url = $WebService::Strike::BASE_URL . '/downloads/?hash=' . $self->hash;
+ my $url = $WebService::Strike::BASE_URL . '/download/?hash=' . $self->hash;
my $ht = WebService::Strike::_ht(); ## no critic (ProtectPrivate)
my $response = $ht->get($url);
return unless $response->{success};
say $t->seeds;
say $t->leeches;
say $t->count; # 1
- say $t->size; # 587 MB
+ say $t->size; # 615514112
say $t->date; # 1420502400
say $t->uploader; # The_Doctor-
say @{$t->names}; # archlinux-2015.01.01-dual.iso
=item B<size>
-The total size of the files in the torrent as a human-readable string.
-See B<file_lengths> for exact sizes.
+The total size of the files in the torrent in bytes.
=item B<date>, B<upload_date>
Arrayref of lengths of files in the torrent, in bytes.
-=item B<magnet>
+=item B<magnet>, B<magnet_uri>
Magnet link for the torrent.
my %data = (
leeches => 13,
- size => '587 MB',
- torrent_hash => 'b425907e5755031bda4a8d1b6dccaca97da14c04',
+ size => 615514112,
+ torrent_hash => 'B425907E5755031BDA4A8D1B6DCCACA97DA14C04',
file_count => 1,
sub_category => '',
torrent_category => 'Applications',
- file_info => [{
+ file_info => {
file_names => [ 'archlinux-2015.01.01-dual.iso' ],
file_lengths => [ 615514112 ],
- }],
+ },
upload_date => 'Jan 6, 2015',
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)'
);
is $t->seeds, 645, 'seeds';
is $t->leeches, 13, 'leeches';
is $t->count, 1, 'count';
-is $t->size, '587 MB', 'size';
+is $t->size, 615514112, 'size';
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%20Linux%202015.01.01%20%28x86%2Fx64%29', 'magnet';
+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';