1 package C4
::HTML5Media
;
3 # Copyright 2012 Mirko Tietgen
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
33 This module gets the relevant data from field 856 (MARC21/UNIMARC) to create a HTML5 audio or video element containing the file(s) catalogued in 856.
39 Get all relevant data from field 856. Takes a $record in the subroutine call, sets appropriate params.
46 my @HTML5Media_sets = ();
47 my @HTML5Media_fields = $record->field(856);
50 my @HTML5MediaExtensions = split( /\|/, C4
::Context
->preference("HTML5MediaExtensions") );
51 my $marcflavour = C4
::Context
->preference("marcflavour");
52 foreach my $HTML5Media_field (@HTML5Media_fields) {
55 if ( $HTML5Media_field->indicator(1) eq '1' ) {
56 $HTML5Media{protocol
} = 'ftp';
58 elsif ( $HTML5Media_field->indicator(1) eq '4' ) {
59 $HTML5Media{protocol
} = 'http';
61 elsif ( $HTML5Media_field->indicator(1) eq '7' ) {
62 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC') {
63 $HTML5Media{protocol
} = $HTML5Media_field->subfield('2');
65 elsif ($marcflavour eq 'UNIMARC') {
66 $HTML5Media{protocol
} = $HTML5Media_field->subfield('y');
70 $HTML5Media{protocol
} = 'http';
73 if ( $HTML5Media_field->subfield('l') ) {
74 $HTML5Media{username
} = $HTML5Media_field->subfield('l'); # yes, that is arbitrary if h and l are not the same. originally i flipped a coin in that case.
76 elsif ( $HTML5Media_field->subfield('h') ) {
77 $HTML5Media{username
} = $HTML5Media_field->subfield('h');
80 if ( $HTML5Media{username
} && $HTML5Media_field->subfield('k') ) {
81 $HTML5Media{loginblock
} = $HTML5Media{username
} . ':' . $HTML5Media_field->subfield('k') . '@';
83 elsif ( $HTML5Media{username
} ) {
84 $HTML5Media{loginblock
} = $HTML5Media{username
} . '@';
87 $HTML5Media{loginblock
} = '';
90 if ( $HTML5Media_field->subfield('p') ) {
91 $HTML5Media{portblock
} = ':' . $HTML5Media_field->subfield('k');
94 $HTML5Media{portblock
} = '';
97 if ( $HTML5Media_field->subfield('u') ) {
98 $HTML5Media{srcblock
} = $HTML5Media_field->subfield('u');
100 elsif ( $HTML5Media_field->subfield('a') && $HTML5Media_field->subfield('d') && $HTML5Media_field->subfield('f') ) {
101 $HTML5Media{host
} = $HTML5Media_field->subfield('a');
102 $HTML5Media{host
} =~ s/(^\/|\/$)//g;
103 $HTML5Media{path
} = $HTML5Media_field->subfield('d');
104 $HTML5Media{path
} =~ s/(^\/|\/$)//g;
105 $HTML5Media{file
} = $HTML5Media_field->subfield('f');
106 $HTML5Media{srcblock
} = $HTML5Media{protocol
} . '://' . $HTML5Media{loginblock
} . $HTML5Media{host
} . $HTML5Media{portblock
} . '/' . $HTML5Media{path
} . '/' . $HTML5Media{file
};
109 next; # no file to play
112 $HTML5Media{extension
} = ($HTML5Media{srcblock
} =~ m/([^.]+)$/)[0];
113 if ( !grep /$HTML5Media{extension}/, @HTML5MediaExtensions ) {
114 next; # not a specified media file
117 if ( $HTML5Media_field->subfield('c') ) {
118 $HTML5Media{codecs
} = $HTML5Media_field->subfield('c');
121 if ( $HTML5Media_field->subfield('q') ) {
122 $HTML5Media{mime
} = $HTML5Media_field->subfield('q');
124 ### …or from file extension and codecs…
125 elsif ( $HTML5Media{codecs
} ) {
126 if ( $HTML5Media{codecs
} =~ /theora.*vorbis/ ) {
127 $HTML5Media{mime
} = 'video/ogg';
129 elsif ( $HTML5Media{codecs
} =~ /vp8.*vorbis/ ) {
130 $HTML5Media{mime
} = 'video/webm';
132 elsif ( ($HTML5Media{codecs
} =~ /^vorbis$/) && ($HTML5Media{extension
} eq 'ogg') ) {
133 $HTML5Media{mime
} = 'audio/ogg';
135 elsif ( ($HTML5Media{codecs
} =~ /^vorbis$/) && ($HTML5Media{extension
} eq 'webm') ) {
136 $HTML5Media{mime
} = 'audio/webm';
139 ### …or just from file extension
141 if ( $HTML5Media{extension
} eq 'ogv' ) {
142 $HTML5Media{mime
} = 'video/ogg';
143 $HTML5Media{codecs
} = 'theora,vorbis';
145 if ( $HTML5Media{extension
} eq 'oga' ) {
146 $HTML5Media{mime
} = 'audio/ogg';
147 $HTML5Media{codecs
} = 'vorbis';
149 elsif ( $HTML5Media{extension
} eq 'spx' ) {
150 $HTML5Media{mime
} = 'audio/ogg';
151 $HTML5Media{codecs
} = 'speex';
153 elsif ( $HTML5Media{extension
} eq 'opus' ) {
154 $HTML5Media{mime
} = 'audio/ogg';
155 $HTML5Media{codecs
} = 'opus';
157 elsif ( $HTML5Media{extension
} eq 'vtt' ) {
158 $HTML5Media{mime
} = 'text/vtt';
162 if ( $HTML5Media{codecs
} ) {
163 $HTML5Media{codecblock
} = '; codecs="' . $HTML5Media{codecs
} . '"';
166 $HTML5Media{codecblock
} = '';
169 if ( $HTML5Media{mime
} ) {
170 $HTML5Media{typeblock
} = ' type=\'' . $HTML5Media{mime
} . $HTML5Media{codecblock
} . '\'';
173 $HTML5Media{typeblock
} = '';
176 if ( $HTML5Media{mime
} =~ /audio/ ) {
177 $HTML5Media{type
} = 'audio';
179 elsif ( $HTML5Media{mime
} =~ /video/ ) {
180 $HTML5Media{type
} = 'video';
182 elsif ( $HTML5Media{mime
} =~ /text/ ) {
183 $HTML5Media{type
} = 'track';
186 if ( $HTML5Media{srcblock
} && $HTML5Media{type
} ) {
187 push (@HTML5Media_sets, \
%HTML5Media);
191 for my $media ( @HTML5Media_sets ) {
192 if ( ($media->{mime
}) && ($media->{mime
} =~ /audio/) ) {
193 if ( $HTML5MediaParent ne 'video' ) {
194 $HTML5MediaParent = 'audio';
195 $HTML5MediaWidth = '';
198 elsif ( ($media->{mime
}) && ($media->{mime
} =~ /video/) ) {
199 $HTML5MediaParent = 'video';
200 $HTML5MediaWidth = ' width="480"';
204 for my $media ( @HTML5Media_sets ) {
205 if ( ($media->{type
}) && ( ($media->{type
} eq 'video') || ($media->{type
} eq 'audio') ) ) {
206 if ( $media->{type
} eq $HTML5MediaParent ) {
207 $media->{child
} = 'source';
211 $media->{child
} = $media->{type
};
216 HTML5MediaEnabled
=> ( (scalar(@HTML5Media_sets) > 0) && ($HTML5MediaParent) ),
217 HTML5MediaSets
=> \
@HTML5Media_sets,
218 HTML5MediaParent
=> $HTML5MediaParent,
219 HTML5MediaWidth
=> $HTML5MediaWidth,