urvin / m3u
M3U PHP 解析器 & 创建器
dev-master
2019-04-16 13:24 UTC
Requires
- php: ^7.1
Requires (Dev)
- phpunit/phpunit: ^8
This package is auto-updated.
Last update: 2024-09-18 03:07:15 UTC
README
M3u 播放列表操作(解析 & 创建)类。
要求
- PHP >= 7.1
安装
composer require urvin/m3u
使用
$playlist = '#EXTM3U #EXTINF:0,TV Channel #EXTGRP:News http://broadcaster.tv/channel.m3u8 #EXTINF:0 group-title="Sports",Sports channel http://broadcaster.tv/sports.m3u8 # That\'s my favourite song #EXTINF:253,John Doe - Universe /home/jd - universe.mp3 '; // create a playlist object $m3u = new M3u(); // parse an existing file $m3u->parse($playlist); // walk through items $entries = $m3u->getEntries(); foreach($entries as &$entry) { echo $entry->name, PHP_EOL; } // add records $new = new M3uEntry(); $new->path = '/home/test1.mp3'; $m3u->addEntry($new); // or this way $m3u->addEntry(new M3uEntry([ 'path' => '/home/test2.mp3', 'artist' => 'Unknown artist', 'name' => 'Unknown record' ])); // export valid m3u playlist echo $m3u;