Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a website that hosts videos from a client. On the website the files load externally via m3u8 link.

The client would now like to have those videos on a Roku channel.

If I simply use the m3u8 link from the site it gives an error because the url generated is sent with a cookie and so a client must click and the link to generate a new code for them.

I would like if possible (and I have not seen this here) is to scrape the html page and just return the link via PHP script on the website from the Roku.

I know how to get titles and such using pure php but am having problems returning the m3u8 link..

I do have code to show I am not looking for handouts and actually am trying.

This is what I have used for getting the title name for example.

Note: I would like to know if it is possible to have one php that autofills the html page per url so I do not have to use a different php for each video with the url pretyped in.

$html = file_get_contents('http://example.com'); //get the html returned from the following url $movie_doc = new DOMDocument(); libxml_use_internal_errors(TRUE); //disable libxml errors if(!empty($html)){ //if any html is actually returned $movie_doc->loadHTML($html); libxml_clear_errors(); //remove errors for yucky html $movie_xpath = new DOMXPath($movie_doc); //get all the titles $movie_row = $movie_xpath->query('//title'); if($movie_row->length > 0){ foreach($movie_row as $row){ echo $row->nodeValue . "<br/>"; this might be doable on Roku's side too, roUrlTransfer supports custom headers and cookies Nas Banov Jan 28, 2017 at 23:35

There is a simple approach for this, which involves using regex.

In this example let's say the video M3u8 file is located at: http://example.com/theVideoPage

You would point the video URL Source in your XML to your PHP file.

http://thisPhpFileLocation.com

$html = file_get_contents("http://example.com/theVideoPage"); preg_match_all( '/(http.*m3u8)/', $html, $posts, // will contain the article data PREG_SET_ORDER // formats data into an array of posts foreach ($posts as $post) { $link = $post[0]; header("Location: $link");

Now if you want to use a URL that you can append a URL link at the end it could look something like this and you would use an address as such for a Video Url located at

http://thisPhpFileLocation.com?id=theVideoPage

$id = $_GET['id']; $html = file_get_contents("http://example.com".$id); preg_match_all( '/(http.*m3u8)/', $html, $things, // will contain the article data PREG_SET_ORDER // formats data into an array of posts foreach ($things as $thing) { $link = $thing[1]; // clear out the output buffer while (ob_get_status()) ob_end_clean(); // no redirect header("Location: $link");

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .