v1.2.0
M3u8 file parser / dumper
$ composer require 'chrisyue/php-m3u8'
$parser = new \Chrisyue\PhpM3u8\Parser();
$m3u8 = $parser->parse($m3u8Content);
// or with loader
class MyLoader implements LoaderInterface
{
public function load($uri)
{
// return $uri content by `file_get_contents` or `guzzle` etc.
}
}
$parser->setLoader(new MyLoader());
$parser->parseFromUri($uri);
Fortunately you don't really need to write a MyLoader
class because there is already a CachableLoader
along with this library
supposing you are using psr6 compatible cache utils like Symfony cache component:
$cachePool = new \Symfony\Component\Cache\Adapter\ApcuAdapter();
$loader = new \Chrisyue\PhpM3u8\CachableLoader($cachePool);
$parser->setLoader($loader);
$m3u8 = $parser->parseFromUri($uri);
$dumper = new \Chrisyue\PhpM3u8\Dumper();
echo $dumper->dump($m3u8);