1
0

Remove legacy generator and add missing features to latest generator.

This commit is contained in:
Christer Warén
2026-01-13 02:56:21 +02:00
parent d028b86ff0
commit f62535d9bb
3 changed files with 56 additions and 75 deletions

View File

@@ -2,62 +2,69 @@
namespace Radio; namespace Radio;
class Generator { error_reporting(0);
ini_set('error_reporting', 0);
public function pls (){ class Playlist {
$json = json_decode(file_get_contents(__DIR__."/playlist.json"), true); protected $data;
$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++) { public function init(){
$content .= 'File'.$i.'='.$json[$i-1]['stream'][$json[$i-1]['stream']['default']]."\n"; $this->data = file_get_contents("https://git.waren.io/cwchristerw/radio/raw/branch/master/playlist.json");
$content .= 'Title'.$i.'='.$json[$i-1]['name']."\n\n"; $this->data = str_replace("aw_0_1st.skey=1701171117", "aw_0_1st.skey=".time(),$this->data);
$this->data = json_decode($this->data, true);
} }
$content .= 'Version=2'; public function generate($format){
switch($format){
fwrite($file, $content); case "json":
fclose($file); header('Content-Type: application/json');
} $content = json_encode($this->data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
echo $content;
public function m3u (){ break;
$json = json_decode(file_get_contents(__DIR__."/playlist.json"), true); case "m3u":
$file = fopen(__DIR__."/playlists/playlist.m3u", "w") or die("Unable to open file!"); header('Content-Type: application/vnd.apple.mpegurl');
$content = '#EXTM3U'."\n\n"; $content = '#EXTM3U'."\n\n";
for ($i = 0; $i < count($this->data); $i++) {
for ($i = 0; $i < count($json); $i++) { $content .= '#EXTINF:-1,'.$this->data[$i]['name']."\n";
$content .= '#EXTINF:-1,'.$json[$i]['name']."\n"; $content .= $this->data[$i]['stream'][$this->data[$i]['stream']['default']].( $i + 1 < count($this->data) ? "\n\n" : "");
$content .= $json[$i]['stream'][$json[$i]['stream']['default']].( $i + 1 < count($json) ? "\n\n" : "");
} }
fwrite($file, $content); echo $content;
fclose($file); 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';
public function xspf (){ echo $content;
$json = json_decode(file_get_contents(__DIR__."/playlist.json"), true); break;
$file = fopen(__DIR__."/playlists/playlist.xspf", "w") or die("Unable to open file!"); case "xspf":
header('Content-Type: application/xspf+xml');
$content = '<?xml version="1.0" encoding="UTF-8"?>'."\n"; $content = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
$content .= '<playlist version="1" xmlns="http://xspf.org/ns/0/">'."\n"; $content .= '<playlist version="1" xmlns="http://xspf.org/ns/0/">'."\n";
$content .= '<trackList>'."\n"; $content .= '<trackList>'."\n";
for ($i = 0; $i < count($this->data); $i++) {
for ($i = 0; $i < count($json); $i++) {
$content .= ' <track>'."\n"; $content .= ' <track>'."\n";
$content .= ' <title>'.$json[$i]['name'].'</title>'."\n"; $content .= ' <title>'.$this->data[$i]['name'].'</title>'."\n";
$content .= ' <location>'.$json[$i]['stream'][$json[$i]['stream']['default']].'</location>'."\n"; $content .= ' <location>'.$this->data[$i]['stream'][$this->data[$i]['stream']['default']].'</location>'."\n";
$content .= ' </track>'."\n"; $content .= ' </track>'."\n";
} }
$content .= '</trackList>'."\n"; $content .= '</trackList>'."\n";
$content .= '</playlist>'; $content .= '</playlist>';
echo $content;
fwrite($file, $content); break;
fclose($file); default:
$this->generate("json");
break;
}
} }
} }
$generator = new Generator; $playlist = new Playlist;
$generator->pls(); $playlist->init();
$generator->m3u(); $format = $_GET['format'];
$generator->xspf(); $playlist->generate($format);
?> ?>

View File

@@ -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

View File

@@ -1,25 +0,0 @@
<?php
namespace Radio;
error_reporting(0);
ini_set('error_reporting', 0);
header('Content-Type: application/json');
class Generator {
public function json (){
$json = file_get_contents("https://git.waren.io/cwchristerw/radio/raw/branch/master/playlist.json");
$json = str_replace("aw_0_1st.skey=1701171117", "aw_0_1st.skey=".time(),$json);
echo $json;
}
}
$generator = new Generator;
$generator->json();
?>