PageRenderTime 78ms CodeModel.GetById 22ms app.highlight 13ms RepoModel.GetById 33ms app.codeStats 0ms

/lib/Teto/Track/NicoVideo/sm.pm

http://github.com/motemen/Teto
Perl | 30 lines | 23 code | 7 blank | 0 comment | 1 complexity | eda6f334fcb9c77c67bc5a0c9a45ef27 MD5 | raw file
 1package Teto::Track::NicoVideo::sm;
 2use Mouse;
 3
 4extends 'Teto::Track::NicoVideo';
 5
 6override buildargs_from_url => sub {
 7    my ($class, $url) = @_;
 8    $url =~ m<^http://(?:\w+\.nicovideo\.jp/watch|nico\.ms)/(sm\d+)> or return undef;
 9    return { video_id => $1 };
10};
11
12override _play => sub {
13    my $self = shift;
14    my $media_url = $self->media_url or return;
15    my $fh = $self->url_to_fh($media_url);
16    $self->ffmpeg($fh);
17};
18
19after done => sub {
20    my $self = shift;
21    if (my $e = $self->error) {
22        $self->sleep($e =~ /403/ ? 30 : 10);
23    }
24};
25
26__PACKAGE__->meta->make_immutable;
27
28no Mouse;
29
301;