使用 PHP 获取和 return 媒体 url (m3u8)

Get and return media url (m3u8) using PHP

我有一个托管客户视频的网站。在网站上,文件通过 m3u8 link.

从外部加载

客户现在想在 Roku 频道上播放这些视频。

如果我简单地使用网站上的 m3u8 link 它会给出错误,因为生成的 url 是与 cookie 一起发送的,因此客户端必须单击并且 link为他们生成一个新代码。

如果可能的话(我在这里没有看到)我希望通过 PHP 脚本抓取 html 页面,然后 return link来自 Roku 的网站。

我知道如何使用纯 php 获得标题等,但在 return 使用 m3u8 link..

时遇到问题

我确实有代码表明我不是在寻找讲义,实际上我正在尝试。

这就是我用来获取标题名称的示例。

注意:我想知道是否有一个 php 可以根据 url 自动填充 html 页面,这样我就不必使用不同的 php 对于每个预先输入 url 的视频。

<?php
$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/>";
        }
    }
}
?>

对此有一个简单的方法,涉及使用正则表达式。

在此示例中,假设视频 M3u8 文件位于:http://example.com/theVideoPage

您可以将 XML 中的视频 URL 来源指向您的 PHP 文件。

http://thisPhpFileLocation.com

<?php
$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");
}
?>

现在,如果你想使用一个 URL,你可以在末尾附加一个 URL link 它可能看起来像这样,你可以使用这样的地址位于

的视频 Url

http://thisPhpFileLocation.com?id=theVideoPage

<?php
$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");

}
?>