Skip to content

Instantly share code, notes, and snippets.

@sunapi386
Created October 26, 2019 23:02
Show Gist options
  • Save sunapi386/a324485ee9de8a322082ac93cf10c853 to your computer and use it in GitHub Desktop.
Save sunapi386/a324485ee9de8a322082ac93cf10c853 to your computer and use it in GitHub Desktop.
Fish shell script to download Vimeo video
#!/usr/bin/env fish
# Script to download videos from vimeo
# Vimeo streams the video to you in segments of m4s and so this script
# downloads all the segments until failure, then combines the segments
# into a single mp4 file.
function download_vimeo_video
if test (count $argv) -ne 2
echo "Require a topic and url"
echo "E.g. download_vimeo_video rifles https://skyfire.vimeocdn.com/1572130717-0x7f11ed0a574f8d7450aac24f4e125d4b81385b40/209635117/sep/video/1057526374/chop/segment-8.m4s"
return
end
set topic $argv[1]
set url $argv[2]
echo $topic $url
set BAD_REQUEST "1233275989"
# set segment (echo $url | cut -d'/' -f10)
# set segmentid (echo $segment | cut -d'.' -f1 | cut -c 9-)
# set videoid (echo $url | cut -d'/' -f5)
set n 0
# download all the videos
while true
set regex "s/segment-.\+\.m4s/segment-$n.m4s/"
set urlbase (echo $url | sed $regex)
set filename "$topic-$n.m4s"
echo $urlbase
set exec "curl $urlbase --output $filename"
set n (math "$n+1")
eval $exec
# check if bad download
if test $BAD_REQUEST = (cksum $filename | cut -d' ' -f1)
rm $filename
echo "done"
break
end
cat "$filename" >> "$topic-all.m4s"
end
# merge all videos together
ffmpeg -i "$topic-all.m4s" -c copy $topic.mp4
rm "$topic*.m4s"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment