From 94d2cd604cb8086a52a99b39efc0a0965014152f Mon Sep 17 00:00:00 2001 From: Christopher Latza Date: Fri, 12 Jun 2020 15:05:43 +0200 Subject: [PATCH] add offline message --- message.json | 28 ---------------------------- start.php | 33 ++++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 39 deletions(-) delete mode 100644 message.json diff --git a/message.json b/message.json deleted file mode 100644 index 8306fbd..0000000 --- a/message.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "embeds": [ - { - "title": "RTMP Stream Online!", - "description": "Ein RTMP Stream ist jetzt online! Wenn du ihn dir anschauen willst, kannst du dies mit dem VLC Media Player tun.\nÖffne dazu den VLC Media Player, klicke oben links auf Medien und wähle Netzwerkstream. Dort trägst du dann folgene Adresse ein:\n\n%%adresse%%\n", - "color": 2139936, - "author": { - "name": "RTMP Noticer", - "url": "https://clatza.dev/Christopher/Discord-RTMP-Notice.git", - "icon_url": "https://files.clatza.dev/Icons/git.png" - }, - "image": { - "url": "%%vorschau%%" - } - }, - { - "title": "Stream wird aufgezeichnet.", - "description": "Für diesen Stream steht eine Aufzeichnung bereit.\nDu kannst dir den Stream in den nächsten 48 Stunden erneut anschauen.\nÖffne dazu den VLC Media Player, klicke auf Medien -> Netzwerkstream und gebe dort folgene URL ein.\n\n%%downloadURL%%\n", - "author": { - "name": "RTMP Noticer", - "url": "https://clatza.dev/Christopher/Discord-RTMP-Notice.git", - "icon_url": "https://files.clatza.dev/Icons/git.png" - } - } - ], - "username": "RTMP Noticer", - "avatar_url": "https://files.clatza.dev/Icons/vlc.png" -} \ No newline at end of file diff --git a/start.php b/start.php index af1d4e0..9e413b4 100644 --- a/start.php +++ b/start.php @@ -25,28 +25,39 @@ while(TRUE) copy($fileName, "tmp/rtmp/".$fileName); unlink($fileName); - $jsonMessage = file_get_contents("message.json"); + $jsonStartMessage = file_get_contents("startMessage.json"); + $jsonEndMessage = file_get_contents("endMessage.json"); - $jsonMessage = str_replace("%%adresse%%", $StreamURL, $jsonMessage); - $jsonMessage = str_replace("%%vorschau%%", "https://files.clatza.dev/tmp/rtmp/".$fileName, $jsonMessage); - $jsonMessage = str_replace("%%downloadURL%%", "https://files.clatza.dev/tmp/rtmp/".$videoFileName, $jsonMessage); + $jsonStartMessage = str_replace("%%adresse%%", $StreamURL, $jsonMessage); + $jsonStartMessage = str_replace("%%vorschau%%", "https://files.clatza.dev/tmp/rtmp/".$fileName, $jsonMessage); - $options = [ + $startOptions = [ 'http' => [ 'method' => 'POST', 'header' => 'Content-Type: application/json', 'timeout' => 5, - 'content' => $jsonMessage + 'content' => $jsonStartMessage ] ]; - echo "Sending info to discord..."; - $result = file_get_contents($DiscordWebhook, false, stream_context_create($options)); + $endOptions = [ + 'http' => [ + 'method' => 'POST', + 'header' => 'Content-Type: application/json', + 'timeout' => 5, + 'content' => $jsonEndMessage + ] + ]; + + echo "Sending start info to discord..."; + $result = file_get_contents($DiscordWebhook, false, stream_context_create($startOptions)); echo "done.\n"; - echo "Start Recording..."; - system("rtmpdump -r ".$StreamURL." -m 30 -o tmp/rtmp/".$videoFileName); - echo "done."; + system("rtmpdump -r ".$StreamURL." -m 15 -o /dev/null"); + + echo "Sending end info to discord..."; + $result = file_get_contents($DiscordWebhook, false, stream_context_create($endOptions)); + echo "done.\n"; }else{ echo "ERROR: Image not generated!\n"; }