Bug 20783 - Cannot embed some YouTube videos due to 403 errors Sponsored-by: UCA - Universidad de Cádiz

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Bug 20783 - Cannot embed some YouTube videos due to 403 errors Sponsored-by: UCA - Universidad de Cádiz

Juan Romay Sieira
YouTube videos are embeded instead of played with its videoplayback URL, that can throw a 403 error
---
 C4/HTML5Media.pm                                   | 30 ++++++++++------------
 C4/Installer/PerlDependencies.pm                   |  6 ++---
 koha-tmpl/intranet-tmpl/prog/css/staff-global.css  |  5 ++++
 .../prog/en/modules/catalogue/detail.tt            | 12 ++++++---
 .../opac-tmpl/bootstrap/en/modules/opac-detail.tt  | 14 ++++++----
 koha-tmpl/opac-tmpl/bootstrap/less/opac.less       |  7 +++++
 6 files changed, 45 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 130740c..3240b3d 100644
--- a/C4/Installer/PerlDependencies.pm
+++ b/C4/Installer/PerlDependencies.pm
@@ -802,10 +802,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/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/css/staff-global.css
index c68bff6..d3231c0 100644
--- a/koha-tmpl/intranet-tmpl/prog/css/staff-global.css
+++ b/koha-tmpl/intranet-tmpl/prog/css/staff-global.css
@@ -2479,6 +2479,11 @@ video {
     width: 480px;
 }
 
+.html5-embed-video {
+ width: 480px;
+ height: 300px;
+}
+
 /* Bootstrap overrides */
 button,
 .btn {
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 ec6695c..ea76058 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt
@@ -795,10 +795,14 @@
 <div id="html5media">
           [% FOREACH HTML5MediaSet IN HTML5MediaSets %]
             <p>
-              <[% HTML5MediaParent %] controls preload=none>
-                <[% HTML5MediaSet.child  %] src="[% HTML5MediaSet.srcblock %]"[% HTML5MediaSet.typeblock %] />
-                [[% HTML5MediaParent %] tag not supported by your browser.]
-              </[% HTML5MediaParent %]>
+                [% IF (HTML5MediaSet.embed) %]
+                    [% HTML5MediaSet.embed %]
+                [% ELSE %]
+                    <[% HTML5MediaParent %] controls preload=none>
+                    <[% HTML5MediaSet.child  %] src="[% HTML5MediaSet.srcblock %]"[% HTML5MediaSet.typeblock %] />
+                    [[% HTML5MediaParent %] tag not supported by your browser.]
+                    </[% HTML5MediaParent %]>
+                [% END %]
             </p>
           [% END %]
 </div>
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 121fe6d..e2b105b 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt
@@ -1031,11 +1031,15 @@
                             <div id="html5media">
                               [% FOREACH HTML5MediaSet IN HTML5MediaSets %]
                                 <p>
-                                  [% SET ctrl_preload = ' controls preload=none' #translatability %]
-                                  <[% HTML5MediaParent _ ctrl_preload %] >
-                                    <[% HTML5MediaSet.child _ ' src="' _  HTML5MediaSet.srcblock _'"' _ HTML5MediaSet.typeblock %] />
-                                    <span>[[% HTML5MediaParent %] tag not supported by your browser.]</span>
-                                  </[% HTML5MediaParent %]>
+                                    [% IF (HTML5MediaSet.embed) %]
+                                        [% HTML5MediaSet.embed %]
+                                    [% ELSE %]
+                                        [% SET ctrl_preload = ' controls preload=none' #translatability %]
+                                        <[% HTML5MediaParent _ ctrl_preload %] >
+                                        <[% HTML5MediaSet.child _ ' src="' _  HTML5MediaSet.srcblock _'"' _ HTML5MediaSet.typeblock %] />
+                                        <span>[[% HTML5MediaParent %] tag not supported by your browser.]</span>
+                                        </[% HTML5MediaParent %]>
+                                    [% END %]
                                 </p>
                               [% END %]
                             </div>
diff --git a/koha-tmpl/opac-tmpl/bootstrap/less/opac.less b/koha-tmpl/opac-tmpl/bootstrap/less/opac.less
index 3cbfdb8..ed0b94d 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/less/opac.less
+++ b/koha-tmpl/opac-tmpl/bootstrap/less/opac.less
@@ -2636,6 +2636,13 @@ a.reviewlink:visited {
     }
 }
 
+video {
+    width: 480px;
+}
 
+.html5-embed-video {
+    width: 480px;
+    height: 300px;
+}
 
 @import "responsive.less";
--
2.1.4

_______________________________________________
Koha-patches mailing list
[hidden email]
http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-patches
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/