line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Statocles::Plugin::VideoTag; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GENE'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Change video file anchors to video elements |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.0300'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
631
|
use Statocles::Base 'Class'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
9
|
|
|
|
|
|
|
with 'Statocles::Plugin'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has file_type => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
isa => Str, |
15
|
|
|
|
|
|
|
default => sub { 'mp4' }, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has width => ( |
20
|
|
|
|
|
|
|
is => 'ro', |
21
|
|
|
|
|
|
|
isa => Int, |
22
|
|
|
|
|
|
|
default => sub { 560 }, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has height => ( |
27
|
|
|
|
|
|
|
is => 'ro', |
28
|
|
|
|
|
|
|
isa => Int, |
29
|
|
|
|
|
|
|
default => sub { 315 }, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has frameborder => ( |
34
|
|
|
|
|
|
|
is => 'ro', |
35
|
|
|
|
|
|
|
isa => Int, |
36
|
|
|
|
|
|
|
default => sub { 0 }, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has allow => ( |
41
|
|
|
|
|
|
|
is => 'ro', |
42
|
|
|
|
|
|
|
isa => Str, |
43
|
|
|
|
|
|
|
default => sub { 'accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture' }, |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has allowfullscreen => ( |
48
|
|
|
|
|
|
|
is => 'ro', |
49
|
|
|
|
|
|
|
isa => Int, |
50
|
|
|
|
|
|
|
default => sub { 1 }, |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub video_tag { |
55
|
2
|
|
|
2
|
1
|
938918
|
my ($self, $page) = @_; |
56
|
2
|
50
|
|
|
|
14
|
if ($page->has_dom) { |
57
|
2
|
100
|
|
|
|
17
|
if ($self->file_type eq 'youtu') { |
58
|
|
|
|
|
|
|
$page->dom->find('a[href*="'. $self->file_type .'"]')->each(sub { |
59
|
1
|
|
|
1
|
|
2469
|
my ($el) = @_; |
60
|
1
|
|
|
|
|
5
|
my $href = $el->attr('href'); |
61
|
1
|
|
|
|
|
20
|
$href =~ s/watch\?v=(.+)$/embed\/$1/; |
62
|
1
|
50
|
|
|
|
16
|
my $replacement = sprintf '<iframe width="%d" height="%d" src="%s" frameborder="%d" allow="%s" %s></iframe>', |
63
|
|
|
|
|
|
|
$self->width, $self->height, |
64
|
|
|
|
|
|
|
$href, |
65
|
|
|
|
|
|
|
$self->frameborder, |
66
|
|
|
|
|
|
|
$self->allow, |
67
|
|
|
|
|
|
|
$self->allowfullscreen ? 'allowfullscreen' : ''; |
68
|
1
|
|
|
|
|
4
|
$el->replace($replacement); |
69
|
1
|
|
|
|
|
17
|
}); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else { |
72
|
|
|
|
|
|
|
$page->dom->find('a[href$=.'. $self->file_type .']')->each(sub { |
73
|
1
|
|
|
1
|
|
4223
|
my ($el) = @_; |
74
|
1
|
|
|
|
|
9
|
my $replacement = sprintf '<video controls><source type="video/%s" src="%s"></video>', |
75
|
|
|
|
|
|
|
$self->file_type, $el->attr('href'); |
76
|
1
|
|
|
|
|
23
|
$el->replace($replacement); |
77
|
1
|
|
|
|
|
20
|
}); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
2
|
|
|
|
|
621
|
return $page; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub register { |
85
|
0
|
|
|
0
|
1
|
|
my ($self, $site) = @_; |
86
|
|
|
|
|
|
|
$site->on(build => sub { |
87
|
0
|
|
|
0
|
|
|
my ($event) = @_; |
88
|
0
|
|
|
|
|
|
for my $page (@{ $event->pages }) { |
|
0
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
$page = $self->video_tag($page); |
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
|
}); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=pod |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=encoding UTF-8 |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 NAME |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Statocles::Plugin::VideoTag - Change video file anchors to video elements |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 VERSION |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
version 0.0300 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 SYNOPSIS |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# site.yml |
113
|
|
|
|
|
|
|
site: |
114
|
|
|
|
|
|
|
class: Statocles::Site |
115
|
|
|
|
|
|
|
args: |
116
|
|
|
|
|
|
|
plugins: |
117
|
|
|
|
|
|
|
video_tag: |
118
|
|
|
|
|
|
|
$class: Statocles::Plugin::VideoTag |
119
|
|
|
|
|
|
|
$args: |
120
|
|
|
|
|
|
|
file_type: 'youtu' |
121
|
|
|
|
|
|
|
width: 500 |
122
|
|
|
|
|
|
|
height: 300 |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 DESCRIPTION |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
C<Statocles::Plugin::VideoTag> changes video file anchor elements to |
127
|
|
|
|
|
|
|
video elements. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 file_type |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
The file type to replace. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Default: C<mp4> |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 width |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Width of the iframe for an embedded YouTube video. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Default: C<560> |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 height |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Height of the iframe for an embedded YouTube video. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Default: C<315> |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 frameborder |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Whether to have a frameborder on the iframe for a YouTube video. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Default: C<0> |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 allow |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
The iframe B<allow> attribute string for a YouTube video. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Default: C<accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture> |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 allowfullscreen |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Whether to allow full-screen for the iframe for a YouTube video. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Default: C<1> |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 METHODS |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head2 video_tag |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
$page = $plugin->video_tag($page); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Process the video bits of a L<Statocles::Page>. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
If the B<file_type> is given as C<youtu>, YouTube links of this exact |
176
|
|
|
|
|
|
|
form will be converted to an embedded iframe: |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
https://www.youtube.com/watch?v=abcdefg1234567 |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Where the C<abcdefg1234567> is a placeholder for the actual video. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
* Currently, including a start time (e.g. C<&t=42>) in the link is not |
183
|
|
|
|
|
|
|
honored. In fact including any argument other than C<v> will not |
184
|
|
|
|
|
|
|
render the embedded video correctly at this time... |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 register |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Register this plugin to install its event handlers. Called automatically. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 SEE ALSO |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
L<Statocles> |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
L<Statocles::Plugin> |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
L<Statocles::Plugin::AudioTag> |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
L<https://ology.github.io/2020/12/06/making-a-statocles-plugin/> |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head1 AUTHOR |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Gene Boggs <gene@cpan.org> |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
This software is copyright (c) 2021 by Gene Boggs. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
209
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=cut |