From 8159bd4c689fe28e993d68269ba3979805827a2f Mon Sep 17 00:00:00 2001 From: Mirko Tietgen Date: Thu, 22 Oct 2015 19:39:37 +0200 Subject: [PATCH] [SIGNED-OFF] 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 Works perfectly! Signed-off-by: Nicole C Engard --- C4/HTML5Media.pm | 28 +++++++++++++++++++--- C4/Installer/PerlDependencies.pm | 5 ++++ installer/data/mysql/sysprefs.sql | 1 + .../admin/preferences/enhanced_content.pref | 6 +++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/C4/HTML5Media.pm b/C4/HTML5Media.pm index a53922e..1094aa9 100644 --- a/C4/HTML5Media.pm +++ b/C4/HTML5Media.pm @@ -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'; diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index d621f33..32a0e6c 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -822,6 +822,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; diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 96ea9ad..770bed1 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -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'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref index 1e68153..8b8ca2b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/enhanced_content.pref @@ -319,6 +319,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 -- 2.1.4