1
0
radio/generator.php

64 lines
2.1 KiB
PHP
Raw Permalink Normal View History

2020-10-03 22:07:22 +00:00
<?php
namespace Radio;
class Generator {
public function pls (){
$json = json_decode(file_get_contents(__DIR__."/playlist.json"), true);
$file = fopen(__DIR__."/playlists/playlist.pls", "w") or die("Unable to open file!");
$content = '[playlist]'."\n\n";
for ($i = 1; $i-1 < count($json); $i++) {
$content .= 'File'.$i.'='.$json[$i-1]['stream'][$json[$i-1]['stream']['default']]."\n";
$content .= 'Title'.$i.'='.$json[$i-1]['name']."\n\n";
}
$content .= 'Version=2';
fwrite($file, $content);
fclose($file);
}
public function m3u (){
$json = json_decode(file_get_contents(__DIR__."/playlist.json"), true);
$file = fopen(__DIR__."/playlists/playlist.m3u", "w") or die("Unable to open file!");
$content = '#EXTM3U'."\n\n";
for ($i = 0; $i < count($json); $i++) {
$content .= '#EXTINF:-1,'.$json[$i]['name']."\n";
$content .= $json[$i]['stream'][$json[$i]['stream']['default']].( $i + 1 < count($json) ? "\n\n" : "");
}
fwrite($file, $content);
fclose($file);
}
public function xspf (){
$json = json_decode(file_get_contents(__DIR__."/playlist.json"), true);
$file = fopen(__DIR__."/playlists/playlist.xspf", "w") or die("Unable to open file!");
$content = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
$content .= '<playlist version="1" xmlns="http://xspf.org/ns/0/">'."\n";
$content .= '<trackList>'."\n";
for ($i = 0; $i < count($json); $i++) {
$content .= ' <track>'."\n";
$content .= ' <title>'.$json[$i]['name'].'</title>'."\n";
$content .= ' <location>'.$json[$i]['stream'][$json[$i]['stream']['default']].'</location>'."\n";
$content .= ' </track>'."\n";
}
$content .= '</trackList>'."\n";
$content .= '</playlist>';
fwrite($file, $content);
fclose($file);
}
}
$generator = new Generator;
$generator->pls();
$generator->m3u();
$generator->xspf();
?>