Skip to content

Instantly share code, notes, and snippets.

@m4p
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m4p/9931154 to your computer and use it in GitHub Desktop.
Save m4p/9931154 to your computer and use it in GitHub Desktop.
A bash script to download a twitch archive broadcast by its id number. needs axel and ffmpeg.
#!/bin/bash
ID=$1
DATA="$(curl -silent http://api.justin.tv/api/broadcast/by_archive/$ID.xml?onsite=true)"
URLs="$(echo $DATA | grep -io 'http.*\.flv')"
NAME="$(echo $DATA | grep '<title>' | head -n1 | sed 's/<title>//g' | sed 's/<\/title>//g' | sed 's/^ *//g' | sed 's/ /\./g'| sed 's/\///g'|sed s/\'//g)"
mkdir "$NAME"
cd "$NAME"
COUNTER=1
while read -r line; do
axel -a -n20 "$line"
filename="$(basename $line)"
mv "$filename" "$NAME.-.Part.$COUNTER".flv
let COUNTER=COUNTER+1
done <<< "$URLs"
for f in ./*.flv; do echo "file '$f'" >> file.list; done
ffmpeg -f concat -i file.list -c copy "$NAME.m4v"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment