archive/webhook/index.php

47 lines
1.4 KiB
PHP
Raw Normal View History

2018-11-19 21:09:20 +00:00
<?php
2020-06-28 06:55:55 +00:00
$json = json_decode(file_get_contents('php://input'), true);
2018-11-19 21:09:20 +00:00
$excluded_djs = [
"alrs",
2021-03-24 14:29:41 +00:00
"cat",
"dctrud",
2020-12-11 05:07:14 +00:00
"epoch",
"vivi",
2021-03-24 21:48:35 +00:00
"ten_forward"
];
2020-06-28 06:55:55 +00:00
if ($json["live"]["is_live"]) {
2018-11-19 21:09:20 +00:00
// start recording
2020-06-28 06:55:55 +00:00
$streamer = $json["live"]["streamer_name"];
2018-11-19 21:09:20 +00:00
if (!in_array($streamer, $excluded_djs)) {
2020-07-15 22:52:13 +00:00
$current_pid = intval(file_get_contents("ffmpeg.pid"));
// posix_kill with 0 signal tells you if the process is running
if ($current_pid != "" && posix_kill($current_pid, 0)) die();
2018-11-19 21:09:20 +00:00
2020-07-15 22:52:13 +00:00
$timestamp = date("Y-m-d\TH_i_s");
if (!is_dir(__DIR__."/../$streamer")) {
mkdir(__DIR__."/../$streamer");
copy(__DIR__."/../djindex.php", __DIR__."/../$streamer/index.php");
}
2018-11-19 21:09:20 +00:00
2020-07-15 22:52:13 +00:00
$standard_stream = "https://radio.tildeverse.org/radio/8000/radio.ogg";
$testing_stream = "https://radio.tildeverse.org/radio/8010/radio.mp3";
$metadata = "-metadata title=\"tilderadio archive - $timestamp\" -metadata artist=\"$streamer\"";
$cmd = "/usr/bin/ffmpeg -i $standard_stream $metadata ../$streamer/tilderadio-$streamer-$timestamp.mp3 >out.log 2>&1 & echo $!";
$pid = exec($cmd);
2018-11-19 21:09:20 +00:00
2020-07-15 22:52:13 +00:00
echo $pid;
file_put_contents("ffmpeg.pid", $pid);
}
2018-11-19 21:09:20 +00:00
} else {
// stop recording
$pid = file_get_contents("ffmpeg.pid");
if ($pid != "" && posix_kill(intval($pid), 0)) {
posix_kill(intval($pid), 2);
file_put_contents("ffmpeg.pid", "");
}
}