0f2ffa28ad10bb2086a1ec8aad18193aeefb5ee6
[cascardo/www-eztv.git] / lib / WWW / EZTV / Episode.pm
1 package WWW::EZTV::Episode;
2 use Moose;
3 with 'WWW::EZTV::UA';
4
5 # ABSTRACT: EZTV single episode
6
7 has show     => is => 'ro', isa => 'WWW::EZTV::Show', required => 1;
8 has title    => is => 'ro', isa => 'Str', required => 1;
9 has url      => is => 'ro', isa => 'Mojo::URL', required => 1;
10 has links    => is => 'rw';
11
12 has _parsed  => is => 'ro', lazy => 1, builder => '_parse';
13
14 has name     => is => 'ro', lazy => 1, 
15     default  => sub { shift->_parsed->{name} };
16
17 has season     => is => 'ro', lazy => 1, 
18     default  => sub { shift->_parsed->{season} };
19
20 has number     => is => 'ro', lazy => 1, 
21     default  => sub { shift->_parsed->{number} };
22
23 has version     => is => 'ro', lazy => 1, 
24     default  => sub { shift->_parsed->{version} };
25
26 has quality     => is => 'ro', lazy => 1, 
27     default  => sub { shift->_parsed->{quality} || 'standard' };
28
29 has size     => is => 'ro', lazy => 1,
30     default  => sub { shift->_parsed->{size} };
31
32 sub _parse {
33     my $title = shift->title;
34
35     $title =~ /^\s*
36       (?<name>.+?)
37       \s+
38       (?<chapter>
39         S (?<season>\d+) E (?<number>\d+)
40        |(?<season>\d+) x (?<number>\d+)
41        |(?<number>\d+) of (?<total>\d+)
42       )
43       \s+
44       (?<version>
45         ((?<quality>\d+p)\s+)?
46         (?<team>.*?)
47       )
48       (?: 
49         \s+
50         \((?<size> 
51           \d+ 
52           [^\)]+
53         )\) 
54       )?
55     \s*$/xi;
56
57     return {
58         name    => $+{name} || $title,
59         chapter => $+{chapter},
60         number  => $+{number} +0,
61         season  => ($+{season}||0) +0,
62         total   => ($+{total}||0) +0,
63         version => $+{version} || '',
64         quality => $+{quality} || 'standard',
65         team    => $+{team},
66         size    => $+{size}
67     };
68 }
69
70 1;