0

I was looking for a solution to write a script which warns if the embed video on the website has been deleted or removed on the video provider site such as Youtube, Vimeo.

I looked everywhere, but i cannot find any solution on this subject.

GABOCSA
  • 11
  • 1
  • 4
  • 2
    You should check the API docs for each video provider. They should have some handling code for that. – Joseph Jun 24 '14 at 14:54

1 Answers1

0

Check this out:

function isURLReal(fullyQualifiedURL) {
    var URL = encodeURIComponent(fullyQualifiedURL),
        dfd = $.Deferred(),
        checkURLPromise = $.getJSON('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22' + URL + '%22&format=json');

    checkURLPromise
            .done(function(response) {
                // results should be null if the page 404s or the domain doesn't work
                if (response.query.results) { 
                    dfd.resolve(true);
                } else {
                    dfd.reject(false);
                }
            })
            .fail(function() {
                dfd.reject('failed');
            });
    });

    return dfd.promise();
}

// usage
isURLReal('http://google.com')
        .done(function(result) {
            // yes
        })
        .fail(function(result) {
            // no, or request failed
        });

Full details here : StackOverFlowLink

Community
  • 1
  • 1
ak0053792
  • 523
  • 1
  • 5
  • 18