【问题标题】:Get Stream as m3u8 over php通过 php 将 Stream 作为 m3u8 获取
【发布时间】:2020-10-10 14:16:42
【问题描述】:

我有这个 PHP 代码可以从名为 stream.php 的页面获取流 URL:

$url = file_get_contents("stream.php");
preg_match('#src="(.*?)"#', $url, $getm3u8);

echo ($getm3u8[1]);

在 stream.php 我有这个:

<source src="http://domaine.com/test1/playlist.m3u8" type="video/mp4">
<source src="http://domaine.com/test2/playlist.m3u8" type="video/mp4">
<source src="http://domaine.com/test3/playlist.m3u8" type="video/mp4">

此代码echo ($getm3u8[1]); 返回第一个网址“http://domaine.com/test1/playlist.m3u8”

如何获取其他 2 个网址?

【问题讨论】:

    标签: php file-get-contents


    【解决方案1】:

    调用preg_match_all可以捕获所有源标签

    $html_str =
      视频>
    HTML;
    
    if (preg_match_all('/]*src="([^"]+)"[^]*type="video\/mp4"[^]*>/iu', $html_str, $matches)) {
        var_dump($matches[1]);
    }
    

    【讨论】:

    • 我一次只想获取一个 url 并且页面 stream.php 在外部站点上我无法在此页面上进行修改
    • 为什么不尝试一次获取所有 src 链接并缓存它们。我认为它比每次都从外部站点获取 src 链接要快。
    • 好主意!我该怎么做??
    • 我猜你可以选择像 Redis 这样的缓存服务,或者只是将文件保存为 JSON 格式。
    • 如果您能给我一个代码,可以检索所有 之间的代码,不便之处敬请见谅。类似于我在外部页面上没有进行任何更改的第一个代码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-13
    • 1970-01-01
    • 1970-01-01
    • 2011-12-21
    • 2011-07-29
    • 2016-01-12
    相关资源
    最近更新 更多