Skip to content

Instantly share code, notes, and snippets.

@zmwangx
Last active June 8, 2019 08:47
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zmwangx/be5022ae3c26d558f64bfc8632daad4e to your computer and use it in GitHub Desktop.
Save zmwangx/be5022ae3c26d558f64bfc8632daad4e to your computer and use it in GitHub Desktop.
v.qq.com SHD downloader (腾讯超清视频下载) https://github.com/soimort/you-get/issues/1298#issuecomment-236489420
#!/usr/bin/env zsh
print_progress () print -R $'\e[32m'"$*"$'\e[0m' >&2
print_error () print -R $'\e[31m'"Error: $*"$'\e[0m' >&2
# Obvious parameters
vid=f00213kcpwl
defn=shd
# To be extracted from browser's network inspector
appver=3.2.19.358
encryptver=5.4
platform=70902
format=10201
ckey=x-NT24B0-3FJRXQI6uALnc12Ws8AVeCu2DmFBWMmWK2yzefOiiRUyvB8ol_69Y09sIPJu3mp4RhTc7oEaog0sXSh12zwBuyUGmjsbCjFiFU1zkUBlLxyjhyCATw7ogn91GxDB8IfzzyAqL3byEqTgOz_Yy3hRoPq_d88CXJDv7x-ynNV7uXL2f0Araieh1w6cLoFFEqbGCNqmAmYqqhkHQB9Sjkvaqr8UaLdPq5UYUSBvyOLkLij7IPIfM5O0SuQpp96aP5Cxug4bgPN2tbbyG0vbp4 # valid for a limited period of time, probably ~30min
parts=()
ffmpeg_concat_list=$vid.list
trap 'rm -f $ffmpeg_concat_list' EXIT
cat /dev/null >$ffmpeg_concat_list
vinfo=$(curl -sS 'http://vv.video.qq.com/getvinfo' --data "otype=json&appver=$appver&platform=$platform&defn=$defn&vid=$vid&cKey=$ckey" | sed 's/^QZOutputJson=//; s/;$//')
base_url=$(jq -r '.vl.vi[].ul.ui[0].url' <<< $vinfo)
base_filename=${$(jq -r '.vl.vi[].fn' <<< $vinfo)%.mp4}
total=$(jq -r '.vl.vi[].cl.ci | length' <<< $vinfo)
jq -r '.vl.vi[].cl.ci[] | ((.idx | tostring) + " " + (.cs | tostring) + " " + .cmd5)' <<< $vinfo | \
while read index size md5; do
segment_filename=$base_filename.$index.mp4
vkey=$(curl -sS 'http://vv.video.qq.com/getvkey' --data "otype=json&appver=$appver&encryptVer=$encryptver&platform=$platform&format=$format&vid=$vid&cKey=$ckey&filename=$segment_filename" | sed 's/^QZOutputJson=//; s/;$//' | jq -r '.key')
print_progress "Downloading part $index/$total..."
curl -Lo $segment_filename "$base_url/$segment_filename?vkey=$vkey"
realsize=$(wc -c <$segment_filename)
realmd5=$(openssl md5 -binary $segment_filename | xxd -p)
if [[ $md5 != $realmd5 ]]; then
print_error "$segment_filename: MD5 mismatch, expecting $md5, got $realmd5."
exit 1
fi
if [[ $size != $realsize ]]; then
print_error "$segment_filename: Size mismatch, expecting $size, got $realsize."
exit 1
fi
parts+=$segment_filename
print -R "file '$segment_filename'" >>$ffmpeg_concat_list
done
print_progress "Concatenating into $vid.mp4..."
if ffmpeg -f concat -safe -1 -i $ffmpeg_concat_list -c copy $vid.mp4; then
print_progress "Concatenated into $vid.mp4."
rm $parts
else
print_error 'Concatenation failed.'
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment