dbiesecke
7/15/2015 - 3:45 AM

livestreamer - save TV Streams from Internet

livestreamer - save TV Streams from Internet

#
FROM debian:jessie
MAINTAINER dbiesecke

ADD http://www.deb-multimedia.org/pool/main/d/deb-multimedia-keyring/deb-multimedia-keyring_2015.6.1_all.deb /keyring.deb 
RUN dpkg -i /keyring.deb 
RUN echo 'deb http://www.deb-multimedia.org jessie main non-free' > /etc/apt/sources.list.d/ffmpeg.list 
RUN echo 'deb ftp://ftp.deb-multimedia.org jessie main non-free' >> /etc/apt/sources.list.d/ffmpeg.list 

RUN apt-get update
RUN apt-get install ffmpeg python-setuptools ca-certificates openssl -y -f
RUN easy_install livestreamer 

RUN apt-get install curl psmisc -y -f

WORKDIR /video
ADD https://gist.githubusercontent.com/dbiesecke/7e6211785c8cfc4b0545/raw/run-rip.pl /run.pl
RUN chmod +x /run.pl
ENTRYPOINT ["perl","/run.pl"]

#Will save a Pro7 MAXX stream without LOGO 
livestreamer -O --http-header "X-Forwarded-For=195.186.136.21" "hds://http://pebbles107-lh.akamaihd.net/z/pro7maxx_1@97522//manifest.f4m" best | ffmpeg -i - -vcodec copy -c:v mpeg4 -c:a copy  -vf "delogo=x=874:y=24:w=125:h=35:band=10" outfile.avi

Save (Internet) TV Streams easy on HDD

  • Use your fav. TV Stream from list like my iptv.m3u8
  • install livestreamer
`livestreamer -O --yes-run-as-root  --http-header "X-Forwarded-For=195.186.136.21" "hds://http://pebbles107-lh.akamaihd.net/z/pro7maxx_1@97522//manifest.f4m" best | ffmpeg  -i - -c:v copy   -vcodec copy -c:a copy   /video/outfile.mkv`

Manifest for best selection

  • You can transform url's to files like this: http://pebbles107-lh.akamaihd.net/i/pro7maxx_1@97522/master.m3u8 to http://pebbles107-lh.akamaihd.net/z/pro7maxx_1@97522/manifest.f4m
    % livestreamer  --http-header "X-Forwarded-For=195.186.136.21" "hds://http://pebbles107-lh.akamaihd.net/z/rtl2_1@97460/manifest.f4m" best                                                                        :(
    [cli][info] Found matching plugin stream for URL hds://http://pebbles107-lh.akamaihd.net/z/rtl2_1@97460/manifest.f4m
    [cli][info] Available streams: 1428k (best), 908k (worst)
    [cli][info] Opening stream: 1428k (hds)
    [....]
#!/usr/bin/perl -w
use warnings;
use POSIX qw(strftime);
 

die ("Usage: $ARGV[0] TV-Channel TIMEOUT-IN-MIN <FTP-SERVER/OUTPUTFILE>\n\n\tStreams:tagesschau_1,ntv_1,n24_1,daserste_1,zdf_1,rtl_1,sat1_1,prosieben_1,rtl2_1,vox_1,kabeleins_1,superrtl_1,eurosportde_1,sport1_1,disney_channel_de_1,pro7maxx_1,rtlnitro_1,sixx_1,kika_1,nickcc_1,viva_1,dmax_1,artede_1,3sat_1,phoenix_1,swr_1,wdr_1,br3_1,servus_1,orf1_1,orf2_1,sf1_1,sf2_1,3plus_1,atv_1,daserste_de,de14_v1,de13_v1,tagesschau_1,de12_v1,de11_v1,dach10_v1,servustvhd_1,livetvmdrsachsenanhalt_de,ndrfs_nds,wdrfs_geogeblockt,bfssued_germany,bralpha_germany,rbb_berlin,live_1\n") if (scalar (@ARGV) < 3);

print scalar(@urls)."\n";
my $time_to_die=0;
my $tvchan = $ARGV[0];
my $val = scalar($ARGV[1]);
my $timeout=$val*60; #in seconds 
my $file = $ARGV[2] || 'ftp://foilo:yeah12ha!!@nated.at:21/outtest.avi';
my $mins = strftime '%M',gmtime();
my $date = strftime '%d.%m', gmtime(); # 2014-11-09
my $hour = strftime '%H',gmtime();

$file=~s/\.([a-z]+)$/-$hour.$mins-$tvchan\.$1/i;
my $filter = "";

#$filter = '-vf "delogo=x=874:y=24:w=125:h=35:band=10"' if ($tvchan =~/pro7maxx/i);

print "TV:$tvchan\t$val\t$file\n";
if (-f '/tmp/ip.pls') {
}else{
 system("curl https://gist.githubusercontent.com/dbiesecke/c15243da0e8c17067c73/raw/gistfile1.txt > /tmp/ip.pls");
};
my ($url,$forward);

if(-f '/tmp/ip.pls') {
  $url = `cat /tmp/ip.pls | grep $tvchan`;
  $forward = $2 if ( $url=~/(.*)\|X-Forwarded-For=([\d\.]+)/) || die("ERROR! - $url\n");
  $url = $1;
  $url =~ s/i(\/$tvchan\@\d+).*/z$1\/manifest\.f4m/ig;
}
my $strm_proto;

if($url =~/\.m3u8/){ 
        $strm_proto = "hls://"
}elsif($url =~/manifest\.f4m/) {        $strm_proto = "hds://" };


die("ERROR - cant find TV-Channel") if not ($url=~/http/);

print "$url\t$forward\n";
$SIG{ALRM} = sub { $time_to_die=1; 
        system("killall livestreamer");
        system("killall ffmpeg");
        system("sleep 2 && clear && ls -lah outtest.avi");
        exit;


};

alarm($timeout);
while(!$time_to_die){
my $cmd =  'livestreamer --yes-run-as-root  -O --http-header "X-Forwarded-For='.$forward.'" "'.$strm_proto.''.$url.'" best | ffmpeg -i - -vcodec copy -c:v libx264 -c:a copy  '.$filter.' '.$file;
system($cmd);
print "[ERROR]\t Something went wrong!\n";
exit -1;
}

#will allow while loop to complete 
#after $SIG{ALRM} is received