Skip to content

Instantly share code, notes, and snippets.

@grwlf
Last active October 21, 2023 20:04
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save grwlf/e1876f5d78cb6e66791809771d7bf36b to your computer and use it in GitHub Desktop.
Save grwlf/e1876f5d78cb6e66791809771d7bf36b 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"
@evil26r
Copy link

evil26r commented Dec 2, 2021

@mark99i алгоритм примерно следующий:

  1. Получить все .ts из m3u8
  2. вычлинить все байты из пейлоадов каждой части(part) .ts (в каждом part'е 8 байт заголовков)
  3. склеенные байты пейлоада и будет mp3

работает тоже медленно, но хотя бы все работает в памяти без io

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment