Skip to content

Instantly share code, notes, and snippets.

@tblobaum
Created April 21, 2012 06:49
Show Gist options
  • Select an option

  • Save tblobaum/2434906 to your computer and use it in GitHub Desktop.

Select an option

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?)
process.setgid('nobody')
process.setuid('nobody')
require('rconsole')
.set({ facility: 'local0' })
require('http')
.createServer(require(__dirname + '/vimeo'))
.listen(80)
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