Lines 51-57
sub gethtml5media {
Link Here
|
51 |
my $HTML5MediaYouTube = C4::Context->preference("HTML5MediaYouTube"); |
51 |
my $HTML5MediaYouTube = C4::Context->preference("HTML5MediaYouTube"); |
52 |
my $marcflavour = C4::Context->preference("marcflavour"); |
52 |
my $marcflavour = C4::Context->preference("marcflavour"); |
53 |
foreach my $HTML5Media_field (@HTML5Media_fields) { |
53 |
foreach my $HTML5Media_field (@HTML5Media_fields) { |
54 |
my $isyoutube = 0; |
54 |
my $is_youtube = 0; |
55 |
my %HTML5Media; |
55 |
my %HTML5Media; |
56 |
# protocol |
56 |
# protocol |
57 |
if ( $HTML5Media_field->indicator(1) eq '1' ) { |
57 |
if ( $HTML5Media_field->indicator(1) eq '1' ) { |
Lines 100-117
sub gethtml5media {
Link Here
|
100 |
$HTML5Media{srcblock} = $HTML5Media_field->subfield('u'); |
100 |
$HTML5Media{srcblock} = $HTML5Media_field->subfield('u'); |
101 |
if (grep /youtu\.?be/, $HTML5Media_field->subfield('u') ) { |
101 |
if (grep /youtu\.?be/, $HTML5Media_field->subfield('u') ) { |
102 |
if ($HTML5MediaYouTube == 1) { |
102 |
if ($HTML5MediaYouTube == 1) { |
103 |
require WWW::YouTube::Download; |
103 |
my $url = $HTML5Media_field->subfield('u'); |
104 |
import WWW::YouTube::Download qw(playback_url); |
104 |
# Credit for regex goes to https://stackoverflow.com/questions/3452546/how-do-i-get-the-youtube-video-id-from-a-url |
105 |
my $youtube = WWW::YouTube::Download->new; |
105 |
next unless $url =~ m{^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*}; |
106 |
eval { |
106 |
my $video_id = $2; |
107 |
$HTML5Media{srcblock} = $youtube->playback_url( |
107 |
next unless length($video_id) == 11; # Youtube video ids are 11 chars length |
108 |
$HTML5Media_field->subfield('u'), { |
108 |
$HTML5Media{srcblock} = sprintf '%s://www.youtube.com/embed/%s', $HTML5Media{protocol}, $video_id; |
109 |
'fmt' => '43' #webm is the only format compatible to all modern browsers. maybe check for available qualities |
109 |
$HTML5Media{is_youtube} = 1; |
110 |
} |
110 |
$is_youtube = 1; |
111 |
); |
|
|
112 |
}; |
113 |
if ($@) { warn $@; } |
114 |
else { $isyoutube = 1;} |
115 |
} |
111 |
} |
116 |
else { |
112 |
else { |
117 |
next; # do not embed youtube videos |
113 |
next; # do not embed youtube videos |
Lines 145-156
sub gethtml5media {
Link Here
|
145 |
else { |
141 |
else { |
146 |
$HTML5Media{extension} = ($HTML5Media{srcblock} =~ m/([^.]+)$/)[0]; |
142 |
$HTML5Media{extension} = ($HTML5Media{srcblock} =~ m/([^.]+)$/)[0]; |
147 |
} |
143 |
} |
148 |
if ( ( !grep /\Q$HTML5Media{extension}\E/, @HTML5MediaExtensions ) && ( $isyoutube != 1) ) { |
144 |
if ( ( !grep /\Q$HTML5Media{extension}\E/, @HTML5MediaExtensions ) && ( $is_youtube != 1) ) { |
149 |
next; # not a specified media file |
145 |
next; # not a specified media file |
150 |
} |
146 |
} |
151 |
# youtube |
147 |
# youtube |
152 |
if ($isyoutube == 1) { |
148 |
if ($is_youtube == 1) { |
153 |
$HTML5Media{mime} = 'video/webm'; |
149 |
$HTML5Media{mime} = 'video/webm'; |
|
|
150 |
$HTML5Media{type} = 'video'; |
154 |
} |
151 |
} |
155 |
# mime |
152 |
# mime |
156 |
if ( $HTML5Media_field->subfield('c') ) { |
153 |
if ( $HTML5Media_field->subfield('c') ) { |