From 37c4ebcb4c4009ea6274ef19f2e56755887bf413 Mon Sep 17 00:00:00 2001
From: Mirko Tietgen <mirko@abunchofthings.net>
Date: Mon, 16 Nov 2015 18:10:27 +0100
Subject: [PATCH] Bug 15225: Make HTML5Media work with file upload feature.
Content-Type: text/plain; charset=utf-8

Koha::Upload allows files to be attached to bibliographic records.
HTML5Media streaming in Koha does not work with these files.

Test plan:
- apply patch
- make sure OPACBaseURL is set correctly
- enable HTML5MediaEnabled in OPAC and staff client
- connect upload.pl to 856$u in your framework
- upload a file with an extension set in HTML5MediaExtensions,
  make sure to set the codec correctly if you use WEBM (subfield c,
  eg. 'vp8, vorbis')
- save record, view in staff client and browser, check if 'Play
  media' option is available and works

Signed-off-by: Hugo Agud <hagud@orex.es>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
---
 C4/HTML5Media.pm |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/C4/HTML5Media.pm b/C4/HTML5Media.pm
index c8c8a77..2bdb794 100644
--- a/C4/HTML5Media.pm
+++ b/C4/HTML5Media.pm
@@ -1,6 +1,6 @@
 package C4::HTML5Media;
 
-# Copyright 2012 Mirko Tietgen
+# Copyright 2012/2015 Mirko Tietgen
 #
 # This file is part of Koha.
 #
@@ -22,7 +22,7 @@ use warnings;
 
 use C4::Context;
 use MARC::Field;
-
+use Koha::Upload;
 
 =head1 HTML5Media
 
@@ -109,7 +109,14 @@ sub gethtml5media {
             next; # no file to play
         }
         # extension
-        $HTML5Media{extension} = ($HTML5Media{srcblock} =~ m/([^.]+)$/)[0];
+        # check uploaded files
+        if ( $HTML5Media{srcblock} =~ /\Qopac-retrieve-file.pl\E/ ) {
+            $HTML5Media{extension} = (Koha::Upload->new->get({ hashvalue => (split(/id=/, $HTML5Media{srcblock}))[1] })->{name} =~ m/([^.]+)$/)[0];
+        }
+        # check remote files
+        else {
+            $HTML5Media{extension} = ($HTML5Media{srcblock} =~ m/([^.]+)$/)[0];
+        }
         if ( !grep /\Q$HTML5Media{extension}\E/, @HTML5MediaExtensions ) {
             next; # not a specified media file
         }
-- 
1.7.10.4