Retrive episode links by type and some more docs v0.03
authordiegok <diego@freekeylabs.com>
Tue, 25 Dec 2012 23:47:07 +0000 (00:47 +0100)
committerdiegok <diego@freekeylabs.com>
Tue, 25 Dec 2012 23:47:07 +0000 (00:47 +0100)
Changes
lib/WWW/EZTV.pm
lib/WWW/EZTV/Episode.pm
lib/WWW/EZTV/Link.pm
lib/WWW/EZTV/Show.pm
t/02-find.t

diff --git a/Changes b/Changes
index 905b5fe..44f8f09 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 {{$NEXT}}
 
+    - Retrieve episode link by type (magnet, torrent, direct).
+
+0.02      2012-12-26 00:06:54 Europe/Madrid
+
     - Better docs formatting
     - Changes file :)
 
index d2bde1f..2bf91dc 100644 (file)
@@ -36,20 +36,24 @@ sub _build_shows {
 
 =head1 SYNOPSIS
 
-First create a WWW::EZTV object to navigate.
-
     use WWW::EZTV;
+    use v5.10;
 
     my $eztv = WWW::EZTV->new;
 
+    # Find one show
     my $show = $eztv->find_show(sub{ $_->name =~ /Walking dead/i });
 
+    # Find one episode
     my $episode = $show->find_episode(sub{ 
         $_->season == 3 && 
         $_->number == 8 && 
         $_->quality eq 'standard' 
     });
 
+    # Get first torrent url for this episode
+    say $episode->find_link(sub{ $_->type eq 'torrent' })->url;
+
 =attr url
 
 EZTV URL.
index 0f2ffa2..fa2da23 100644 (file)
@@ -2,12 +2,17 @@ package WWW::EZTV::Episode;
 use Moose;
 with 'WWW::EZTV::UA';
 
-# ABSTRACT: EZTV single episode
+# ABSTRACT: Show episode
 
 has show     => is => 'ro', isa => 'WWW::EZTV::Show', required => 1;
 has title    => is => 'ro', isa => 'Str', required => 1;
 has url      => is => 'ro', isa => 'Mojo::URL', required => 1;
-has links    => is => 'rw';
+has links    => 
+    is      => 'ro',
+    handles => {
+        find_link => 'first',
+        has_links => 'size',
+    };
 
 has _parsed  => is => 'ro', lazy => 1, builder => '_parse';
 
@@ -68,3 +73,16 @@ sub _parse {
 }
 
 1;
+
+=attr has_links
+
+How many episodes has this show.
+
+=cut
+
+=method find_link
+
+Find first L<WWW::EZTV::Link> object matching the given criteria. 
+This method accept an anon function.
+
+=cut
index 065544b..12b1a81 100644 (file)
@@ -2,8 +2,41 @@ package WWW::EZTV::Link;
 use Moose;
 with 'WWW::EZTV::UA';
 
-# ABSTRACT: EZTV episode link
+# ABSTRACT: Episode link
 
+=attr url
+
+Link address
+
+=cut
 has url => is => 'ro', isa => 'Str', required => 1;
 
+
+=attr type
+
+Link type. It can be:
+
+ - magnet
+ - torrent
+ - torrent-redirect (URL that do html/js redirect to a torrent file)
+ - direct
+
+=cut
+has type => is => 'ro', lazy => 1, builder => '_guess_type';
+
+sub _guess_type {
+    my $self = shift;
+
+    if ( $self->url =~ /magnet:/ ) {
+        return 'magnet';
+    }
+    elsif ( $self->url =~ /\.torrent$/ ) {
+        return 'torrent';
+    }
+    elsif ( $self->url =~ /bt-chat.com/ ) {
+        return 'torrent-redirect';
+    }
+
+    return 'direct';
+}
 1;
index 4b8761c..7ab346b 100644 (file)
@@ -4,7 +4,7 @@ with 'WWW::EZTV::UA';
 use WWW::EZTV::Link;
 use WWW::EZTV::Episode;
 
-# ABSTRACT: EZTV show object
+# ABSTRACT: Show object
 
 has title    => is => 'ro', isa => 'Str', required => 1;
 has name     => is => 'ro', lazy => 1, default => \&_name;
index 37d6a6e..ec2de31 100644 (file)
@@ -24,6 +24,10 @@ subtest 'Find episodes' => sub {
     diag( 'Version: ' . $ep->version );
     diag( 'Size:    ' . $ep->size );
     is( $ep->name, 'The Walking Dead', 'Name looks good' );
+
+    ok( $ep->has_links, 'Episode has links' );
+    ok( my $link = $ep->find_link(sub{ $_->type eq 'torrent' }), 'Find a torrent link' );
+    ok( $link->url, 'Link has URL' );
 };
 
 done_testing();