簡體   English   中英

使用 PHP 獲取和返回媒體 url (m3u8)

[英]Get and return media url (m3u8) using PHP

我有一個網站,可以托管來自客戶的視頻。 在網站上,文件通過 m3u8 鏈接從外部加載。

客戶現在想要在 Roku 頻道上播放這些視頻。

如果我只是使用來自站點的 m3u8 鏈接,則會出現錯誤,因為生成的 url 是隨 cookie 一起發送的,因此客戶端必須單擊該鏈接才能為他們生成新代碼。

如果可能的話(我還沒有在這里看到),我想抓取 html 頁面,然后通過 Roku 網站上的 PHP 腳本返回鏈接。

我知道如何使用純 php 獲取標題等,但在返回 m3u8 鏈接時遇到問題..

我確實有代碼表明我不是在尋找講義,而是在嘗試。

例如,這就是我用來獲取標題名稱的方法。

注意:我想知道是否有可能有一個 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 鏈接,它可能看起來像這樣,你可以使用這樣的地址作為位於

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");

}
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM