X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FHTML5Media.pm;h=1ac22f17c32675eb8cb569ee72c1121a98df73c6;hb=4cc79c77c904e9a8e5ff35ca872b7673b3c005c9;hp=7c2b174d923e6b0407d41d10d21a01ce20ced75d;hpb=3963740ee29000d1f3d9b82db23a71b69027fe20;p=koha.git diff --git a/C4/HTML5Media.pm b/C4/HTML5Media.pm index 7c2b174d92..1ac22f17c3 100644 --- a/C4/HTML5Media.pm +++ b/C4/HTML5Media.pm @@ -22,8 +22,7 @@ use warnings; use C4::Context; use MARC::Field; -use Koha::Upload; -use WWW::YouTube::Download qw(playback_url); +use Koha::UploadedFiles; =head1 HTML5Media @@ -99,16 +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 /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 @@ -131,10 +134,12 @@ sub gethtml5media { if ( $HTML5Media{srcblock} =~ /\Qopac-retrieve-file.pl\E/ ) { my ( undef, $id ) = split /id=/, $HTML5Media{srcblock}; next if !$id; - my $public = ( ( caller )[1] =~ /opac/ ) ? { public => 1 }: {}; - my $upl = Koha::Upload->new( $public )->get({ hashvalue => $id }); - next if !$upl || $upl->{name} !~ /\./; - $HTML5Media{extension} = ( $upl->{name} =~ m/([^.]+)$/ )[0]; + my %public = ( ( caller )[1] =~ /opac/ ) ? ( public => 1 ): (); + my $upload = Koha::UploadedFiles->search({ + hashvalue => $id, %public, + })->next; + next if !$upload || $upload->filename !~ /\./; + $HTML5Media{extension} = ( $upload->filename =~ m/([^.]+)$/ )[0]; } # check remote files else {