Skip to content

Instantly share code, notes, and snippets.

@alexeygrigorev
Created September 17, 2016 09:09
Show Gist options
  • Save alexeygrigorev/a1bc540925054b71e1a7268e50ad55cd to your computer and use it in GitHub Desktop.
Save alexeygrigorev/a1bc540925054b71e1a7268e50ad55cd 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://178skyfiregce-a.akamaihd.net/exp=1474107106~acl=%2F142089577%2F%2A~hmac=0d9becc441fc5385462d53bf59cf019c0184690862f49b414e9a2f1c5bafbe0d/142089577/video/426274424,426274425,426274423,426274422/master.json?base64_init=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 = '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()
@abdus
Copy link

abdus commented Jan 1, 2021

Easier, if you have youtube-dl installed:

  1. copy the master.json URL
  2. replace .json?base64_init=1 with .mpd
  3. provide it to youtube-dl: youtube-dl EDITED_URL

yt-dl will download the best quality available :)

@franzo15
Copy link

Easier, if you have youtube-dl installed:

  1. copy the master.json URL
  2. replace .json?base64_init=1 with .mpd
  3. provide it to youtube-dl: youtube-dl EDITED_URL

yt-dl will download the best quality available :)

it works like a charm!

@madhurnawandar
Copy link

Thanks, very useful. I made a version which combines audio and video download in a single file (just took the two scripts @alexeygrigorev and @brasno), using ffmpeg: https://github.com/AbCthings/vimeo-audio-video

Thanks. It works

@balexandre
Copy link

just to update my previous answer as some sources no longer provide the referer as an option

image

steps:

  • open inspector in the Network tab
  • filter the search with player.vimeo
  • refresh the page (so the video can be loaded and show in the network tab)
  • open the item and copy the Request URL
  • in a free service like SaveMeVideo paste that full URL and click Download
  • choose the right resolution you want, right-click and choose Save link as...

@pedropcruz
Copy link

hey @abdus just a question, where is that master.json? Thanks

@MuerMas
Copy link

MuerMas commented Feb 12, 2022

@pedropcruz

hey @abdus just a question, where is that master.json? Thanks
master json

@dantebarba
Copy link

I think this option is not available now at least from the source my trying to download from. They are using some sort of anti-scrapping (Akamai) to prevent you from downloading from outside the original source.

@balexandre
Copy link

balexandre commented Mar 26, 2022

@dantebarba
Copy link

@bsalamakha
Copy link

Easier, if you have youtube-dl installed:

  1. copy the master.json URL
  2. replace .json?base64_init=1 with .mpd
  3. provide it to youtube-dl: youtube-dl EDITED_URL

yt-dl will download the best quality available :)

it works like a charm!

This method sort of still works. Instead of changing all of ".json?base64_init=1" with ".mpd"
Just tested and works by just replacing ".json" with ".mpd" leaving everything else intact. E.g., [URL].mpd?base64_init=1

@mohamedhaddi
Copy link

@abdus

Easier, if you have youtube-dl installed:

  1. copy the master.json URL
  2. replace .json?base64_init=1 with .mpd
  3. provide it to youtube-dl: youtube-dl EDITED_URL

yt-dl will download the best quality available :)

Dope! Works perfectly. Thanks.

@Sogl
Copy link

Sogl commented Sep 12, 2022

@abdus

It worked quite recently, but now youtube-dl and yt-dlp shows me the same error:

ERROR: unable to download video data: HTTP Error 403: Forbidden

@JonnieCache
Copy link

JonnieCache commented Nov 11, 2022

The key is to change json to mpd, remove base64_init=1 but keep query_string_ranges=1 at the end, so

master.mpd?query_string_ranges=1

@manish-makwana
Copy link

The key is to change json to mpd, remove base64_init=1 but keep query_string_ranges=1 at the end, so

master.mpd?query_string_ranges=1

Thank you!! this solved it for me - nothing else worked.

@OGProgrammer
Copy link

The YouTube-dl was the trick, I downloaded the latest Mac release, installed ffmpeg via home-brew, and found the master.json and changed to .mpd and removed base64 url part. Seems to be working! Was skeptical because this says YouTube but did in fact work for Vimeo.

@tinglycraniumplacidly
Copy link

The key is to change json to mpd, remove base64_init=1 but keep query_string_ranges=1 at the end, so

master.mpd?query_string_ranges=1

hero!

@manish-makwana
Copy link

manish-makwana commented Feb 11, 2023 via email

@Somstradamus
Copy link

sorry, mega n00b here, but where do I download YouTube-dl?

@manish-makwana
Copy link

sorry, mega n00b here, but where do I download YouTube-dl?

http://ytdl-org.github.io/youtube-dl/download.html

@Somstradamus
Copy link

nevermind, I finally dit it but, despite having ffmpeg installed, the command prompt says this (bold):

C:\Users\User\Downloads>youtube-dl.exe https://191vod-adaptive.akamaized.net/exp=1682170382~acl=/d4844fb3-b791-47ab-abbe-295778afe9f6/*~hmac=220d9c1430786cb2339b3af3e09XXXXXXXXXXXXX (sensible content so had to censor)354054850fa99c5e5ef/d4844fb3-b791-47ab-abbe-295778afe9f6/sep/video/10450380,3226820b,a02b9e37,b330b035,fb75fb5d/audio/38617de8,8c26e513,b4d2f1e7/master.mpd?query_string_ranges=1
[generic] master: Requesting header
WARNING: Falling back on generic information extractor.
[generic] master: Downloading webpage
[generic] master: Extracting information
WARNING: You have requested multiple formats but ffmpeg or avconv are not installed. The formats won't be merged.
[dashsegments] Total fragments: 764
[download] Destination: master-master.fvideo-10450380.mp4
[download] 100% of 282.79MiB in 01:38
[dashsegments] Total fragments: 764
[download] Destination: master-master.faudio-8c26e513.m4a
[download] 100% of 104.16MiB in 01:23

So I end up with a .mp4 and .m4a files but can't merge them in once which was the initial goal :(

Any suggestion on why youtube-dl won't merge it?

@Somstradamus
Copy link

Somstradamus commented Apr 22, 2023

found the fix, youtube-dl.exe needed to be in the same folder than ffmeg.exe, silly me

thanks to all of you, guys, you made my day

@DraZen-es
Copy link

I had some fails on some test videos, after checking the json i found this structure:
"base_url": "../../../",
"video": [{
"id": "xxxxx",
"base_url": "../../parcel/video/",

So i made this adjustment:
video_base_url = base_url + content['base_url'] + video['base_url'] resulting in an url like this: http://xxxx.xx/xxx/../../../parcel/video/
Same for audio part

so i have a full url with the steps back and it works fine now.

Hope it helps

@divStar
Copy link

divStar commented Jun 29, 2023

The key is to change json to mpd, remove base64_init=1 but keep query_string_ranges=1 at the end, so

master.mpd?query_string_ranges=1

hero!

I am still downloading, but at least the 403 error went away... omg. THANK YOU.

@plutack1
Copy link

plutack1 commented Jul 8, 2023

Just in case anyone still has a use for this, I updated the readme to be a bit more understanding and also usable for windows users while also implementing @DraZen-es code change. The fork i created works well.

@plutack1
Copy link

plutack1 commented Aug 3, 2023

seems this isnt working again. anyone figure out the new url should ve formatted?

@plutack1
Copy link

plutack1 commented Aug 3, 2023

For anyone who is still interested in downloading via this way modifying this script to your choosing will help.

@flinhong
Copy link

Easier, if you have youtube-dl installed:

1. copy the `master.json` URL

2. replace `.json?base64_init=1` with `.mpd`

3. provide it to `youtube-dl`: `youtube-dl EDITED_URL`

yt-dl will download the best quality available :)

amazing...

@Somstradamus
Copy link

Somstradamus commented Nov 7, 2023

got an issue, been downloading a bunch of video for days and then suddenly the one that was downloading ended up with this error:

F:\ffmpeg>youtube-dl.exe -o 22-10-23PERF.mp4 https://91vod-adaptive.akamaized.net/exp=1699318792~acl=%2F222d9b05-2ac9-4bf1-a98e-c821e509c8fa%2F%2A~hmac=5924a2ed3f6704c9aa9892d413bbbac8da8b7428ebafad976496229f310d7d8a/222d9b05-2ac9-4bf1-a98e-c821e509c8fa/sep/video/2ed9800f,b18fccd0,cbccf898,e88838cd,effa0196/audio/2deec4db,8c92b620,fd7a357a/master.mpd?query_string_ranges=1
[generic] master: Requesting header
WARNING: Falling back on generic information extractor.
[generic] master: Downloading webpage
[generic] master: Extracting information
[dashsegments] Total fragments: 1069
[download] Destination: 22-10-23PERF.fvideo-2ed9800f.mp4
[download] 8.9% of ~571.81MiB at 549.60KiB/s ETA 23:44 ERROR: unable to download video data: <urlopen error [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:600)>

then now when I try ANY video, even ones from the past that were successfully downloaded, I end up with this error:

F:\ffmpeg>youtube-dl.exe -o 24-10-23.mp4 https://194vod-adaptive.akamaized.net/exp=1699310038~acl=%2Fb852eef9-3848-48a9-81af-a6bb0c3bb101%2F%2A~hmac=64987b83dd191c8ee0833181540fe12c44f6937f244256cc9fe42a15c4a4ede4/b852eef9-3848-48a9-81af-a6bb0c3bb101/sep/video/4ea580af,58650cf4,9886125d,a4f6fd04,ad9e4799/audio/3de08f2b,a69e0c39,c8ff288c/master.mpd?query_string_ranges=1
[generic] Extracting URL: https://194vod-adaptive.akamaized.net/exp=1699310038~acl=%2Fb852eef9-3848-48a9-81af-a6bb0c3bb101%...uery_string_ranges=1
[generic] master: Downloading webpage
ERROR: [generic] Unable to download webpage: HTTP Error 410: Gone (caused by <HTTPError 410: Gone>); please report this issue on https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using yt-dlp -U

And yes, it is up to date:

F:\ffmpeg>youtube-dl.exe -U
Available version: stable@2023.10.13, Current version: stable@2023.10.13
yt-dlp is up to date (stable@2023.10.13)

Help please?

@Somstradamus
Copy link

got an issue, been downloading a bunch of video for days and then suddenly the one that was downloading ended up with this error:

F:\ffmpeg>youtube-dl.exe -o 22-10-23PERF.mp4 https://91vod-adaptive.akamaized.net/exp=1699318792~acl=%2F222d9b05-2ac9-4bf1-a98e-c821e509c8fa%2F%2A~hmac=5924a2ed3f6704c9aa9892d413bbbac8da8b7428ebafad976496229f310d7d8a/222d9b05-2ac9-4bf1-a98e-c821e509c8fa/sep/video/2ed9800f,b18fccd0,cbccf898,e88838cd,effa0196/audio/2deec4db,8c92b620,fd7a357a/master.mpd?query_string_ranges=1 [generic] master: Requesting header WARNING: Falling back on generic information extractor. [generic] master: Downloading webpage [generic] master: Extracting information [dashsegments] Total fragments: 1069 [download] Destination: 22-10-23PERF.fvideo-2ed9800f.mp4 [download] 8.9% of ~571.81MiB at 549.60KiB/s ETA 23:44 ERROR: unable to download video data: <urlopen error [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:600)>

then now when I try ANY video, even ones from the past that were successfully downloaded, I end up with this error:

F:\ffmpeg>youtube-dl.exe -o 24-10-23.mp4 https://194vod-adaptive.akamaized.net/exp=1699310038~acl=%2Fb852eef9-3848-48a9-81af-a6bb0c3bb101%2F%2A~hmac=64987b83dd191c8ee0833181540fe12c44f6937f244256cc9fe42a15c4a4ede4/b852eef9-3848-48a9-81af-a6bb0c3bb101/sep/video/4ea580af,58650cf4,9886125d,a4f6fd04,ad9e4799/audio/3de08f2b,a69e0c39,c8ff288c/master.mpd?query_string_ranges=1 [generic] Extracting URL: https://194vod-adaptive.akamaized.net/exp=1699310038~acl=%2Fb852eef9-3848-48a9-81af-a6bb0c3bb101%...uery_string_ranges=1 [generic] master: Downloading webpage ERROR: [generic] Unable to download webpage: HTTP Error 410: Gone (caused by <HTTPError 410: Gone>); please report this issue on https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using yt-dlp -U

And yes, it is up to date:

F:\ffmpeg>youtube-dl.exe -U Available version: stable@2023.10.13, Current version: stable@2023.10.13 yt-dlp is up to date (stable@2023.10.13)

Help please?

solved:

this command was to try to resume a failed download from yesterday (while I was sleeping), so I re typed the exact same command to resume the download except that when I went on the video to compare the source, it has changed. Typing the same command with the fresh URL worked as usual.

F:\ffmpeg>youtube-dl.exe -o 24-10-23.mp4 https://194vod-adaptive.akamaized.net/exp=1699353551~acl=%2Fb852eef9-3848-48a9-81af-a6bb0c3bb101%2F%2A~hmac=75ad5d633886e2d01ef04535372fa4342bd0aa2da02b5d160c9702ea04ebea50/b852eef9-3848-48a9-81af-a6bb0c3bb101/sep/video/4ea580af,58650cf4,9886125d,a4f6fd04,ad9e4799/audio/3de08f2b,a69e0c39,c8ff288c/master.mpd?query_string_ranges=1
[generic] Extracting URL: https://194vod-adaptive.akamaized.net/exp=1699353551~acl=%2Fb852eef9-3848-48a9-81af-a6bb0c3bb101%...uery_string_ranges=1
[generic] master: Downloading webpage
WARNING: [generic] Falling back on generic information extractor
[generic] master: Extracting information
[info] master: Downloading 1 format(s): video-9886125d+audio-3de08f2b
[dashsegments] Total fragments: 658
[download] Destination: 24-10-23.fvideo-9886125d.mp4
[download] 37.7% of ~ 458.35MiB at 434.71KiB/s ETA 09:58 (frag 248/658)

my guess is that Vimeo updates it's URL sources every x hours (these bastards)

@MihaelIsaev
Copy link

Easier, if you have youtube-dl installed:

  1. copy the master.json URL
  2. replace .json?base64_init=1 with .mpd
  3. provide it to youtube-dl: youtube-dl EDITED_URL

yt-dl will download the best quality available :)

it works like a charm!

This method sort of still works. Instead of changing all of ".json?base64_init=1" with ".mpd" Just tested and works by just replacing ".json" with ".mpd" leaving everything else intact. E.g., [URL].mpd?base64_init=1

this way works! thank you!!!

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