Ticket #12625: remotestream.patch

File remotestream.patch, 4.1 KB (added by Stefan Enzinger <mindoms@…>, 6 years ago)

the patch

  • modules/stream/handler.pl

    diff --git a/modules/stream/handler.pl b/modules/stream/handler.pl
    index 9015c62..2692b2f 100755
    a b  
    1212
    1313    require "modules/$Path[0]/tv.pl";
    1414
    15     unless ($filename) {
     15
     16    if (!defined $filename and !defined $dlurl) {
    1617        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.";
    1819        exit;
    1920    }
    2021
     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
    2128# ASX mode?
    2229    if ($ENV{'REQUEST_URI'} =~ /\.asx$/i) {
    2330        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
     6use 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  
    2424    }
    2525
    2626# 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
    2828                              FROM recorded
    2929                             WHERE starttime=FROM_UNIXTIME(?)
    3030                                   AND recorded.chanid   = ?');
    3131    $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();
    3333    $sh->finish;
    3434
    3535# No match?
     
    5050    }
    5151    $sh->finish;
    5252
     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
    5376    1;