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