]>
iEval git - www-search-torrentz.git/blob - Torrentz.pm
432badd210bce279f23c4172aed9ab13477a61c6
1 package WWW
::Search
::Torrentz
;
6 no if $] >= 5.018, warnings
=> 'experimental::smartmatch';
7 use parent qw
/WWW::Search/;
10 our $VERSION = '0.001003';
11 our $MAINTAINER = 'Marius Gavrilescu <marius@ieval.ro>';
13 use WWW
::Search
::Torrentz
::Result
;
15 sub debug
{ say STDERR
@_ } ## no critic (RequireCheckedSyscalls)
17 sub gui_query
{ shift->native_query(@_) }
19 sub _native_setup_search
{ ## no critic (ProhibitUnusedPrivateSubroutines)
20 my ($self, $native_query, $options) = @_;
21 $self->agent_email('marius@ieval.ro');
23 my $base_url = $options->{search_url
} // 'https://torrentz.eu/search';
24 $self->{search_debug
} = $options->{search_debug
};
25 $self->{_next_url
} = "$base_url?f=$native_query";
26 $self->user_agent->delay(2/60);
29 sub fullint
($) { int (shift =~ y/0-9//cdr) } ## no critic (ProhibitSubroutinePrototypes)
31 sub _parse_tree
{ ## no critic (ProhibitUnusedPrivateSubroutines)
32 my ($self, $tree) = @_;
35 my @potential_results = $tree->find('dl');
36 my $result_count = $tree->find('h2')->as_text;
37 if (defined $result_count && $result_count ne 'No Torrents Found') {
38 $result_count =~ s/orrents.*//;
39 $self->approximate_result_count(fullint
$result_count);
42 for my $node (@potential_results) {
43 my $a = $node->find('a');
44 next unless defined $a;
46 my $infohash = substr $a->attr('href'), 1;
47 next unless $infohash =~ /^[a-f0-9]{40}$/;
48 my $title = $a->as_text;
49 my ($verified, $age, $size, $seeders, $leechers);
51 for my $span ($node->find('span')) {
52 given($span->attr('class')){
53 $verified = int ($span->as_text =~ /^\d+/) when 'v';
54 $age = $span->as_text when 'a';
55 $size = $span->as_text when 's';
56 $seeders = fullint
$span->as_text when 'u';
57 $leechers = fullint
$span->as_text when 'd';
61 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);
62 debug
"infohash => $infohash, title => $title, verified => $verified, age => $age, size => $size, seeders => $seeders, leechers => $leechers" if $self->{search_debug
};
66 my $url = $tree->look_down(rel
=> 'next');
68 my $prev = $self->{_prev_url
} =~ s{/[^/]+$}{}r;
69 $self->{_next_url
} = $prev . $url->attr('href')
71 debug
"Found: $found" if $self->{search_debug
};
82 WWW::Search::Torrentz - [DEPRECATED] search torrentz.eu with WWW::Search
87 my $search = WWW::Search->new('Torrentz');
88 $search->gui_query('query');
89 say $_->title while $_ = $search->next_result;
93 This module is deprecated since L<https://torrentz.eu> was shut down
96 WWW::Search::Torrentz is a subclass of WWW::Search that searches the
97 L<https://torrentz.eu> search aggregator.
99 To use this module, read the L<WWW::Search> documentation.
101 Search results are instances of the L<WWW::Search::Torrentz::Result> class.
103 Available optional L<WWW::Search> methods:
109 Identical to B<native_query>.
111 =item B<approximate_result_count>
113 Returns the exact result count, as indicated by Torrentz.
119 L<https://torrentz.eu/help>, L<WWW::Search>, L<WWW::Search::Torrentz::Result>
123 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
125 =head1 COPYRIGHT AND LICENSE
127 Copyright (C) 2013 by Marius Gavrilescu
129 This library is free software; you can redistribute it and/or modify
130 it under the same terms as Perl itself, either Perl version 5.18.1 or,
131 at your option, any later version of Perl 5 you may have available.
This page took 0.052974 seconds and 3 git commands to generate.