diff options
Diffstat (limited to 'public/assets/javascripts/ui/lib/Parser.js')
| -rw-r--r-- | public/assets/javascripts/ui/lib/Parser.js | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/public/assets/javascripts/ui/lib/Parser.js b/public/assets/javascripts/ui/lib/Parser.js index 46fe09c..f39239e 100644 --- a/public/assets/javascripts/ui/lib/Parser.js +++ b/public/assets/javascripts/ui/lib/Parser.js @@ -4,7 +4,15 @@ var Parser = { regex: /\.(jpeg|jpg|gif|png|svg)(\?.*)?$/i, async: false, fetch: function(url, done) { - done("", "") + var img = new Image () + img.onload = function(){ + done("", "", img.naturalWidth, img.naturalHeight, "") + img = null + } + img.src = url + if (img.complete) { + img.onload() + } }, tag: function (media) { return '<img src="' + media.url + '" onerror="imgError(this);">'; @@ -16,7 +24,19 @@ var Parser = { fetch: function(url, done) { var id = (url.match(/v=([-_a-zA-Z0-9]{11})/i) || url.match(/youtu.be\/([-_a-zA-Z0-9]{11})/i) || url.match(/embed\/([-_a-zA-Z0-9]{11})/i))[1].split('&')[0]; var thumb = "http://i.ytimg.com/vi/" + id + "/hqdefault.jpg" - done(id, thumb); + $.ajax({ + type: 'GET', + url: 'https://www.googleapis.com/youtube/v3/videos', + data: { + id: id, + key: "AIzaSyDYPKGD0-_VRBWpUYRmX8Qg6BtWmcPU_cM", + part: "id,contentDetails,snippet,status", + }, + success: function(result){ + var res = res.items[0] + done(id, thumb, 640, 360, res.snippet.title); + } + }) }, tag: function (media) { return '<img class="video" type="youtube" vid="'+media.token+'" src="'+media.thumbnail+'"><span class="playvid">▶</span>'; @@ -31,8 +51,9 @@ var Parser = { type: 'GET', url: 'http://vimeo.com/api/v2/video/' + id + '.json', success: function(result){ - if (result.length == 0) { return done(id, "") } - done(id, result[0].thumbnail_large) + if (result.length == 0) { return done(id, "", 640, 360) } + var res = result[0] + done(id, res.thumbnail_large, res.width, res.height, res.title) } }) }, @@ -79,11 +100,14 @@ var Parser = { parse: function (url, cb) { var matched = Parser.integrations.some(function(integration){ if (integration.regex.test(url)) { - integration.fetch(url, function(token, thumbnail){ + integration.fetch(url, function(token, thumbnail, width, height, title){ cb({ token: token, thumbnail: thumbnail, type: integration.type, + title: title, + width: width, + height: height, url: url, }) }) |
