Last active
March 25, 2017 15:10
-
-
Save fcicq/3154529395659339082b to your computer and use it in GitHub Desktop.
Recorder for ustream.tv. usage: ustream.sh CHANNELID [loop]
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 | |
# coding: utf-8 | |
# ustreamtv.sh by fcicq | |
(jq --version 1>/dev/null 2>&1) || (echo 'install jq first'; exit) | |
(livestreamer --version 1>/dev/null 2>&1) || (echo 'install livestreamer first (run pip/pip3 install livestreamer)'; exit) | |
if [ -n "$1" ]; then | |
id=$(echo "$1" | sed 's|^.*/||g') | |
while true; do | |
while true; do | |
(curl -s "https://api.ustream.tv/channels/$id.json" | jq ".channel | {id: .id, status:.status}" | grep "live") && break | |
echo "Not Alive, Sleeping $(date +'%F_%H-%M-%S')" | |
sleep 30 | |
done | |
fname="${id}_$(date +'%F_%H-%M-%S').ts" | |
url="http://iphone-streaming.ustream.tv/uhls/$id/streams/live/playlist.m3u8" | |
livestreamer --hls-segment-threads 3 --hls-segment-timeout 1.5 --http-timeout 1.5 -o "$fname" "hlsvariant://$url" best | |
# ffmpeg -nostdin -i "$url" \ | |
# -vcodec copy -acodec copy -f mpegts "$fname" | |
if [ "$2" != "loop" ]; then | |
break | |
fi | |
done | |
else | |
echo "usage: $0 cid" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment