Skip to content

Instantly share code, notes, and snippets.

@tayiorbeii
Created February 24, 2017 17:18
Show Gist options
  • Save tayiorbeii/d78c7e4b338b031ce8090b30b395a46f to your computer and use it in GitHub Desktop.
Save tayiorbeii/d78c7e4b338b031ce8090b30b395a46f to your computer and use it in GitHub Desktop.
Usage: `python vimeo_downloader.py https://...master.json optional_name.mp4` modified from https://gist.github.com/alexeygrigorev/a1bc540925054b71e1a7268e50ad55cd
import requests
import base64
from tqdm import tqdm
import sys
master_json_url = sys.argv[1]
base_url = master_json_url[:master_json_url.rfind('/', 0, -26) + 1]
resp = requests.get(master_json_url)
content = resp.json()
heights = [(i, d['height']) for (i, d) in enumerate(content['video'])]
idx, _ = max(heights, key=lambda (_, h): h)
video = content['video'][idx]
video_base_url = base_url + video['base_url']
print 'base url:', video_base_url
filename = sys.argv[2] if sys.argv[2] else 'video_%d.mp4' % video['id']
print 'saving to %s' % filename
video_file = open(filename, 'wb')
init_segment = base64.b64decode(video['init_segment'])
video_file.write(init_segment)
for segment in tqdm(video['segments']):
segment_url = video_base_url + segment['url']
resp = requests.get(segment_url, stream=True)
if resp.status_code != 200:
print 'not 200!'
print resp
print segment_url
break
for chunk in resp:
video_file.write(chunk)
video_file.flush()
video_file.close()
@paschoaletto
Copy link

I've modified this code to download video & audio segmented and encode them in one .mp4 file: https://gist.github.com/paschoaletto/7f65b7e36b76ccde9fe52b74b62ab9df

@eMBee
Copy link

eMBee commented Apr 6, 2017

i have merged all gists into a repo here: https://github.com/eMBee/vimeo-download

@vaibhavbangwal
Copy link

How can I download Bitmovin Player videos which are embedded as XHR types of multiple-segmented files with iFrame?
https://104.199.144.5:1935/vod/smil:4219201806131300.smil/chunk_ctaudio_ridp0aa0br125000_cs58211206_w230083586_mpd.m4s

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