VideoHelp Forum



Support our site by donate $5 directly to us Thanks!!!

Try StreamFab Downloader and download streaming video from Netflix, Amazon!



+ Reply to Thread
Results 1 to 4 of 4
  1. Hi all,

    I've been following intently trying to learn up from scratch how to create a PHP script that will enable me to extract M3U8s automatically and/or alter pre-existing links to then feed into recording via livestreamer (though I may end up also using ffmpeg which I am more used to). Now my problem is I have seen some previous examples posted by biezom that I am struggling to follow due to my total noobness when it comes to PHP scripting.

    The sample sites I am looking at are MamaHD and StreamHD.eu. What I am able to get is the m3u8s manually right now but this is no good for recording as one creates a new session id each time you click on it and then expires (MamaHD) and the other is HLS variant so runs super quick. So I am trying to tackle this several different ways... not quite knowing what the best is. I've ended up deciding PHP is a good way to go as I can just about read it and edit it but some of the terminology i.e. pgrep_match ... that I believe I need to use is stumping me. I understand how to get livestreamer to do a straight out record i.e. livestreamer "hls://http://94.102.50.93:8081/live/mamahdsky11.m3u8?e=1475580868&st=eVpb5x0LfodiovcZs BM_ig" best -o mama.ts but for scheduling recording this is not good and I need to in this case scrape the URL at point of record or at teh very least update from .m3u8? onwards.

    The code I have been trying to create variations on is:

    <?php
    $return=file_get_contents("http://mamahd.com/sky-sports-1-live-free-stream-1.html"); preg_match('/m3u8?e=: "(.*?)"/', $return, $token);

    $return2=file_get_contents("http://89.248.172.45:8081/live/mamahdsky11.m3u8?e=$token); $hls=str_replace("http","hls://http";
    $date = date("H:i_d-m-Y"); $outputfile= $date . "-mama.ts";
    echo "Starting livestreamer...\n\n";
    echo shell_exec("livestreamer \"$hls\" best -o \"$outputfile\" &");
    echo "Done.\n";
    ?>

    Which is probably totally incorrect. I know what I want this to do but I am having a pig of a time trying to get it to behave. I want to also do similarly for streamhd.eu (i.e. http://www.streamhd.eu/tv/sky-sports-1-live-stream.php - which is offline at time of writing) but I can't work it out at all as that one is an hls variant. One of the things I am struggling with is how to discover the argument for preg_match.. I mean I can find an m3u8 no probs but examples I have seen elsewhere are referring to things like "src" etc which I'm not sure if I should be using chrome developer tools for or really how to find the easiest way to track down such things for the sample sites I am using. I'd really like to be able to scrape the entire link but I'd also be interested to learn how to scrape a portion of the urls (i.e. if they have tokens at the end or like mamahd changing values such as e= and st=). If anyone can give me some pointers as to how best to do this and is able to point out the mammoth mistakes I am no doubt making, I'd be really really grateful.
    Quote Quote  
  2. hi

    try this

    Code:
    <?php
    
    
    $opts1 = array(
      'http'=>array(
        'method'=>"GET",
        'header'=>"Referer: \r\n" .
    		"User-Agent: Mozilla/5.0 (X11; Linux i686; rv:42.0) Gecko/20100101 Firefox/42.0 Iceweasel/42.0)"       
      )
    );
    
    $return=file_get_contents("http://mamahd.com/sky-sports-1-live-free-stream-1.html", false, stream_context_create($opts1));
    preg_match('/iframe.*?src="(.*?)"/', $return, $iframe);
    
    $return=file_get_contents($iframe[1], false, stream_context_create($opts1));
    
    preg_match('/fid="(.*?)"/', $return, $fid);
    
    $opts2 = array(
      'http'=>array(
        'method'=>"GET",
        'header'=>"Referer: $iframe[1]\r\n" .
    		"User-Agent: Mozilla/5.0 (X11; Linux i686; rv:42.0) Gecko/20100101 Firefox/42.0 Iceweasel/42.0)"       
      )
    );
    
    $return=file_get_contents("http://hdcast.org/embedlive1.php?u=$fid[1]", false, stream_context_create($opts2));
    
    preg_match('/allowtransparency="true" src=(.*?)\&/', $return, $embed);
    
    
    $opts3 = array(
      'http'=>array(
        'method'=>"GET",
        'header'=>"Referer: http://hdcast.org/embedlive1.php?u=$fid[1]\r\n" .
    		"User-Agent: Mozilla/5.0 (X11; Linux i686; rv:42.0) Gecko/20100101 Firefox/42.0 Iceweasel/42.0)"       
      )
    );
    
    $return=file_get_contents("$embed[1]", false, stream_context_create($opts3));
    preg_match('/file:"(.*?)"/', $return, $m3u8);
    
    echo "$m3u8[1]\n\n";
    
    $hls=str_replace("http","hls://http",$m3u8[1]);
    
    $date = date("H-i_d-m-Y");
    $outputfile= $date . "-mama.ts";
    echo "$outputfile\n\n";
    echo "Starting livestreamer...\n\n";
    echo shell_exec("livestreamer \"$hls\" best -o \"$outputfile\" &");
    echo "Done.\n";
    ?>
    Last edited by biezom; 4th Oct 2016 at 22:43.
    Quote Quote  
  3. Thankyou so much for replying!! I've tried running the script. It runs but it's not outptting anything or showing anything is being grabbed. I am just getting a long livestreamer function list. Any thoughts? This was a much longer script than i expected so thanks again for all the effort!!!
    Quote Quote  
  4. Member DB83's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Search Comp PM
    Why should you get help ?

    Sky Sports is NOT free. It is a UK based subscription service. That website is getting and sharing the streams illegally. And since this is not free it is beyond the rules of the forum.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!