]>
iEval git - www-search-torrentz.git/blob - lib/WWW/Search/Torrentz.pm
e7c77137d96d4469fdf466c55eaab483ab6d90b8
1 package WWW
::Search
::Torrentz
;
6 no if $] >= 5.018, warnings
=> 'experimental::smartmatch';
7 use parent qw
/WWW::Search/;
9 our $VERSION = '0.001002';
10 our $MAINTAINER = 'Marius Gavrilescu <marius@ieval.ro>';
12 use WWW
::Search
::Torrentz
::Result
;
14 sub gui_query
{ shift->native_query(@_) }
16 sub _native_setup_search
{
17 my ($self, $native_query, $options) = @_;
18 $self->agent_email('marius@ieval.ro');
20 my $base_url = $options->{search_url
} // 'https://torrentz.eu/search';
21 $self->{search_debug
} = $options->{search_debug
};
22 $self->{_next_url
} = "$base_url?f=$native_query";
23 $self->user_agent->delay(2/60);
26 sub fullint
($) { int (shift =~ y/0-9//cdr) }
29 my ($self, $tree) = @_;
32 my @potential_results = $tree->find('dl');
33 my $result_count = $tree->find('h2')->as_text;
34 if (defined $result_count && $result_count ne 'No Torrents Found') {
35 $result_count =~ s/orrents.*//;
36 $self->approximate_result_count(fullint
$result_count);
39 for my $node (@potential_results) {
40 my $a = $node->find('a');
41 next unless defined $a;
43 my $infohash = substr $a->attr('href'), 1;
44 next unless $infohash =~ m
,^[a
-f0
-9]{40}$,;
45 my $title = $a->as_text;
46 my ($verified, $age, $size, $seeders, $leechers);
48 for my $span ($node->find('span')) {
49 given($span->attr('class')){
50 $verified = int ($span->as_text =~ m
,^\d
+,) when 'v';
51 $age = $span->as_text when 'a';
52 $size = $span->as_text when 's';
53 $seeders = fullint
$span->as_text when 'u';
54 $leechers = fullint
$span->as_text when 'd';
58 push @
{$self->{cache
}}, WWW
::Search
::Torrentz
::Result
->new(infohash
=> $infohash, title
=> $title, verified
=> $verified, age
=> $age, size
=> $size, seeders
=> $seeders, leechers
=> $leechers, ua
=> $self->user_agent);
59 say STDERR
"infohash => $infohash, title => $title, verified => $verified, age => $age, size => $size, seeders => $seeders, leechers => $leechers" if $self->{search_debug
};
63 my $url = $tree->look_down(rel
=> 'next');
65 my $prev = $self->{_prev_url
} =~ s
,/[^/]+$,,r
;
66 $self->{_next_url
} = $prev . $url->attr('href')
68 say STDERR
"Found: $found" if $self->{search_debug
};
79 WWW::Search::Torrentz - search torrentz.eu with WWW::Search
84 my $search = WWW::Search->new('Torrentz');
85 $search->gui_query('query');
86 say $_->title while $_ = $search->next_result;
90 WWW::Search::Torrentz is a subclass of WWW::Search that searches the L<https://torrentz.eu> search aggregator.
92 To use this module, read the L<WWW::Search> documentation.
94 Search results are instances of the L<WWW::Search::Torrentz::Result> class.
96 Available optional L<WWW::Search> methods:
102 Identical to B<native_query>.
104 =item B<approximate_result_count>
106 Returns the exact result count, as indicated by Torrentz.
112 L<https://torrentz.eu/help>, L<WWW::Search>, L<WWW::Search::Torrentz::Result>
116 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
118 =head1 COPYRIGHT AND LICENSE
120 Copyright (C) 2013 by Marius Gavrilescu
122 This library is free software; you can redistribute it and/or modify
123 it under the same terms as Perl itself, either Perl version 5.18.1 or,
124 at your option, any later version of Perl 5 you may have available.
This page took 0.06008 seconds and 3 git commands to generate.