Bump version and update Changes
[www-search-torrentz.git] / lib / WWW / Search / Torrentz.pm
CommitLineData
e605ae0f
MG
1package WWW::Search::Torrentz;
2
3use 5.014000;
4use strict;
5use warnings;
d54e3343 6no if $] >= 5.018, warnings => 'experimental::smartmatch';
e605ae0f 7use parent qw/WWW::Search/;
9219ba0f 8use re '/s';
e605ae0f 9
101a5951 10our $VERSION = '0.002';
e605ae0f
MG
11our $MAINTAINER = 'Marius Gavrilescu <marius@ieval.ro>';
12
13use WWW::Search::Torrentz::Result;
14
9219ba0f
MG
15sub debug { say STDERR @_ } ## no critic (RequireCheckedSyscalls)
16
e605ae0f
MG
17sub gui_query{ shift->native_query(@_) }
18
9219ba0f 19sub _native_setup_search{ ## no critic (ProhibitUnusedPrivateSubroutines)
7dcf8cda
MG
20 my ($self, $native_query, $options) = @_;
21 $self->agent_email('marius@ieval.ro');
22 $options //= {};
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);
e605ae0f
MG
27}
28
9219ba0f 29sub fullint ($) { int (shift =~ y/0-9//cdr) } ## no critic (ProhibitSubroutinePrototypes)
287bea8a 30
9219ba0f 31sub _parse_tree{ ## no critic (ProhibitUnusedPrivateSubroutines)
7dcf8cda
MG
32 my ($self, $tree) = @_;
33 my $found = 0;
34
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.*//;
287bea8a 39 $self->approximate_result_count(fullint $result_count);
e605ae0f
MG
40 }
41
7dcf8cda
MG
42 for my $node (@potential_results) {
43 my $a = $node->find('a');
44 next unless defined $a;
45
46 my $infohash = substr $a->attr('href'), 1;
9219ba0f 47 next unless $infohash =~ /^[a-f0-9]{40}$/;
7dcf8cda
MG
48 my $title = $a->as_text;
49 my ($verified, $age, $size, $seeders, $leechers);
50 $verified = 0;
51 for my $span ($node->find('span')) {
52 given($span->attr('class')){
9219ba0f 53 $verified = int ($span->as_text =~ /^\d+/) when 'v';
7dcf8cda
MG
54 $age = $span->as_text when 'a';
55 $size = $span->as_text when 's';
287bea8a
MG
56 $seeders = fullint $span->as_text when 'u';
57 $leechers = fullint $span->as_text when 'd';
7dcf8cda
MG
58 }
59 }
60
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);
9219ba0f 62 debug "infohash => $infohash, title => $title, verified => $verified, age => $age, size => $size, seeders => $seeders, leechers => $leechers" if $self->{search_debug};
7dcf8cda
MG
63 $found++;
64 }
65
66 my $url = $tree->look_down(rel => 'next');
67 if (defined $url) {
9219ba0f 68 my $prev = $self->{_prev_url} =~ s{/[^/]+$}{}r;
7dcf8cda
MG
69 $self->{_next_url} = $prev . $url->attr('href')
70 }
9219ba0f 71 debug "Found: $found" if $self->{search_debug};
7dcf8cda 72 return $found;
e605ae0f
MG
73}
74
751;
76__END__
77
78=encoding utf-8
79
80=head1 NAME
81
47d688d7 82WWW::Search::Torrentz - [DEPRECATED] search torrentz.eu with WWW::Search
e605ae0f
MG
83
84=head1 SYNOPSIS
85
86 use WWW::Search;
87 my $search = WWW::Search->new('Torrentz');
88 $search->gui_query('query');
89 say $_->title while $_ = $search->next_result;
90
91=head1 DESCRIPTION
92
47d688d7
MG
93This module is deprecated since L<https://torrentz.eu> was shut down
94in August 2016.
95
96WWW::Search::Torrentz is a subclass of WWW::Search that searches the
97L<https://torrentz.eu> search aggregator.
e605ae0f
MG
98
99To use this module, read the L<WWW::Search> documentation.
100
101Search results are instances of the L<WWW::Search::Torrentz::Result> class.
102
103Available optional L<WWW::Search> methods:
104
105=over
106
107=item B<gui_query>
108
109Identical to B<native_query>.
110
111=item B<approximate_result_count>
112
113Returns the exact result count, as indicated by Torrentz.
114
115=back
116
117=head1 SEE ALSO
118
119L<https://torrentz.eu/help>, L<WWW::Search>, L<WWW::Search::Torrentz::Result>
120
121=head1 AUTHOR
122
123Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
124
125=head1 COPYRIGHT AND LICENSE
126
127Copyright (C) 2013 by Marius Gavrilescu
128
129This library is free software; you can redistribute it and/or modify
130it under the same terms as Perl itself, either Perl version 5.18.1 or,
131at your option, any later version of Perl 5 you may have available.
132
133
134=cut
This page took 0.020395 seconds and 4 git commands to generate.