Created
April 21, 2012 06:49
-
-
Save tblobaum/2434906 to your computer and use it in GitHub Desktop.
a little server to get vimeo thumbnails (why dont they do this already?)
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
| process.setgid('nobody') | |
| process.setuid('nobody') | |
| require('rconsole') | |
| .set({ facility: 'local0' }) | |
| require('http') | |
| .createServer(require(__dirname + '/vimeo')) | |
| .listen(80) |
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
| global.timeout = 2500 | |
| var request = require('request') | |
| function route (req, res) { | |
| res.socket.setNoDelay() | |
| switch (true) { | |
| case /vimeo\/thumbnail\/[0-9]+\/[0-3]\.jpg/.test(req.url): | |
| var id = req.url.match(/[0-9]+/)[0] | |
| request({ | |
| timeout: global.timeout | |
| , url: 'http://vimeo.com/api/v2/video/'+id+'.json' | |
| }, function (error, response, body) { | |
| try { | |
| body = JSON.parse(body) | |
| } | |
| catch (err) { | |
| console.error(err) | |
| res.end() | |
| } | |
| // thumbnail_small | |
| // thumbnail_medium | |
| // thumbnail_large | |
| console.notice('vimeo thumbnail', req.url) | |
| request.get(body[0].thumbnail_small).pipe(res) | |
| }) | |
| break | |
| default: | |
| res.end() | |
| } | |
| } | |
| module.exports = route |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment