Initial commit
This commit is contained in:
3
web/Dockerfile
Normal file
3
web/Dockerfile
Normal file
@@ -0,0 +1,3 @@
|
||||
FROM php:apache
|
||||
|
||||
COPY . /var/www/html
|
||||
52
web/admin.php
Normal file
52
web/admin.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
html { background: #505; color: white; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<form method="GET">
|
||||
<input type="hidden" name="auth" value="<?php echo $_GET['auth'] ?>" />
|
||||
<input type="submit" name="action" value="NEXT" />
|
||||
<input type="submit" name="action" value="INFO" />
|
||||
<input type="submit" name="action" value="REFRESH" />
|
||||
</form>
|
||||
<?php
|
||||
include('functions.php');
|
||||
if ($_REQUEST['action']) {
|
||||
echo '<pre>';
|
||||
switch ($_REQUEST['action']) {
|
||||
case 'NEXT':
|
||||
echo telnet_send("dodsorfas(dot)main.skip");
|
||||
break;
|
||||
case 'INFO':
|
||||
cool_print(get_infos(), 'debug');
|
||||
break;
|
||||
case 'DIRE':
|
||||
echo "TODO";
|
||||
break;
|
||||
case 'REQUEST':
|
||||
echo "TODO";
|
||||
break;
|
||||
case 'REFRESH':
|
||||
break;
|
||||
default:
|
||||
print_r($_REQUEST);
|
||||
print_r($_ENV);
|
||||
break;
|
||||
}
|
||||
echo '</pre>';
|
||||
}
|
||||
?>
|
||||
<table border="1">
|
||||
<thead>
|
||||
<th>Title</th>
|
||||
</thead>
|
||||
<?php foreach (get_metadata() as $song) { ?>
|
||||
<tr>
|
||||
<td><?php print($song['right_title']);?> </td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
124
web/functions.php
Normal file
124
web/functions.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
function telnet_send($command) {
|
||||
$fp = stream_socket_client($_ENV['MAIN_PORT_5000_TCP'], $errno, $errstr, 5);
|
||||
if (!$fp) {
|
||||
return("<b><u>TELNET FAILURE:</u> $errstr ($errno)</b><br>");
|
||||
}
|
||||
fwrite($fp, "$command\nquit\n");
|
||||
$eat = '';
|
||||
while (!feof($fp)) {
|
||||
$eat .= fgets($fp, 1024);
|
||||
}
|
||||
fclose($fp);
|
||||
return $eat;
|
||||
}
|
||||
|
||||
function cache_get($name) {
|
||||
$cache_file = "$name.cache";
|
||||
if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 5 ))) {
|
||||
return json_decode(file_get_contents($cache_file));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function cache_set($name, $value) {
|
||||
$cache_file = "$name.cache";
|
||||
file_put_contents($cache_file, json_encode($value), LOCK_EX);
|
||||
}
|
||||
function get_infos() {
|
||||
$infos = array();
|
||||
$metadata = get_metadata();
|
||||
$infos['current'] = array_shift($metadata);
|
||||
//include_once('getid3/getid3/getid3.php');
|
||||
//$getID3 = new getID3;
|
||||
$infos['history'] = $metadata;
|
||||
return $infos;
|
||||
}
|
||||
function get_metadata() {
|
||||
$entries = cache_get('metadata');
|
||||
if ($entries) {
|
||||
foreach ($entries as $key => $value) {
|
||||
$entries[$key] = (array)$value;
|
||||
}
|
||||
} else {
|
||||
$lines = explode("\n", trim(telnet_send("dodsorfas(dot)main.metadata")));
|
||||
$entries_assoc = [];
|
||||
$entry_number = 0;
|
||||
foreach ($lines as $line) {
|
||||
if (in_array(trim($line), array('END', 'Bye!'))) {
|
||||
continue;
|
||||
}
|
||||
$match = preg_match('/^---\ ([0-9]*)\ ---/', $line, $search);
|
||||
if ($match) {
|
||||
if ($entry_number) {
|
||||
$entries_assoc[$entry_number] = $entry;
|
||||
}
|
||||
$entry_number = intval($search[1]);
|
||||
$entry = array();
|
||||
} else {
|
||||
$value = explode('=', $line, 2);
|
||||
$entry[$value[0]] = trim(trim($value[1]), '"');
|
||||
}
|
||||
}
|
||||
$entries_assoc[$entry_number] = $entry;
|
||||
$entries = array();
|
||||
for ($i = 1; $i < sizeof($entries_assoc); $i++) {
|
||||
$entry = $entries_assoc[$i];
|
||||
$pos = strrpos($entry['title'], '(');
|
||||
$entry['left_title'] = trim(substr($entry['title'], 0, $pos));
|
||||
$entry['right_title'] = substr(trim(substr($entry['title'], $pos)), 1, -1);
|
||||
if (preg_match('/(LIVE de copains- radio Salut c\'est cool)/', $entry['title'])) {
|
||||
$entry['live'] = 1;
|
||||
$entry['mode'] = 'live';
|
||||
$entry['artist'] = 'Copains de salut c\'est cool';
|
||||
} else if (preg_match('/(LIVE de SCC - radio Salut c\'est cool)/', $entry['title'])) {
|
||||
$entry['live'] = 1;
|
||||
$entry['mode'] = 'live';
|
||||
$entry['live_artist'] = 'scc';
|
||||
//$entry['artist'] = 'salut c\'est cool';
|
||||
} else {
|
||||
$mode = explode(' - ', $entry['right_title']);
|
||||
$entry['live'] = 0;
|
||||
if ($mode[0]) {
|
||||
$entry['mode'] = $mode[0];
|
||||
}
|
||||
}
|
||||
if (empty($entry['full_title'])) {
|
||||
if ($entry['artist'] && $entry['left_title']) {
|
||||
$entry['full_title'] = sprintf('%s - %s', $entry['artist'], $entry['left_title']);
|
||||
} else {
|
||||
$entry['full_title'] = $entry['left_title'];
|
||||
}
|
||||
}
|
||||
if (empty($entry['full_title'])) {
|
||||
//$entry['full_title'] = 'Morceau sans nom';
|
||||
$entry['full_title'] = basename($entry['filename']);
|
||||
}
|
||||
/*if ($entry['live_artist'] == 'scc') {
|
||||
if (empty($entry['full_title'])) {
|
||||
$entry['full_title'] = 'salut c\'est cool en live';
|
||||
} else {
|
||||
$entry['full_title'] = sprintf('salut c\'est cool en live (%s)', $entry['full_title']);
|
||||
}
|
||||
}*/
|
||||
$entries[] = $entry;
|
||||
}
|
||||
cache_set('metadata', $entries);
|
||||
}
|
||||
return $entries;
|
||||
}
|
||||
function cool_print($data, $format) {
|
||||
switch ($format) {
|
||||
case 'json':
|
||||
echo(json_encode($data));
|
||||
break;
|
||||
case 'jsonp':
|
||||
printf("%s(%s);", $_GET['callback'], json_encode($data));
|
||||
break;
|
||||
case 'debug':
|
||||
echo '<pre>';
|
||||
print_r($data);
|
||||
echo '</pre>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
?>
|
||||
24
web/index.php
Normal file
24
web/index.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
include('functions.php');
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$url = $_POST['url'];
|
||||
|
||||
$url = preg_replace("/:/", "$(colon)", $url);
|
||||
|
||||
echo telnet_send("request.push ffmpeg2wav:youtube-dl:" . $url);
|
||||
}
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Radio Dodsorfas</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<form action="/index.php" method="post">
|
||||
Song: <input type="text" name="url"><br>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user