Add gfycat support

This commit is contained in:
Les De Ridder 2016-06-14 05:38:20 +02:00
parent 047a61ea0d
commit cfe10c5532
1 changed files with 19 additions and 2 deletions

View File

@ -96,7 +96,7 @@ function getBetterUrl(url, callback) {
url = url.replace("gifv", "mp4");
}
if(isTwitterUrl(url)) {
if(isTwitterImageUrl(url)) {
if(url.indexOf(':') != url.lastIndexOf(':')) { //Match if there are occurences of ':' other than the ':' in 'https://', such as in '.jpg:large'
url = url.substr(0, url.lastIndexOf(':'));
}
@ -154,6 +154,19 @@ function getBetterUrl(url, callback) {
url = url + '/imgpsh_fullsize';
callback(url);
} else if(isGfycatUrl(url)) {
var id = url.substr(url.lastIndexOf('/') + 1);
var request = new XMLHttpRequest();
request.open('GET', 'http://gfycat.com/cajax/get/' + id, true);
request.onload = function () {
var json = JSON.parse(request.responseText);
var webmUrl = json.gfyItem.webmUrl;
callback(webmUrl);
};
request.send();
} else {
callback(url);
}
@ -194,7 +207,7 @@ function cleanExtension(url) {
return url;
}
function isTwitterUrl(url) {
function isTwitterImageUrl(url) {
return url.indexOf('pbs.twimg.com/media/') != -1;
}
@ -210,6 +223,10 @@ function isSkypeUrl(url) {
return url.indexOf('api.asm.skype.com/v1/objects/') != -1;
}
function isGfycatUrl(url) {
return url.indexOf('gfycat.com/') != -1;
}
function isCoolUrl(url, callback) {
url = url.toLowerCase();