// 1. Open the browser developper console on the network tab | |
// 2. Start the video | |
// 3. In the dev tab, locate the load of the "master.json" file, copy its full URL | |
// 4. Run: node vimeo-downloader.js "<URL>" | |
// 5. Combine the m4v and m4a files with mkvmerge | |
const fs = require('fs'); | |
const url = require('url'); | |
const https = require('https'); | |
let masterUrl = process.argv[2]; | |
if (!masterUrl.endsWith('?base64_init=1')) { | |
masterUrl+= '?base64_init=1'; | |
} | |
getJson(masterUrl, (err, json) => { | |
if (err) { | |
throw err; | |
} | |
const videoData = json.video.pop(); | |
const audioData = json.audio.pop(); | |
const videoBaseUrl = url.resolve(url.resolve(masterUrl, json.base_url), videoData.base_url); | |
const audioBaseUrl = url.resolve(url.resolve(masterUrl, json.base_url), audioData.base_url); | |
processFile('video', videoBaseUrl, videoData.init_segment, videoData.segments, json.clip_id + '.m4v', (err) => { | |
if (err) { | |
throw err; | |
} | |
processFile('audio', audioBaseUrl, audioData.init_segment, audioData.segments, json.clip_id + '.m4a', (err) => { | |
if (err) { | |
throw err; | |
} | |
}); | |
}); | |
}); | |
function processFile(type, baseUrl, initData, segments, filename, cb) { | |
if (fs.existsSync(filename)) { | |
console.log(`${type} already exists`); | |
return cb(); | |
} | |
const segmentsUrl = segments.map((seg) => baseUrl + seg.url); | |
const initBuffer = Buffer.from(initData, 'base64'); | |
fs.writeFileSync(filename, initBuffer); | |
const output = fs.createWriteStream(filename, {flags: 'a'}); | |
combineSegments(type, 0, segmentsUrl, output, (err) => { | |
if (err) { | |
return cb(err); | |
} | |
output.end(); | |
cb(); | |
}); | |
} | |
function combineSegments(type, i, segmentsUrl, output, cb) { | |
if (i >= segmentsUrl.length) { | |
console.log(`${type} done`); | |
return cb(); | |
} | |
console.log(`Download ${type} segment ${i}`); | |
https.get(segmentsUrl[i], (res) => { | |
res.on('data', (d) => output.write(d)); | |
res.on('end', () => combineSegments(type, i+1, segmentsUrl, output, cb)); | |
}).on('error', (e) => { | |
cb(e); | |
}); | |
} | |
function getJson(url, cb) { | |
let data = ''; | |
https.get(url, (res) => { | |
res.on('data', (d) => data+= d); | |
res.on('end', () => cb(null, JSON.parse(data))); | |
}).on('error', (e) => { | |
cb(e); | |
}); | |
} |
thanks
Easier, if you have
youtube-dl
installed:
- copy the
master.json
URL- replace
.json?base64_init=1
with.mpd
- provide it to
youtube-dl
:youtube-dl EDITED_URL
yt-dl will download the best quality available :)
It's amazing! And just add ffmpeg.exe for automerge mp4 and m4a
thanks for the ffmpeg-hint
Hi folks, not a very experienced one. Where am Im supposed to input the master.json url? Also it will work just running the script in visual studio code or is it necessary to set up a project in a dedicated IDE?
Hi folks, not a very experienced one. Where am Im supposed to input the master.json url? Also it will work just running the script in visual studio code or is it necessary to set up a project in a dedicated IDE?
In the Terminal.
youtube-dl....
This works! I just need to run
ffmpeg -i video_file -i audio_file -c:v copy -c:a copy out_file.mp4
to merge the files after the download then it is a proper mp4 with audio!!
Hi guys ! How can I download this .mpd
https://manifests.v2.api.xxxxxxxxxxx.com/dash.mpd?f.audioTrack=en-US%7Cprogram&f.audioTrack=es-419%7Cprogram&f.audioTrack=pt-BR%7Cprogram&f.textTrack=en-US&f.textTrack=es-419&f.textTrack=pt-BR&r.duration=666.874512&r.host=https%3A%2F%2Fcmaf.cf.latam.xxxxxxxxxxxcdn.com&r.keymod=2&r.main=0&r.manifest=videos%2FGYMr2VAoIoVAhwgEAAAAO%2F2%2Fadb413%2F2.mpd&r.origin=cmaf
I've tried with youtube-dl but it dont worked too.