use C4::Context;
use MARC::Field;
-use Koha::Upload;
+use Koha::UploadedFiles;
=head1 HTML5Media
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 $isyoutube = 0;
my %HTML5Media;
# protocol
if ( $HTML5Media_field->indicator(1) eq '1' ) {
# 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
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 {