Bug 17231 - HTML5MediaYouTube should recognize youtu.be links from youtube as well at the full links

To test:
Enable HTML5MediaYouTube and ensure WWW::YouTube::Download is installed
Add an 856$u to a record like: https://www.youtube.com/watch?v=tu0qtEwb9gE
Verify you can see the embedded player
Use the youtube shortened like (from the share button) like:
https://youtu.be/tu0qtEwb9gE
Verify you can see the embedded player

Signed-off-by: Claire Gravely <claire_gravely@hotmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Nick Clemens 2016-08-31 17:37:56 +00:00 committed by Kyle M Hall
parent eab75d0aa4
commit b1dc5092d8
1 changed files with 10 additions and 8 deletions

View File

@ -98,18 +98,20 @@ sub gethtml5media {
# src
if ( $HTML5Media_field->subfield('u') ) {
$HTML5Media{srcblock} = $HTML5Media_field->subfield('u');
if (grep /youtube/, $HTML5Media_field->subfield('u') ) { # TODO is there an official YT URL shortener? Can we use that too?
if (grep /youtube|youtu[.]be/, $HTML5Media_field->subfield('u') ) {
if ($HTML5MediaYouTube == 1) {
require WWW::YouTube::Download;
import WWW::YouTube::Download qw(playback_url);
my $youtube = WWW::YouTube::Download->new;
$HTML5Media{srcblock} = $youtube->playback_url(
$HTML5Media_field->subfield('u'), {
'fmt' => '43' #webm is the only format compatible to all modern browsers. maybe check for available qualities
}
);
# TODO handle error if format not available. Does that ever occur?
$isyoutube = 1;
eval {
$HTML5Media{srcblock} = $youtube->playback_url(
$HTML5Media_field->subfield('u'), {
'fmt' => '43' #webm is the only format compatible to all modern browsers. maybe check for available qualities
}
);
};
if ($@) { warn $@; }
else { $isyoutube = 1;}
}
else {
next; # do not embed youtube videos