Skip to content

Instantly share code, notes, and snippets.

@razvanioan
Forked from alexeygrigorev/vimeo-download.py
Last active September 1, 2022 13:01
Show Gist options
  • Save razvanioan/b40999ca807e09bfed1b20c07cd45e1c to your computer and use it in GitHub Desktop.
Save razvanioan/b40999ca807e09bfed1b20c07cd45e1c to your computer and use it in GitHub Desktop.
Downloading segmented video from vimeo
import requests
import base64
from tqdm import tqdm
master_json_url = 'https://109vod-adaptive.akamaized.net/exp=1662040711~acl=%2Fbc4b6790-2eb0-46e2-a2b4-6396b03d7ba4%2F%2A~hmac=b43d7d0ed71e01041955fb7559ec6230b4aaea55ef2b8a794f6abf4b1e319916/bc4b6790-2eb0-46e2-a2b4-6396b03d7ba4/sep/video/40079aa2,6e220c50,db93bcf5,7e658976,3f44d6fe/audio/9f9f9d50,ff94feee/master.json?query_string_ranges=1&base64_init=1'
base_url = master_json_url[:master_json_url.rfind('/video/') + 7]
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[1])
video = content['video'][idx]
video_base_url = base_url + video['base_url']
print ('base url:', video_base_url)
filename = 'video_%s.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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment