Skip to content

Instantly share code, notes, and snippets.

@jtbonhomme
Created April 17, 2016 17:48
Show Gist options
  • Save jtbonhomme/20876ada6c9bf564da98120235f4a022 to your computer and use it in GitHub Desktop.
Save jtbonhomme/20876ada6c9bf564da98120235f4a022 to your computer and use it in GitHub Desktop.
This script downloads a VOD multi profile HLS content in a local directory
#!/bin/bash
# ./captureHls.sh http://www.cdn.com/master.m3u8 DIRECTORY
URL=$1
OUTPUT=$2
# create output directory
if [ -d $OUTPUT ]
then
echo "Directory $OUTPUT already exists"
else
echo "Create directory $OUTPUT"
mkdir $OUTPUT
fi
pushd $OUTPUT
echo "Download master playlist"
curl -s -o master.m3u8.tmp $URL
for i in `cat master.m3u8.tmp|grep http`
do
index=`echo -n $i |sed 's/^http.*\/\(.*[.]m3u8\)$/\1/g'`
echo "Download index: "$index
curl -s -o $index.tmp $i
for j in `cat $index.tmp|grep http`
do
echo "Download chunk "$j
curl -s -O $j
done
cat $index.tmp | sed 's/^http.*\/\(.*[.]ts\)$/\1/g' > $index
rm $index.tmp
done
cat master.m3u8.tmp| sed 's/^http.*\/\(.*[.]m3u8\)$/\1/g' > master.m3u8
rm master.m3u8.tmp
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment