Bug 14168 - enhance streaming cataloging to include youtube

Add optional embedding of YouTube videos via HTML5Media.
New syspref: HTML5MediaYouTube: Embed/Don't embed videos.
Format WEBM is hardcoded as it is the only format accepted by all
modern browsers.

Test plan:
- apply patch
- catalogue a YouTube link in 856$u
- turn on HTML5MediaEnabled and HTML5MediaYouTube
- open the record in OPAC and staff client, check that the
  'Play media' tab is showing and playing the video works.

Possible enhancements for followups:
- check available formats, offer quality choice
- accept official YT URL shortener

Signed-off-by: Aleisha <aleishaamohia@hotmail.com>
Works perfectly!

Signed-off-by: Nicole C Engard <nengard@bywatersolutions.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com
This commit is contained in:
Mirko Tietgen 2015-10-22 19:39:37 +02:00 committed by Brendan Gallagher
parent d9dc15f21e
commit f3e1e49797
4 changed files with 37 additions and 3 deletions

View File

@ -23,6 +23,7 @@ use warnings;
use C4::Context;
use MARC::Field;
use Koha::Upload;
use WWW::YouTube::Download qw(playback_url);
=head1 HTML5Media
@ -48,7 +49,9 @@ sub gethtml5media {
my $HTML5MediaParent;
my $HTML5MediaWidth;
my @HTML5MediaExtensions = split( /\|/, C4::Context->preference("HTML5MediaExtensions") );
my $HTML5MediaYouTube = C4::Context->preference("HTML5MediaYouTube");
my $marcflavour = C4::Context->preference("marcflavour");
my $isyoutube = 0;
foreach my $HTML5Media_field (@HTML5Media_fields) {
my %HTML5Media;
# protocol
@ -96,12 +99,27 @@ 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 ($HTML5MediaYouTube == 1) {
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 availabe. Does that ever occur?
$isyoutube = 1;
}
else {
next; # do not embed youtube videos
}
}
}
elsif ( $HTML5Media_field->subfield('a') && $HTML5Media_field->subfield('d') && $HTML5Media_field->subfield('f') ) {
$HTML5Media{host} = $HTML5Media_field->subfield('a');
$HTML5Media{host} =~ s/(^\/|\/$)//g;
$HTML5Media{path} = $HTML5Media_field->subfield('d');
$HTML5Media{path} =~ s/(^\/|\/$)//g;
$HTML5Media{path} =~ s/(^\/|\/$)//g; # TODO we could check for youtube here too, but nobody uses these fields anyway…
$HTML5Media{file} = $HTML5Media_field->subfield('f');
$HTML5Media{srcblock} = $HTML5Media{protocol} . '://' . $HTML5Media{loginblock} . $HTML5Media{host} . $HTML5Media{portblock} . '/' . $HTML5Media{path} . '/' . $HTML5Media{file};
}
@ -122,9 +140,13 @@ sub gethtml5media {
else {
$HTML5Media{extension} = ($HTML5Media{srcblock} =~ m/([^.]+)$/)[0];
}
if ( !grep /\Q$HTML5Media{extension}\E/, @HTML5MediaExtensions ) {
if ( ( !grep /\Q$HTML5Media{extension}\E/, @HTML5MediaExtensions ) && ( $isyoutube != 1) ) {
next; # not a specified media file
}
# youtube
if ($isyoutube == 1) {
$HTML5Media{mime} = 'video/webm';
}
# mime
if ( $HTML5Media_field->subfield('c') ) {
$HTML5Media{codecs} = $HTML5Media_field->subfield('c');
@ -156,7 +178,7 @@ sub gethtml5media {
}
if ( $HTML5Media{extension} eq 'oga' ) {
$HTML5Media{mime} = 'audio/ogg';
$HTML5Media{codecs} = 'vorbis';
$HTML5Media{codecs} = 'vorbis';
}
elsif ( $HTML5Media{extension} eq 'spx' ) {
$HTML5Media{mime} = 'audio/ogg';

View File

@ -782,6 +782,11 @@ our $PERL_DEPS = {
'required' => '0',
'min_ver' => '0.03',
},
'WWW::YouTube::Download' => {
'usage' => 'HTML5Media streaming from YouTube',
'required' => '0',
'min_ver' => '0.56',
},
};
1;

View File

@ -163,6 +163,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
('HomeOrHoldingBranch','holdingbranch','holdingbranch|homebranch','Used by Circulation to determine which branch of an item to check with independent branches on, and by search to determine which branch to choose for availability ','Choice'),
('HTML5MediaEnabled','not','not|opac|staff|both','Show a tab with a HTML5 media player for files catalogued in field 856','Choice'),
('HTML5MediaExtensions','webm|ogg|ogv|oga|vtt','','Media file extensions','free'),
('HTML5MediaYouTube',0','Embed|Don\'t embed','YouTube links as videos','YesNo'),
('IDreamBooksReadometer','0','','Display Readometer from IDreamBooks.com','YesNo'),
('IDreamBooksResults','0','','Display IDreamBooks.com rating in search results','YesNo'),
('IDreamBooksReviews','0','','Display book review snippets from IDreamBooks.com','YesNo'),

View File

@ -325,6 +325,12 @@ Enhanced Content:
- pref: HTML5MediaExtensions
class: multi
- (separated with |).
-
- pref: HTML5MediaYouTube
choices:
yes: "Embed"
no: "Don't embed"
- YouTube links as videos.
Plugins:
-
- pref: UseKohaPlugins