Skip to content

Instantly share code, notes, and snippets.

@bliof
Created March 8, 2015 16:23
Show Gist options
  • Save bliof/6d458f8424e913fccc7b to your computer and use it in GitHub Desktop.
Save bliof/6d458f8424e913fccc7b to your computer and use it in GitHub Desktop.
Script for downloading video from twich.tv
#!/bin/bash
# Example:
# http://www.twitch.tv/aziliann/b/633376838
# ./download-twich-video.sh 633376838
id=$1
dir=$(pwd)
tmp_dir=".tmp-dtv-files"
video_parts_dir="$tmp_dir/$id"
set -e
urls=($(
curl --silent "https://api.twitch.tv/api/videos/a$id" | perl -MData::Dumper -MJSON=from_json -ne'
print $_->{url} . "\n" foreach @{from_json($_)->{chunks}->{live}}
'
))
mkdir -p $video_parts_dir
for i in "${!urls[@]}"; do
url=${urls[$i]}
wget $url -O "$video_parts_dir/part-$i.flv" -nv
done
ffmpeg -f concat -i <(printf "file '${dir}/%s'\n" $video_parts_dir/*.flv) -c copy "$id.flv"
rm -rf $video_parts_dir
if [ $(find $tmp_dir -prune -empty -type d) ]; then
rm -rf $tmp_dir
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment