Skip to content

Instantly share code, notes, and snippets.

@SavSanta
Forked from grwlf/vkontakte_m3u8_downloader.sh
Created October 29, 2022 19:21
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 SavSanta/6109e5dfb51eceea9688fbd59095d75d to your computer and use it in GitHub Desktop.
Save SavSanta/6109e5dfb51eceea9688fbd59095d75d to your computer and use it in GitHub Desktop.
vkontakte_m3u8_downloader.sh
#!/bin/sh
# VKontakte *m3u8 downloader
# Worked at the time of writing
mkdir /tmp/m3u8
set -e -x
cd /tmp/m3u8
rm *
# Download m3u8.
url=$1
urldir=`dirname $url`
wget $url -O index.m3u8
# Download first key into 'key.pub'. We expect it is the only key used.
keyurl=`sed -n 's@.*\(https.*key.pub\).*@\1@ p' index.m3u8 | head -n 1`
wget $keyurl
# Replace http urls with local file names
# Download ts segments
cat index.m3u8 | \
sed 's@"https.*pub?.*"@key.pub@g' | \
sed 's@ts?.*@ts@g' >index_local.m3u8
for line in `cat index_local.m3u8 | grep -v '^#'` ; do
wget `dirname $url`/$line
done
# Concat and decrypt ts-segments with ffmpeg, which understands local filesystem paths
ffmpeg -allowed_extensions 'ALL' -protocol_whitelist 'crypto,file' -i index_local.m3u8 -c copy out.ts
# Go grab the output
echo "`pwd`/out.ts"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment