Skip to content

Instantly share code, notes, and snippets.

@robalni
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save robalni/70e0cb6721e1083f9ff7 to your computer and use it in GitHub Desktop.

Select an option

Save robalni/70e0cb6721e1083f9ff7 to your computer and use it in GitHub Desktop.
get-quote
#!/bin/bash
date_diff()
{
s1=$(date -d $1 +%s)
s2=$(date -d $2 +%s)
diff=$((s2-s1))
echo $diff
}
if [[ $# -ne 2 ]]; then
echo "I need two arguments: date, name"
exit
fi
quote_date="$1"
name="$2"
url="https://api.twitch.tv/kraken/channels/$name/videos?broadcasts=true"
temp_file=$(mktemp)
curl -s $url > $temp_file
rec_dates=$(jq -r ".videos[].recorded_at" $temp_file)
urls=$(jq -r ".videos[].url" $temp_file)
rm $temp_file
vidtime=-1
i=0
for rd in $rec_dates; do
diff=$(date_diff $rd $quote_date)
if [[ $diff -ge 0 ]]; then
vidtime=$diff
fi
let i++
if [[ $vidtime -ge 0 ]]; then
break
fi
done
if [[ $vidtime -lt 0 ]]; then
echo "Quote is older than page 1."
exit
fi
url=$(echo $urls | awk "{print \$$i}")
vidtime=$((vidtime - 60))
livestreamer --player-passthrough=hls -vp avconv \
-a "-y -ss $vidtime -i {filename} -c:a copy -c:v copy -t 60 quote.flv" \
$url
mplayer quote.flv &
avconv -y -i quote.flv -c:a pcm_s16le -vn quote.wav
disown -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment