Generator
This commit is contained in:
parent
6c7572f200
commit
4870e21d18
63
generator.php
Normal file
63
generator.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?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();
|
||||
|
||||
?>
|
2
generator.sh
Normal file
2
generator.sh
Normal file
@ -0,0 +1,2 @@
|
||||
docker run -it --rm --name php -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:7-cli php generator.php
|
||||
sudo chown -R 1000:1000 *
|
Loading…
Reference in New Issue
Block a user