Changes URL to eztv.ag and tries to fix DOM parsing. master
authorThadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
Wed, 18 Nov 2015 09:00:16 +0000 (07:00 -0200)
committerThadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
Wed, 18 Nov 2015 09:22:56 +0000 (07:22 -0200)
EZTV domain has changed again to eztv.ag, and its DOM has changed too.
The Walking Dead had two different shows, one of them had no episodes,
so I used Doctor Who as a test.

lib/WWW/EZTV.pm
lib/WWW/EZTV/Show.pm
t/02-find.t

index afce7cb..9c3fa3e 100644 (file)
@@ -6,7 +6,7 @@ use WWW::EZTV::Show;
 
 # ABSTRACT: EZTV scrapper
 
-has url       => ( is => 'ro', lazy => 1, default => sub { Mojo::URL->new('https://eztv.ch/') } );
+has url       => ( is => 'ro', lazy => 1, default => sub { Mojo::URL->new('https://eztv.ag/') } );
 has url_shows => ( is => 'ro', lazy => 1, default => sub { shift->url->clone->path('/showlist/') } );
 
 has shows =>
@@ -21,14 +21,14 @@ has shows =>
 sub _build_shows {
     my $self = shift;
 
-    $self->get_response( $self->url_shows )->dom->find('table.header_brd tr[name="hover"]')->map(sub {
+    $self->get_response($self->url_shows)->dom->find('table tr[name="hover"]')->map(sub {
         my $tr = shift;
-        my $link = $tr->at('td:nth-child(2) a');
+        my $link = $tr->at('td:nth-child(1) a');
         WWW::EZTV::Show->new(
             title  => $link->all_text,
             url    => $self->url->clone->path($link->attr('href')),
-            status => lc($tr->at('td:nth-child(3)')->all_text),
-            rating => $tr->at('td:nth-child(4)')->text + 0
+            status => lc($tr->at('td:nth-child(2)')->all_text),
+            rating => $tr->at('td:nth-child(3) b')->text + 0
         );
     });
 }
index dc9b44c..75d9953 100644 (file)
@@ -25,7 +25,7 @@ has episodes =>
 
 sub _build_episodes {
     my $self = shift;
-    $self->get_response($self->url)->dom->find('table.header_noborder tr[name="hover"]')->map(sub{
+    $self->get_response($self->url)->dom->find('table tr[name="hover"]')->map(sub{
         my $tr = shift;
         my $link = $tr->at('td:nth-child(2) a');
 
index ec2de31..5ee3be5 100644 (file)
@@ -11,19 +11,19 @@ my $show;
 
 subtest 'Find a show' => sub {
     ok( $eztv->has_shows, 'Can fetch shows list' );
-    ok( $show = $eztv->find_show(sub{ $_->name =~ /Walking dead/i }), 'Find a known show' );
-    is( $show->name, 'The Walking Dead', 'Name looks good' );
+    ok( $show = $eztv->find_show(sub{ $_->name =~ /Doctor who/i }), 'Find a known show' );
+    is( $show->name, 'Doctor Who', 'Name looks good' );
     ok( $show->url, 'Has url ' . $show->url );
     ok( $show->status, 'Has status ' . $show->status );
 };
 
 subtest 'Find episodes' => sub {
     ok( $show->has_episodes, 'Show fetch show episodes' );
-    ok( my $ep = $show->find_episode(sub{ $_->season == 3 && $_->number == 8 && $_->quality eq 'standard' }), 'Find a known episode' );
+    ok( my $ep = $show->find_episode(sub{ $_->season == 9 && $_->number == 9 && $_->quality eq 'standard' }), 'Find a known episode' );
     diag( 'Title:   ' . $ep->title );
     diag( 'Version: ' . $ep->version );
     diag( 'Size:    ' . $ep->size );
-    is( $ep->name, 'The Walking Dead', 'Name looks good' );
+    is( $ep->name, 'Doctor Who 2005', 'Name looks good' );
 
     ok( $ep->has_links, 'Episode has links' );
     ok( my $link = $ep->find_link(sub{ $_->type eq 'torrent' }), 'Find a torrent link' );