Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********************************
- Vimeo jQuery Downloader
- v1.0
- 9/5/2014
- Gets download links from
- Vimeo videos
- ********************************/
- var jq_config = {
- jquery_url: "//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js",
- info: "Vimeo jQuery Downloader v1.0",
- vimeo_codec: 'h264',
- video_types: {'hd': 'HD MP4', 'sd': 'SD MP4'},
- failed_tries: 0
- };
- // Main function
- function main(){
- if (window.location.hostname != 'vimeo.com'){
- alert("This script will only work on vimeo.com!");
- return;
- }
- // Need to get the configUrl data from the page
- // before it's removed from the DOM by Vimeo's scripts
- $.ajax({
- url: window.location.href,
- type: 'GET',
- async: true,
- error: function(data){
- modal.open("Error", "There was an error! Details printed in the browser console.");
- console.log(data);
- return;
- },
- success: function(data){
- // If there's no return data, try again (10 tries max, .4 second intervals)
- if (!data){
- jq_config.failed_tries++;
- console.log("Failed to get page. Retrying...");
- if (jq_config.failed_tries >= 10){
- modal.open("Failed to get page", "Couldn't get page info. Try again in a moment.");
- return;
- }
- setTimeout(function(){
- main();
- }, 400);
- return;
- }
- var page = $(data);
- var player = page.find('.player_container .player');
- if (!player.length){
- modal.open("Something went wrong", "Couldn't find the video player on this page. Maybe the site updated.");
- return;
- }
- // Get configUrl data
- // Use this to try to get the download urls of the video
- var config_url = player.data('configUrl');
- $.ajax({
- url: config_url,
- success: function(data){
- // When the stars are right, we should get the URL data back
- // If not, display a failure message
- if (data.message){
- modal.open("Download Not Found", "Could not retrieve download URLs.");
- } else {
- var videos = data.request.files[jq_config.vimeo_codec];
- // Compile html code
- var video_urls = "";
- $.each(videos, function(k, v){
- if (jq_config.video_types[k]){
- video_urls += "<a class='btn' target='_blank' href='"+v.url+"'><i class='fa fa-download'></i> "+jq_config.video_types[k]+"</a>";
- }
- });
- // Failsafe
- if (video_urls == ''){
- modal.open("Download Not Found", "Could not find download URLs.");
- return;
- }
- modal.open("Download Video", video_urls);
- }
- }
- });
- }
- });
- }
- // Load jQuery
- function jquery_ready(main_callback){
- if (window.jQuery){
- main_callback(window.jQuery);
- return;
- }
- // Attach jQuery to the page
- var script = document.createElement("script");
- script.src = jq_config.jquery_url;
- script.type = 'text/javascript';
- document.getElementsByTagName("head")[0].appendChild(script);
- // Wait for it to load
- var checkReady = function(check_callback){
- if (window.jQuery){
- check_callback(jQuery);
- } else {
- setTimeout(function(){checkReady(check_callback);}, 20);
- }
- };
- checkReady(function($){
- $(main_callback);
- });
- }
- // Initialize Modal code and extra stuff
- if (typeof modal === 'undefined'){
- var modal = {};
- modal.init = false;
- }
- function modal_init(){
- // Fix "more videos" links not working
- $('#clips > li > a').click(function(){
- window.location = $(this).attr('href');
- });
- modal.init = true;
- // Close modal object
- modal.close = function(){
- if (modal.object){
- modal.object.fadeOut(200, function(){
- $(this).remove();
- });
- modal.object = null;
- }
- };
- // Get Fontawesome
- $('<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">').appendTo('body');
- // Modal styling
- $("<style>#tsf{line-height: 20px;position:fixed;top:0;right:0;bottom:0;left:0;z-index:1050;display:block;background-color:rgba(0,0,0,.5)}#tsf .dialogue{background-color:#292929;color:#eee;max-width:600px;min-height:200px;margin:0 auto;font-size:14px;position:relative;box-shadow:0 2px 6px rgba(0,0,0,.7)}#tsf .muted{color:#777;font-size:13px}#tsf a{color:#aaa;display:block}#tsf a:hover{color:#ccc}#tsf .close{position:absolute;top:0;right:0;margin:6px 8px;font-size:20px;cursor:pointer;color:#aaa}#tsf .close:hover{color:#ccc}#tsf .header{border-bottom:1px solid #444;font-size:20px;padding:8px}#tsf .content{padding:8px}#tsf a.btn{background-color:#333;border:1px solid #444;border-radius:2px;padding:7px 9px;display:inline-block;margin:3px;text-decoration:none}#tsf a.btn:hover{background-color:#393939;}#tsf *{transition:color .2s,background-color .2s;} #tsf .version{position:absolute;bottom:0;right:0;text-align:right;font-size:11px;color:#777;padding:3px 5px;}</style>").appendTo('body');
- // Create modal with header text and main content
- modal.open = function(header, content){
- // Close existing modal
- modal.close();
- var modal_html = "<div id='tsf'><div class='dialogue'><div class='close'><i class='fa fa-times'></i></div><div class='header'></div><div class='content'></div><div class='version'></div></div></div>";
- // Create modal object
- modal.object = $(modal_html);
- // Click event for closing modal
- modal.object.find('.close').click(modal.close);
- // Fill in content
- modal.object.find('.header').html(header);
- modal.object.find('.content').html(content);
- modal.object.find('.version').html(jq_config.info);
- // Append modal to page
- $('body').append(modal.object);
- // Show it
- modal.object.hide();
- modal.object.fadeIn(200);
- modal.object.find('.dialogue').animate({'margin-top': '30px'}, 200);
- };
- // Clicking on backdrop closes modal
- $(document).mouseup(function(e){
- if ($(e.target).is('#tsf')) modal.close();
- });
- }
- // Run script
- jquery_ready(function(){
- if (!modal.init) modal_init();
- main();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement