Last active
January 31, 2019 21:01
-
-
Save daveyijzermans/58b65024e84790cb436a0ba49997050c to your computer and use it in GitHub Desktop.
Been using this script to record my favorite twitch channel using a raspberry pi, running this 24/7. Enjoy!
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/sh | |
### Twitch Recorder script ### | |
# This script checks whether a Twitch user is streaming and if so, | |
# will start recording it. | |
# | |
# Requires: curl, jq and livestreamer | |
clientId="TWITCH_CLIENT_ID" | |
recordingDir="/mnt/recordings" | |
channel=${1:-"twitchplayspokemon"} | |
setRecDir() | |
{ | |
sudo umount $recordingDir | |
sudo mount -a | |
if [ -d "$recordingDir" ]; then | |
actualDir=$recordingDir | |
else | |
actualDir="/home/pi/recordings" | |
mkdir -p $actualDir | |
echo "Unable to record to set recording directory. Recording to preset directory. Check recording directory before it is full." | |
fi | |
} | |
while true; do | |
printf "\rChecking stream... " | |
streamurl=$(livestreamer "twitch.tv/$channel" "1080p60,720p60,best" -Q --stream-url) | |
if [ $? -eq 0 ]; then | |
json=$(curl -s "https://api.twitch.tv/kraken/channels/$channel?client_id=$clientId" --max-time 10) | |
date=$(date +"%d %m %Y %H-%M-%S") | |
status=$(echo $json | jq '.status' | sed -e 's/[^A-Za-z0-9 ._-]/_/g' -e 's/^_*//' -e 's/_*$//') | |
setRecDir | |
streamName="$channel - $date - $status.mp4" | |
filename="$actualDir/$streamName" | |
echo "Start recording $streamName" | |
livestreamer "twitch.tv/$channel" "1080p60,720p60,best" -o "$filename" | |
echo "Stopped recording $streamName..." | |
else | |
msg="Not streaming." | |
fi | |
n=${2:-30} | |
while [ $n -gt 0 ]; do | |
printf "\r$msg Refreshing in %s " $n | |
sleep 1 | |
n=$((n-1)) | |
done | |
printf "\r " | |
done | |
exit 0 |
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/sh | |
cd | |
# Execute these commands to install and build the dependencies | |
sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y install screen wget curl nano git build-essential openssl jq libssl-dev python-setuptools libx264-dev | |
sudo easy_install livestreamer | |
livestreamer --twitch-oauth-authenticate # generate a twitch oauth token and put it in .livestreamerrc | |
echo "twitch-oauth-token=TOKEN" > .livestreamerrc | |
cd | |
git clone https://github.com/FFmpeg/FFmpeg.git | |
cd FFmpeg | |
sudo ./configure --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree --enable-openssl | |
make | |
sudo make install |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment