Last active
June 4, 2023 08:52
-
-
Save shanept/6dfa520d825e9a50a0f39c0573ca0881 to your computer and use it in GitHub Desktop.
Get Vimeo URLs
This file contains hidden or 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
(function(){ | |
// Quick check to make sure we are in a vimeo document | |
if (window.location.host !== 'player.vimeo.com') { | |
console.error('Not in a vimeo player document. Try again...'); | |
return; | |
} | |
if (!window.playerConfig) { | |
// Vimeo URLs are stored in a script tag after the player element in the body | |
var s = document.getElementById("player").nextElementSibling; | |
// We only want the config object, let's discard the rest | |
var o = s.innerText.indexOf('{'); | |
var t = s.innerText.substring(o).split("; if (!config.request)")[0]; | |
// Now we can parse the text and turn it into a JS object | |
var config = JSON.parse(t); | |
} else { | |
var config = window.playerConfig; | |
} | |
// Sort so that the highest resolution video is first | |
config.request.files.progressive.sort(function(x,y) { | |
if (x.width > y.width) return -1; | |
if (x.width < y.width) return +1; | |
return 0; | |
}); | |
// And open it in a new window | |
window.open(config.request.files.progressive[0].url); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment