From 938e24d65eacc53bb60c6496347baff3ab03ad0b Mon Sep 17 00:00:00 2001 From: Juan Romay Sieira Date: Fri, 18 May 2018 20:47:20 +0200 Subject: [PATCH] Bug 20783: Cannot embed some YouTube videos due to 403 errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit YouTube videos are embeded instead of played with its videoplayback URL, that can throw a 403 error To test the patch you have to: * Install a new package: HTML::Video::Embed * Rebuild the OPAC CSS (https://wiki.koha-community.org/wiki/Working_with_SCSS_in_the_OPAC_and_staff_client) * Enable the syspref HTML5MediaEnabled to some interface, and HTML5MediaYouTube to embed videos. * Edit a biblio and put some youtube video in a 856u field. * Check it in OPAC or INTRANET. The video https://www.youtube.com/watch?v=haT8g7oKnns can not be played before the patch, but after it has no problems. Sponsored-by: UCA - Universidad de Cádiz --- C4/HTML5Media.pm | 30 ++++++++++------------ C4/Installer/PerlDependencies.pm | 6 ++--- .../prog/en/modules/catalogue/detail.tt | 12 ++++++--- koha-tmpl/opac-tmpl/bootstrap/css/src/opac.scss | 9 +++++++ .../opac-tmpl/bootstrap/en/modules/opac-detail.tt | 14 ++++++---- 5 files changed, 42 insertions(+), 29 deletions(-) diff --git a/C4/HTML5Media.pm b/C4/HTML5Media.pm index 1ac22f1..af03bdb 100644 --- a/C4/HTML5Media.pm +++ b/C4/HTML5Media.pm @@ -50,7 +50,7 @@ sub gethtml5media { my @HTML5MediaExtensions = split( /\|/, C4::Context->preference("HTML5MediaExtensions") ); my $HTML5MediaYouTube = C4::Context->preference("HTML5MediaYouTube"); my $marcflavour = C4::Context->preference("marcflavour"); - my $isyoutube = 0; + my $is_embed = 0; foreach my $HTML5Media_field (@HTML5Media_fields) { my %HTML5Media; # protocol @@ -99,19 +99,19 @@ sub gethtml5media { if ( $HTML5Media_field->subfield('u') ) { $HTML5Media{srcblock} = $HTML5Media_field->subfield('u'); if (grep /youtu\.?be/, $HTML5Media_field->subfield('u') ) { + $HTML5Media{srcblock} = ""; if ($HTML5MediaYouTube == 1) { - require WWW::YouTube::Download; - import WWW::YouTube::Download qw(playback_url); - my $youtube = WWW::YouTube::Download->new; + use HTML::Video::Embed; + my $embedder = HTML::Video::Embed->new({ + class => 'html5-embed-video' + }); + 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 - } - ); + my $html_embed_code = $embedder->url_to_embed( $HTML5Media_field->subfield('u') ); + $HTML5Media{embed} = $html_embed_code; }; if ($@) { warn $@; } - else { $isyoutube = 1;} + else { $is_embed = 1;} } else { next; # do not embed youtube videos @@ -145,13 +145,9 @@ sub gethtml5media { else { $HTML5Media{extension} = ($HTML5Media{srcblock} =~ m/([^.]+)$/)[0]; } - if ( ( !grep /\Q$HTML5Media{extension}\E/, @HTML5MediaExtensions ) && ( $isyoutube != 1) ) { + if ( ( !grep /\Q$HTML5Media{extension}\E/, @HTML5MediaExtensions ) && ( $is_embed != 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'); @@ -222,7 +218,7 @@ sub gethtml5media { $HTML5Media{type} = 'track'; } # push - if ( $HTML5Media{srcblock} && $HTML5Media{type} ) { + if ( ($HTML5Media{srcblock} && $HTML5Media{type}) || $HTML5Media{embed} ) { push (@HTML5Media_sets, \%HTML5Media); } } @@ -252,7 +248,7 @@ sub gethtml5media { } return ( - HTML5MediaEnabled => ( (scalar(@HTML5Media_sets) > 0) && ($HTML5MediaParent) ), + HTML5MediaEnabled => ( (scalar(@HTML5Media_sets) > 0 && $HTML5MediaParent) || $is_embed ), HTML5MediaSets => \@HTML5Media_sets, HTML5MediaParent => $HTML5MediaParent, HTML5MediaWidth => $HTML5MediaWidth, diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index 2525a6b..ff1e2b5 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -782,10 +782,10 @@ our $PERL_DEPS = { 'required' => '1', 'min_ver' => '1.10', }, - 'WWW::YouTube::Download' => { - 'usage' => 'HTML5Media streaming from YouTube', + 'HTML::Video::Embed' => { + 'usage' => 'Convert a url into a html embed string', 'required' => '0', - 'min_ver' => '0.56', + 'min_ver' => '0.016000', }, 'Net::SFTP::Foreign' => { 'usage' => 'Edifact', diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 4dddbe4..f1e4294 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -828,10 +828,14 @@
[% FOREACH HTML5MediaSet IN HTML5MediaSets %]

- <[% HTML5MediaParent | html %] controls preload=none> - <[% HTML5MediaSet.child | html %] src="[% HTML5MediaSet.srcblock | html %]"[% HTML5MediaSet.typeblock | html %] /> - [[% HTML5MediaParent | html %] tag not supported by your browser.] - + [% IF (HTML5MediaSet.embed) %] + [% HTML5MediaSet.embed %] + [% ELSE %] + <[% HTML5MediaParent | html %] controls preload=none> + <[% HTML5MediaSet.child | html %] src="[% HTML5MediaSet.srcblock | html %]"[% HTML5MediaSet.typeblock | html %] /> + [[% HTML5MediaParent | html %] tag not supported by your browser.] + + [% END %]

[% END %]
diff --git a/koha-tmpl/opac-tmpl/bootstrap/css/src/opac.scss b/koha-tmpl/opac-tmpl/bootstrap/css/src/opac.scss index c5075d5..b759e9c 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/css/src/opac.scss +++ b/koha-tmpl/opac-tmpl/bootstrap/css/src/opac.scss @@ -3016,4 +3016,13 @@ button.closebtn { } } ++video { + width: 480px; +} + +.html5-embed-video { + width: 480px; + height: 300px; +} + @import "responsive"; diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt index 5decf72..8ec729d 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -1003,11 +1003,15 @@
[% FOREACH HTML5MediaSet IN HTML5MediaSets %]

- [% SET ctrl_preload = ' controls preload=none' #translatability %] - <[% HTML5MediaParent _ ctrl_preload | html %] > - <[% HTML5MediaSet.child | html %] src="[% HTML5MediaSet.srcblock | html %]"[% HTML5MediaSet.typeblock | html %] /> - [[% HTML5MediaParent | html %] tag not supported by your browser.] - + [% IF (HTML5MediaSet.embed) %] + [% HTML5MediaSet.embed %] + [% ELSE %] + [% SET ctrl_preload = ' controls preload=none' #translatability %] + <[% HTML5MediaParent _ ctrl_preload | html %] > + <[% HTML5MediaSet.child | html %] src="[% HTML5MediaSet.srcblock | html %]"[% HTML5MediaSet.typeblock | html %] /> + [[% HTML5MediaParent | html %] tag not supported by your browser.] + + [% END %]

[% END %]
-- 2.1.4