]> iEval git - www-search-torrentz.git/blobdiff - lib/WWW/Search/Torrentz.pm
Bump version and update Changes
[www-search-torrentz.git] / lib / WWW / Search / Torrentz.pm
index cd5920dd64a6f323c04955d5333743ab1a7c89f7..114755b3af18091eea04e33e43965bd7cd11170f 100644 (file)
@@ -3,69 +3,73 @@ package WWW::Search::Torrentz;
 use 5.014000;
 use strict;
 use warnings;
-no warnings 'experimental::smartmatch';
+no if $] >= 5.018, warnings => 'experimental::smartmatch';
 use parent qw/WWW::Search/;
+use re '/s';
 
-our $VERSION = '0.001';
+our $VERSION = '0.002';
 our $MAINTAINER = 'Marius Gavrilescu <marius@ieval.ro>';
 
 use WWW::Search::Torrentz::Result;
 
+sub debug { say STDERR @_ } ## no critic (RequireCheckedSyscalls)
+
 sub gui_query{ shift->native_query(@_) }
 
-sub _native_setup_search{
-  my ($self, $native_query, $options) = @_;
-  $self->agent_email('marius@ieval.ro');
-  $options //= {};
-  my $base_url = $options->{search_url} // 'https://torrentz.eu/search';
-  $self->{search_debug} = $options->{search_debug};
-  $self->{_next_url} = "$base_url?f=$native_query";
-  $self->user_agent->delay(2/60);
+sub _native_setup_search{ ## no critic (ProhibitUnusedPrivateSubroutines)
+       my ($self, $native_query, $options) = @_;
+       $self->agent_email('marius@ieval.ro');
+       $options //= {};
+       my $base_url = $options->{search_url} // 'https://torrentz.eu/search';
+       $self->{search_debug} = $options->{search_debug};
+       $self->{_next_url} = "$base_url?f=$native_query";
+       $self->user_agent->delay(2/60);
 }
 
-sub _parse_tree{
-  my ($self, $tree) = @_;
-  my $found = 0;
-
-  my @potential_results = $tree->find('dl');
-  my $result_count = $tree->find('h2')->as_text;
-  if (defined $result_count && $result_count ne 'No Torrents Found') {
-       $result_count =~ s/orrents.*//;
-       $result_count =~ y/0-9//cd;
-       $self->approximate_result_count(int $result_count);
-  }
-
-  for my $node (@potential_results) {
-       my $a = $node->find('a');
-       next unless defined $a;
-
-       my $infohash = substr $a->attr('href'), 1;
-       next unless $infohash =~ m,^[a-f0-9]{40}$,;
-       my $title = $a->as_text;
-       my ($verified, $age, $size, $seeders, $leechers);
-       $verified = 0;
-       for my $span($node->find('span')) {
-         given($span->attr('class')){
-               $verified = int ($span->as_text =~ m,^\d+,) when 'v';
-               $age = $span->as_text when 'a';
-               $size = $span->as_text when 's';
-               $seeders = int $span->as_text when 'u';
-               $leechers = int $span->as_text when 'd';
-         }
+sub fullint ($) { int (shift =~ y/0-9//cdr) } ## no critic (ProhibitSubroutinePrototypes)
+
+sub _parse_tree{ ## no critic (ProhibitUnusedPrivateSubroutines)
+       my ($self, $tree) = @_;
+       my $found = 0;
+
+       my @potential_results = $tree->find('dl');
+       my $result_count = $tree->find('h2')->as_text;
+       if (defined $result_count && $result_count ne 'No Torrents Found') {
+               $result_count =~ s/orrents.*//;
+               $self->approximate_result_count(fullint $result_count);
        }
 
-       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);
-       say STDERR "infohash => $infohash, title => $title, verified => $verified, age => $age, size => $size, seeders => $seeders, leechers => $leechers" if $self->{search_debug};
-       $found++;
-  }
-
-  my $url = $tree->look_down(rel => 'next');
-  if (defined $url) {
-       my $prev = $self->{_prev_url} =~ s,/[^/]+$,,r;
-       $self->{_next_url} = $prev . $url->attr('href')
-  }
-  say STDERR "Found: $found" if $self->{search_debug};
-  return $found;
+       for my $node (@potential_results) {
+               my $a = $node->find('a');
+               next unless defined $a;
+
+               my $infohash = substr $a->attr('href'), 1;
+               next unless $infohash =~ /^[a-f0-9]{40}$/;
+               my $title = $a->as_text;
+               my ($verified, $age, $size, $seeders, $leechers);
+               $verified = 0;
+               for my $span ($node->find('span')) {
+                       given($span->attr('class')){
+                               $verified = int ($span->as_text =~ /^\d+/) when 'v';
+                               $age = $span->as_text when 'a';
+                               $size = $span->as_text when 's';
+                               $seeders = fullint $span->as_text when 'u';
+                               $leechers = fullint $span->as_text when 'd';
+                       }
+               }
+
+               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);
+               debug "infohash => $infohash, title => $title, verified => $verified, age => $age, size => $size, seeders => $seeders, leechers => $leechers" if $self->{search_debug};
+               $found++;
+       }
+
+       my $url = $tree->look_down(rel => 'next');
+       if (defined $url) {
+               my $prev = $self->{_prev_url} =~ s{/[^/]+$}{}r;
+               $self->{_next_url} = $prev . $url->attr('href')
+       }
+       debug "Found: $found" if $self->{search_debug};
+       return $found;
 }
 
 1;
@@ -75,7 +79,7 @@ __END__
 
 =head1 NAME
 
-WWW::Search::Torrentz - search torrentz.eu with WWW:Search
+WWW::Search::Torrentz - [DEPRECATED] search torrentz.eu with WWW::Search
 
 =head1 SYNOPSIS
 
@@ -86,7 +90,11 @@ WWW::Search::Torrentz - search torrentz.eu with WWW:Search
 
 =head1 DESCRIPTION
 
-WWW::Search::Torrentz is a subclass of WWW::Search that searches the L<https://torrentz.eu> search aggregator.
+This module is deprecated since L<https://torrentz.eu> was shut down
+in August 2016.
+
+WWW::Search::Torrentz is a subclass of WWW::Search that searches the
+L<https://torrentz.eu> search aggregator.
 
 To use this module, read the L<WWW::Search> documentation.
 
This page took 0.034581 seconds and 4 git commands to generate.