Lines 1-6
Link Here
|
1 |
package C4::HTML5Media; |
1 |
package C4::HTML5Media; |
2 |
|
2 |
|
3 |
# Copyright 2012 Mirko Tietgen |
3 |
# Copyright 2012/2015 Mirko Tietgen |
4 |
# |
4 |
# |
5 |
# This file is part of Koha. |
5 |
# This file is part of Koha. |
6 |
# |
6 |
# |
Lines 22-28
use warnings;
Link Here
|
22 |
|
22 |
|
23 |
use C4::Context; |
23 |
use C4::Context; |
24 |
use MARC::Field; |
24 |
use MARC::Field; |
25 |
|
25 |
use WWW::YouTube::Download qw(playback_url); |
26 |
|
26 |
|
27 |
=head1 HTML5Media |
27 |
=head1 HTML5Media |
28 |
|
28 |
|
Lines 48-54
sub gethtml5media {
Link Here
|
48 |
my $HTML5MediaParent; |
48 |
my $HTML5MediaParent; |
49 |
my $HTML5MediaWidth; |
49 |
my $HTML5MediaWidth; |
50 |
my @HTML5MediaExtensions = split( /\|/, C4::Context->preference("HTML5MediaExtensions") ); |
50 |
my @HTML5MediaExtensions = split( /\|/, C4::Context->preference("HTML5MediaExtensions") ); |
|
|
51 |
my $HTML5MediaYouTube = C4::Context->preference("HTML5MediaYouTube"); |
51 |
my $marcflavour = C4::Context->preference("marcflavour"); |
52 |
my $marcflavour = C4::Context->preference("marcflavour"); |
|
|
53 |
my $isyoutube = 0; |
52 |
foreach my $HTML5Media_field (@HTML5Media_fields) { |
54 |
foreach my $HTML5Media_field (@HTML5Media_fields) { |
53 |
my %HTML5Media; |
55 |
my %HTML5Media; |
54 |
# protocol |
56 |
# protocol |
Lines 96-118
sub gethtml5media {
Link Here
|
96 |
# src |
98 |
# src |
97 |
if ( $HTML5Media_field->subfield('u') ) { |
99 |
if ( $HTML5Media_field->subfield('u') ) { |
98 |
$HTML5Media{srcblock} = $HTML5Media_field->subfield('u'); |
100 |
$HTML5Media{srcblock} = $HTML5Media_field->subfield('u'); |
|
|
101 |
if (grep /youtube/, $HTML5Media_field->subfield('u') ) { # TODO is there an official YT URL shortener? Can we use that too? |
102 |
if ($HTML5MediaYouTube == 1) { |
103 |
my $youtube = WWW::YouTube::Download->new; |
104 |
$HTML5Media{srcblock} = $youtube->playback_url( |
105 |
$HTML5Media_field->subfield('u'), { |
106 |
'fmt' => '43' #webm is the only format compatible to all modern browsers. maybe check for available qualities |
107 |
} |
108 |
); |
109 |
# TODO handle error if format not availabe. Does that ever occur? |
110 |
$isyoutube = 1; |
111 |
} |
112 |
else { |
113 |
next; # do not embed youtube videos |
114 |
} |
115 |
} |
99 |
} |
116 |
} |
100 |
elsif ( $HTML5Media_field->subfield('a') && $HTML5Media_field->subfield('d') && $HTML5Media_field->subfield('f') ) { |
117 |
elsif ( $HTML5Media_field->subfield('a') && $HTML5Media_field->subfield('d') && $HTML5Media_field->subfield('f') ) { |
101 |
$HTML5Media{host} = $HTML5Media_field->subfield('a'); |
118 |
$HTML5Media{host} = $HTML5Media_field->subfield('a'); |
102 |
$HTML5Media{host} =~ s/(^\/|\/$)//g; |
119 |
$HTML5Media{host} =~ s/(^\/|\/$)//g; |
103 |
$HTML5Media{path} = $HTML5Media_field->subfield('d'); |
120 |
$HTML5Media{path} = $HTML5Media_field->subfield('d'); |
104 |
$HTML5Media{path} =~ s/(^\/|\/$)//g; |
121 |
$HTML5Media{path} =~ s/(^\/|\/$)//g; # TODO we could check for youtube here too, but nobody uses these fields anyway… |
105 |
$HTML5Media{file} = $HTML5Media_field->subfield('f'); |
122 |
$HTML5Media{file} = $HTML5Media_field->subfield('f'); |
106 |
$HTML5Media{srcblock} = $HTML5Media{protocol} . '://' . $HTML5Media{loginblock} . $HTML5Media{host} . $HTML5Media{portblock} . '/' . $HTML5Media{path} . '/' . $HTML5Media{file}; |
123 |
$HTML5Media{srcblock} = $HTML5Media{protocol} . '://' . $HTML5Media{loginblock} . $HTML5Media{host} . $HTML5Media{portblock} . '/' . $HTML5Media{path} . '/' . $HTML5Media{file}; |
107 |
} |
124 |
} |
108 |
else { |
125 |
else { |
109 |
next; # no file to play |
126 |
next; # no file to play |
110 |
} |
127 |
} |
111 |
# extension |
128 |
# extension or youtube |
112 |
$HTML5Media{extension} = ($HTML5Media{srcblock} =~ m/([^.]+)$/)[0]; |
129 |
$HTML5Media{extension} = ($HTML5Media{srcblock} =~ m/([^.]+)$/)[0]; |
113 |
if ( !grep /\Q$HTML5Media{extension}\E/, @HTML5MediaExtensions ) { |
130 |
if ( ( !grep /\Q$HTML5Media{extension}\E/, @HTML5MediaExtensions ) && ( $isyoutube != 1) ) { |
114 |
next; # not a specified media file |
131 |
next; # not a specified media file |
115 |
} |
132 |
} |
|
|
133 |
# youtube |
134 |
if ($isyoutube == 1) { |
135 |
$HTML5Media{mime} = 'video/webm'; |
136 |
} |
116 |
# mime |
137 |
# mime |
117 |
if ( $HTML5Media_field->subfield('c') ) { |
138 |
if ( $HTML5Media_field->subfield('c') ) { |
118 |
$HTML5Media{codecs} = $HTML5Media_field->subfield('c'); |
139 |
$HTML5Media{codecs} = $HTML5Media_field->subfield('c'); |
Lines 144-150
sub gethtml5media {
Link Here
|
144 |
} |
165 |
} |
145 |
if ( $HTML5Media{extension} eq 'oga' ) { |
166 |
if ( $HTML5Media{extension} eq 'oga' ) { |
146 |
$HTML5Media{mime} = 'audio/ogg'; |
167 |
$HTML5Media{mime} = 'audio/ogg'; |
147 |
$HTML5Media{codecs} = 'vorbis'; |
168 |
$HTML5Media{codecs} = 'vorbis'; |
148 |
} |
169 |
} |
149 |
elsif ( $HTML5Media{extension} eq 'spx' ) { |
170 |
elsif ( $HTML5Media{extension} eq 'spx' ) { |
150 |
$HTML5Media{mime} = 'audio/ogg'; |
171 |
$HTML5Media{mime} = 'audio/ogg'; |