line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::VideoHost::Video; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$App::VideoHost::Video::VERSION = '0.143310'; # TRIAL |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Encapsulate a single video |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1109
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use File::Spec; |
10
|
|
|
|
|
|
|
use Carp qw/croak confess/; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'directory' => (is => 'rw'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub check { |
16
|
|
|
|
|
|
|
my $self = shift; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# XXX there is room for a lot of optimisation here! |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
die "no directory set\n" unless $self->directory; |
21
|
|
|
|
|
|
|
die "directory does not exist\n" unless -d $self->directory; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
die "video does not exist\n" unless -f $self->path_to('video'); |
24
|
|
|
|
|
|
|
die "video is empty\n" unless ! -z $self->path_to('video'); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
die "poster exists but is empty\n" if (-e $self->path_to('poster') && -z $self->path_to('poster')); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
die "tracks file exists but is empty\n" if (-e $self->path_to('tracks') && -z $self->path_to('tracks')); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
die "metadata file does not exist\n" unless (-e $self->path_to('metadata')); |
31
|
|
|
|
|
|
|
die "metadata file is empty\n" if (-z $self->path_to('metadata')); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
return 1; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub has_tracks { return -e shift->path_to('tracks') } |
37
|
|
|
|
|
|
|
sub has_poster { return -e shift->path_to('poster') } |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub short_name { my $title = shift->metadata('title'); $title = lc($title); $title =~ s/\W/-/g; $title =~ s/\-+$//g; return $title }; |
40
|
|
|
|
|
|
|
sub id { shift->short_name } |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub title { my $title = shift->metadata('title'); croak "no title" unless $title; return $title; } |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub file { return shift->path_to('video') } |
45
|
|
|
|
|
|
|
sub poster { return shift->path_to('poster') } |
46
|
|
|
|
|
|
|
sub tracks { return shift->path_to('tracks') } |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub metadata { |
50
|
|
|
|
|
|
|
my $self = shift; |
51
|
|
|
|
|
|
|
my $key = shift; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
open my $fh, "<", $self->path_to('metadata'); |
54
|
|
|
|
|
|
|
while (my $line = <$fh>) { |
55
|
|
|
|
|
|
|
chomp $line; |
56
|
|
|
|
|
|
|
my ($k, $v) = ($line =~ /^(\w+)\s*:\s*(.*?)$/); |
57
|
|
|
|
|
|
|
next unless $k; |
58
|
|
|
|
|
|
|
if ($k eq $key) { return $v } |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
return; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub path_to { |
64
|
|
|
|
|
|
|
my $self = shift; |
65
|
|
|
|
|
|
|
my $item = shift; |
66
|
|
|
|
|
|
|
confess "what do you mean to look for the path to?" unless $item; |
67
|
|
|
|
|
|
|
my $dir = $self->directory; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
if ($item eq 'video') { |
70
|
|
|
|
|
|
|
return File::Spec->catdir( $dir, 'video.mp4' ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
elsif ($item eq 'tracks') { |
73
|
|
|
|
|
|
|
return File::Spec->catdir( $dir, 'tracks.vtt' ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
elsif ($item eq 'poster') { |
76
|
|
|
|
|
|
|
return File::Spec->catdir( $dir, 'poster.jpg'); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
elsif ($item eq 'metadata') { |
79
|
|
|
|
|
|
|
return File::Spec->catdir( $dir, 'metadata.txt'); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
croak "do not know how to get path_to a $item"; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__END__ |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=pod |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=encoding UTF-8 |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 NAME |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
App::VideoHost::Video - Encapsulate a single video |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 VERSION |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
version 0.143310 |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SYNOPSIS |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# /foo/bar/baz contains video.mp4 and metadata.txt |
104
|
|
|
|
|
|
|
my $video = App::VideoHost::Video->new(directory => '/foo/bar/baz'); |
105
|
|
|
|
|
|
|
$video->check; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 METHODS |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 check |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Check this video for correct metadata. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Throws an exception if there is a problem with the video or it's related files. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 metadata |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Return the value for a given key for this L<App::VideoHost::Video> object. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 AUTHOR |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Justin Hawkins <justin@eatmorecode.com> |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Justin Hawkins. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
128
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |