Ticket #12625: remotestream.patch
File remotestream.patch, 4.1 KB (added by , 9 years ago) |
---|
-
modules/stream/handler.pl
diff --git a/modules/stream/handler.pl b/modules/stream/handler.pl index 9015c62..2692b2f 100755
a b 12 12 13 13 require "modules/$Path[0]/tv.pl"; 14 14 15 unless ($filename) { 15 16 if (!defined $filename and !defined $dlurl) { 16 17 print header(), 17 "$basename does not exist in any recognized storage group directories for this host.";18 "$basename does not exist in any recognized storage group directories."; 18 19 exit; 19 20 } 20 21 22 # if recording was found remote, get it from there 23 if($dlurl){ 24 require "modules/$Path[0]/stream_remote.pl"; 25 exit 0; 26 } 27 21 28 # ASX mode? 22 29 if ($ENV{'REQUEST_URI'} =~ /\.asx$/i) { 23 30 require "modules/$Path[0]/stream_asx.pl"; -
new file modules/stream/stream_remote.pl
diff --git a/modules/stream/stream_remote.pl b/modules/stream/stream_remote.pl new file mode 100755 index 0000000..f9a5a3f
- + 1 #!/usr/bin/perl 2 3 # MythWeb Streaming/Download module 4 5 # CGI already defines a head function, so skip it here 6 use LWP::Simple qw(!head); 7 8 # determine suffix if possibile 9 my $suffix = ''; 10 if ($basename =~ /\.mpe?g2?$/) { 11 $suffix = '.mpg'; 12 } 13 elsif ($basename =~ /\.nuv$/) { 14 $suffix = '.nuv'; 15 } 16 elsif ($basename =~ /\.mkv$/) { 17 $suffix = '.mkv'; 18 } 19 20 21 # Build filename 22 my $name = $basename; 23 if ($name =~ /^\d+_\d+\.\w+$/) { 24 if ($title =~ /\w/) { 25 $name = $title; 26 $name .= sprintf(" - %dx%02d", $season, $episode) if $season and $episode; 27 if ($subtitle =~ /\w/) { 28 $name .= " - $subtitle"; 29 } 30 } 31 $name .= $suffix; 32 } 33 34 35 # Retrieve header to determine size and type 36 my ($type, $size) = LWP::Simple::head("$dlurl"); 37 38 unless ($type and $size){ 39 print header(), 40 "$basename could not be retrieved from remote backend"; 41 exit 0; 42 } 43 44 # Set the new header 45 print header(-type => $type, 46 -Content_length => $size, 47 -Content_disposition => " attachment; filename=\"$name\"", 48 ); 49 50 51 52 # Passthrough the requested file 53 my $status = getprint("$dlurl"); 54 55 #not sure how to report any error ($status!=200) after header was written. 56 57 1; -
modules/stream/tv.pl
diff --git a/modules/stream/tv.pl b/modules/stream/tv.pl index 11d5743..18abe02 100755
a b 24 24 } 25 25 26 26 # Get the basename from the database 27 my $sh = $dbh->prepare('SELECT basename, title, subtitle, endtime-starttime, season, episode 27 my $sh = $dbh->prepare('SELECT basename, title, subtitle, endtime-starttime, season, episode, hostname 28 28 FROM recorded 29 29 WHERE starttime=FROM_UNIXTIME(?) 30 30 AND recorded.chanid = ?'); 31 31 $sh->execute($starttime, $chanid); 32 our ($basename, $title, $subtitle, $runtime, $season, $episode ) = $sh->fetchrow_array();32 our ($basename, $title, $subtitle, $runtime, $season, $episode, $hostname) = $sh->fetchrow_array(); 33 33 $sh->finish; 34 34 35 35 # No match? … … 50 50 } 51 51 $sh->finish; 52 52 53 # if no local file is found, prepare url to retrieve it via owning backend 54 our $dlurl; 55 unless($filename){ 56 57 my $sh = $dbh->prepare('SELECT data 58 FROM settings 59 WHERE settings.value = "BackendServerIP" 60 AND settings.hostname = ?'); 61 $sh->execute($hostname); 62 my ($ipaddress) = $sh->fetchrow_array(); 63 $sh->finish; 64 65 $sh = $dbh->prepare('SELECT FROM_UNIXTIME(?),data 66 FROM settings 67 WHERE settings.value = "BackendStatusPort" 68 AND settings.hostname = ?'); 69 $sh->execute($starttime, $hostname); 70 my ($sqltime, $port) = $sh->fetchrow_array(); 71 $sh->finish; 72 73 $dlurl="http://$ipaddress:$port/Content/GetRecording?ChanId=$chanid&StartTime=$sqltime"; 74 } 75 53 76 1;