{{$NEXT}}
+ - Retrieve episode link by type (magnet, torrent, direct).
+
+0.02 2012-12-26 00:06:54 Europe/Madrid
+
- Better docs formatting
- Changes file :)
=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.
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';
}
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
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;
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;
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();