Remove legacy generator and add missing features to latest generator.
This commit is contained in:
105
generator.php
105
generator.php
@@ -2,62 +2,69 @@
|
||||
|
||||
namespace Radio;
|
||||
|
||||
class Generator {
|
||||
error_reporting(0);
|
||||
ini_set('error_reporting', 0);
|
||||
|
||||
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";
|
||||
class Playlist {
|
||||
protected $data;
|
||||
|
||||
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 init(){
|
||||
$this->data = file_get_contents("https://git.waren.io/cwchristerw/radio/raw/branch/master/playlist.json");
|
||||
$this->data = str_replace("aw_0_1st.skey=1701171117", "aw_0_1st.skey=".time(),$this->data);
|
||||
$this->data = json_decode($this->data, true);
|
||||
}
|
||||
|
||||
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" : "");
|
||||
public function generate($format){
|
||||
switch($format){
|
||||
case "json":
|
||||
header('Content-Type: application/json');
|
||||
$content = json_encode($this->data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
echo $content;
|
||||
break;
|
||||
case "m3u":
|
||||
header('Content-Type: application/vnd.apple.mpegurl');
|
||||
$content = '#EXTM3U'."\n\n";
|
||||
for ($i = 0; $i < count($this->data); $i++) {
|
||||
$content .= '#EXTINF:-1,'.$this->data[$i]['name']."\n";
|
||||
$content .= $this->data[$i]['stream'][$this->data[$i]['stream']['default']].( $i + 1 < count($this->data) ? "\n\n" : "");
|
||||
}
|
||||
echo $content;
|
||||
break;
|
||||
case "pls":
|
||||
header('Content-Type: audio/x-scpls');
|
||||
$content = '[playlist]'."\n\n";
|
||||
for ($i = 1; $i-1 < count($this->data); $i++) {
|
||||
$content .= 'File'.$i.'='.$this->data[$i-1]['stream'][$this->data[$i-1]['stream']['default']]."\n";
|
||||
$content .= 'Title'.$i.'='.$this->data[$i-1]['name']."\n\n";
|
||||
}
|
||||
$content .= 'Version=2';
|
||||
echo $content;
|
||||
break;
|
||||
case "xspf":
|
||||
header('Content-Type: application/xspf+xml');
|
||||
$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($this->data); $i++) {
|
||||
$content .= ' <track>'."\n";
|
||||
$content .= ' <title>'.$this->data[$i]['name'].'</title>'."\n";
|
||||
$content .= ' <location>'.$this->data[$i]['stream'][$this->data[$i]['stream']['default']].'</location>'."\n";
|
||||
$content .= ' </track>'."\n";
|
||||
}
|
||||
$content .= '</trackList>'."\n";
|
||||
$content .= '</playlist>';
|
||||
echo $content;
|
||||
break;
|
||||
default:
|
||||
$this->generate("json");
|
||||
break;
|
||||
}
|
||||
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();
|
||||
$playlist = new Playlist;
|
||||
$playlist->init();
|
||||
$format = $_GET['format'];
|
||||
$playlist->generate($format);
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user