mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-08 16:08:54 +00:00
[M3uFormat] extended M3U formatter
This commit is contained in:
parent
db8a3d674d
commit
36f69af043
@ -15,10 +15,60 @@ class M3uFormat extends FormatAbstract
|
|||||||
foreach ($this->getItems() as $item) {
|
foreach ($this->getItems() as $item) {
|
||||||
$itemArray = $item->toArray();
|
$itemArray = $item->toArray();
|
||||||
|
|
||||||
if (isset($itemArray['itunes']) && isset($itemArray['enclosure'])) {
|
$m3uitem = new M3uItem();
|
||||||
$contents .= $itemArray['enclosure']['url'] . "\n";
|
|
||||||
|
if (isset($itemArray['enclosure'])) {
|
||||||
|
$m3uitem->url = $itemArray['enclosure']['url'];
|
||||||
|
$m3uitem->bytes = $itemArray['enclosure']['length'];
|
||||||
}
|
}
|
||||||
|
if (isset($itemArray['itunes']) && isset($itemArray['itunes']['duration'])) {
|
||||||
|
$m3uitem->duration = parse_duration($itemArray['itunes']['duration']);
|
||||||
|
}
|
||||||
|
if (isset($itemArray['title'])) {
|
||||||
|
$m3uitem->title = $itemArray['title'];
|
||||||
|
}
|
||||||
|
$contents .= $m3uitem->render();
|
||||||
}
|
}
|
||||||
return mb_convert_encoding($contents, $this->getCharset(), 'UTF-8');
|
return mb_convert_encoding($contents, $this->getCharset(), 'UTF-8');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parse_duration($duration_string)
|
||||||
|
{
|
||||||
|
$seconds = 0;
|
||||||
|
$parts = explode(':', $duration_string);
|
||||||
|
for ($i = 0; $i < count($parts); $i++) {
|
||||||
|
$seconds += intval($parts[count($parts) - $i - 1]) * pow(60, $i);
|
||||||
|
}
|
||||||
|
return $seconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
class M3uItem
|
||||||
|
{
|
||||||
|
public $duration = null;
|
||||||
|
public $title = null;
|
||||||
|
public $url = null;
|
||||||
|
public $bytes = null;
|
||||||
|
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
if ($this->url === null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
$text = '';
|
||||||
|
$commentParts = [];
|
||||||
|
if ($this->duration !== null && $this->duration > 0) {
|
||||||
|
$commentParts[] = $this->duration;
|
||||||
|
}
|
||||||
|
if ($this->title !== null) {
|
||||||
|
$commentParts[] = $this->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($commentParts) !== 0) {
|
||||||
|
$text .= '#EXTINF:' . implode(',', $commentParts) . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$text .= $this->url . "\n";
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user