diff --git a/generator.php b/generator.php
index 96ef258..3e20822 100644
--- a/generator.php
+++ b/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 = ''."\n";
+ $content .= ''."\n";
+ $content .= ''."\n";
+ for ($i = 0; $i < count($this->data); $i++) {
+ $content .= ' '."\n";
+ }
+ $content .= ''."\n";
+ $content .= '';
+ 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 = ''."\n";
- $content .= ''."\n";
- $content .= ''."\n";
-
- for ($i = 0; $i < count($json); $i++) {
- $content .= ' '."\n";
- }
- $content .= ''."\n";
- $content .= '';
-
- 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);
?>
diff --git a/generator.sh b/generator.sh
deleted file mode 100755
index 5533103..0000000
--- a/generator.sh
+++ /dev/null
@@ -1 +0,0 @@
-podman run -it --rm --name php -v "$PWD":/usr/src/myapp -w /usr/src/myapp docker.io/php:8-cli php generator.php
diff --git a/generatorv2.php b/generatorv2.php
deleted file mode 100644
index f387d70..0000000
--- a/generatorv2.php
+++ /dev/null
@@ -1,25 +0,0 @@
-json();
-
-?>