]>
iEval git - www-search-torrentz.git/blob - lib/WWW/Search/Torrentz.pm
1 package WWW
::Search
::Torrentz
;
6 no if $] >= 5.018, warnings
=> 'experimental::smartmatch';
7 use parent qw
/WWW::Search/;
9 our $VERSION = '0.001001';
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);
27 my ($self, $tree) = @_;
30 my @potential_results = $tree->find('dl');
31 my $result_count = $tree->find('h2')->as_text;
32 if (defined $result_count && $result_count ne 'No Torrents Found') {
33 $result_count =~ s/orrents.*//;
34 $result_count =~ y/0-9//cd;
35 $self->approximate_result_count(int $result_count);
38 for my $node (@potential_results) {
39 my $a = $node->find('a');
40 next unless defined $a;
42 my $infohash = substr $a->attr('href'), 1;
43 next unless $infohash =~ m
,^[a
-f0
-9]{40}$,;
44 my $title = $a->as_text;
45 my ($verified, $age, $size, $seeders, $leechers);
47 for my $span($node->find('span')) {
48 given($span->attr('class')){
49 $verified = int ($span->as_text =~ m
,^\d
+,) when 'v';
50 $age = $span->as_text when 'a';
51 $size = $span->as_text when 's';
52 $seeders = int $span->as_text when 'u';
53 $leechers = int $span->as_text when 'd';
57 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);
58 say STDERR
"infohash => $infohash, title => $title, verified => $verified, age => $age, size => $size, seeders => $seeders, leechers => $leechers" if $self->{search_debug
};
62 my $url = $tree->look_down(rel
=> 'next');
64 my $prev = $self->{_prev_url
} =~ s
,/[^/]+$,,r
;
65 $self->{_next_url
} = $prev . $url->attr('href')
67 say STDERR
"Found: $found" if $self->{search_debug
};
78 WWW::Search::Torrentz - search torrentz.eu with WWW::Search
83 my $search = WWW::Search->new('Torrentz');
84 $search->gui_query('query');
85 say $_->title while $_ = $search->next_result;
89 WWW::Search::Torrentz is a subclass of WWW::Search that searches the L<https://torrentz.eu> search aggregator.
91 To use this module, read the L<WWW::Search> documentation.
93 Search results are instances of the L<WWW::Search::Torrentz::Result> class.
95 Available optional L<WWW::Search> methods:
101 Identical to B<native_query>.
103 =item B<approximate_result_count>
105 Returns the exact result count, as indicated by Torrentz.
111 L<https://torrentz.eu/help>, L<WWW::Search>, L<WWW::Search::Torrentz::Result>
115 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
117 =head1 COPYRIGHT AND LICENSE
119 Copyright (C) 2013 by Marius Gavrilescu
121 This library is free software; you can redistribute it and/or modify
122 it under the same terms as Perl itself, either Perl version 5.18.1 or,
123 at your option, any later version of Perl 5 you may have available.
This page took 0.061331 seconds and 5 git commands to generate.