Last active
June 15, 2017 15:16
-
-
Save M4GNV5/48d6f036179eb69b8d926421e867b3b4 to your computer and use it in GitHub Desktop.
radio using Pointerscript + ffserver + ffmpeg + youtube-dl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function printUsage | |
{ | |
printf "Commands:\n h : show this help\n c : clear the screen\n\ | |
q : quit\n r : restart player\n l : view player log\n\ | |
<id> : add id to queue\n" | |
} | |
printUsage | |
printf "\n" | |
player="" | |
function restartPlayer | |
{ | |
ffplay -nodisp http://m4gnus.de:8100/ytaudio.mp3 > /tmp/avplay.log 2>&1 & | |
player=$! | |
} | |
restartPlayer | |
while true; do | |
printf "INPUT: " | |
read input | |
input=$(echo "$input" | xargs) | |
if [ "$input" == "h" ]; then | |
printUsage | |
elif [ "$input" == "c" ]; then | |
clear | |
elif [ "$input" == "q" ]; then | |
kill -9 "$player" | |
exit 0 | |
elif [ "$input" == "r" ]; then | |
kill -9 "$player" | |
restartPlayer | |
elif [ "$input" == "l" ]; then | |
tail /tmp/avplay.log | |
printf "\n" | |
elif [ $(expr length "$input") -gt 10 ]; then | |
printf "SECRETHERE\n$input\n" | nc m4gnus.de 8101 | |
else | |
printf "Invalid input %s\n" "$input" | |
fi | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HTTPPort 8100 | |
HTTPBindAddress 0.0.0.0 | |
MaxHTTPConnections 2000 | |
MaxClients 1000 | |
#kbit/s | |
MaxBandwidth 3000 | |
CustomLog - | |
<Feed ytaudio.ffm> | |
#File /tmp/ytaudio.ffm | |
#FileMaxSize 100M | |
ACL allow 127.0.0.1 | |
</Feed> | |
<Stream ytaudio.mp3> | |
Feed ytaudio.ffm | |
Metadata title "YT Audio" | |
#AudioCodec libopus | |
AudioBitRate 256 | |
AudioChannels 2 | |
AudioSampleRate 44100 | |
NoVideo | |
</Stream> | |
<Stream status.html> | |
Format status | |
</Stream> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SECRET = "SECRETHERE"; | |
import strcmp, strchr, strstr, strdup, | |
system, popen, pclose, | |
fgets, free, printf; | |
import pthread_create, pthread_detach from "libpthread.so.0"; | |
import SocketServer from "../PtrsStuff/libs/network.ptrs"; | |
import List from "../PtrsStuff/libs/list.ptrs"; | |
import MutexWrap from "../PtrsStuff/libs/mutex.ptrs"; | |
var running = false; | |
var playerThread; | |
var queue = new MutexWrap(new List()); | |
function playerWorker() | |
{ | |
while(queue.length > 0) | |
{ | |
var curr = queue.remove(0); | |
system("youtube-dl %s -o - | ffmpeg -re -i - http://127.0.0.1:8100/ytaudio.ffm" % curr); | |
free(curr); | |
} | |
running = false; | |
} | |
function handleClient(sock) | |
{ | |
var buff{256}; | |
if(sock.available(1000)) | |
{ | |
buff[sock.read(buff, 255, '\n', false) - 1] = 0; | |
if(strcmp(buff, SECRET) != 0) | |
return sock.sends("Invalid secret\n"); | |
sock.available(1000); | |
buff[sock.read(buff, 255, '\n', false) - 1] = 0; | |
if(strstr(buff, "list=") != NULL) | |
{ | |
var p = popen(("youtube-dl --get-id '%s'" % buff), "r"); | |
while(fgets(buff, 255, p) != NULL) | |
{ | |
var newline = as<native>strchr(buff, '\n'); | |
if(newline != NULL) | |
*newline = 0; | |
queue.add(strdup(buff)); | |
sock.sends("Added %s to queue at place %d\n" % buff, queue.length); | |
} | |
pclose(p); | |
} | |
else | |
{ | |
queue.add(strdup(buff)); | |
sock.sends("Added %s to queue at place %d\n" % buff, queue.length); | |
} | |
if(!running) | |
{ | |
pthread_create(&playerThread, NULL, playerWorker, NULL); | |
pthread_detach(&playerThread); | |
running = true; | |
} | |
} | |
} | |
var server = new SocketServer(8101); | |
while(true) | |
{ | |
var sock = server.accept(500); | |
try | |
{ | |
handleClient(sock); | |
} | |
catch(err, trace) | |
{ | |
printf("%s\n%s", err, trace); | |
} | |
delete sock; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment