Last active
September 13, 2022 13:52
-
-
Save paschoaletto/7f65b7e36b76ccde9fe52b74b62ab9df to your computer and use it in GitHub Desktop.
Downloads segmented audio+video from Vimeo and saves as .mp4 - Usage: 'python vimeo_downloader.py http://...master.json?base64_init=1 optional_name' modified from https://gist.github.com/tayiorbeii/d78c7e4b338b031ce8090b30b395a46f that was modified from https://gist.github.com/alexeygrigorev/a1bc540925054b71e1a7268e50ad55cd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import base64 | |
from tqdm import tqdm | |
import sys | |
import subprocess as sp | |
FFMPEG_BIN = 'ffmpeg.exe' | |
master_json_url = sys.argv[1] | |
base_url = master_json_url[:master_json_url.rfind('/', 0, -26) - 5] | |
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/' + video['base_url'] | |
print 'base url:', video_base_url | |
filename = 'v.mp4' | |
video_filename = filename | |
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() | |
audio = content['audio'][0] | |
audio_base_url = base_url + audio['base_url'][3:] | |
print 'base url:', audio_base_url | |
filename = 'a.mp3' | |
audio_filename = filename | |
print 'saving to %s' % filename | |
audio_file = open(filename, 'wb') | |
init_segment = base64.b64decode(audio['init_segment']) | |
audio_file.write(init_segment) | |
for segment in tqdm(audio['segments']): | |
segment_url = audio_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: | |
audio_file.write(chunk) | |
audio_file.flush() | |
audio_file.close() | |
filename = sys.argv[2] + '.mp4' if sys.argv[2] else 'video.mp4' | |
command = [ FFMPEG_BIN, | |
'-y', # (optional) overwrite output file if it exists | |
'-i', audio_filename, | |
'-i',video_filename, | |
'-acodec', 'copy', | |
'-vcodec', 'h264', | |
filename ] | |
sp.call(command, shell=True) |
What if there is no master.json?
http://104.199.144.5:1935/vod/smil:4209201712080900.smil/chunk_ctaudio_ridp0aa0br64000_cs880633_w1255087167_mpd.m4s -- there are several links like this. How do I download these chunks ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you're using Linux, you'll need a few changes:
FFMPEG_BIN = 'ffmpeg.exe'
to:
FFMPEG_BIN = 'ffmpeg'
and
to:
Tested in Fedora 26.