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;
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";
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);
}
$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!");
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($json); $i++) {
$content .= '#EXTINF:-1,'.$json[$i]['name']."\n";
$content .= $json[$i]['stream'][$json[$i]['stream']['default']].( $i + 1 < count($json) ? "\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" : "");
}
fwrite($file, $content);
fclose($file);
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";
}
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 .= '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($json); $i++) {
for ($i = 0; $i < count($this->data); $i++) {
$content .= ' <track>'."\n";
$content .= ' <title>'.$json[$i]['name'].'</title>'."\n";
$content .= ' <location>'.$json[$i]['stream'][$json[$i]['stream']['default']].'</location>'."\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>';
fwrite($file, $content);
fclose($file);
echo $content;
break;
default:
$this->generate("json");
break;
}
}
}
$generator = new Generator;
$generator->pls();
$generator->m3u();
$generator->xspf();
$playlist = new Playlist;
$playlist->init();
$format = $_GET['format'];
$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();
?>