Skip to content

Instantly share code, notes, and snippets.

@JelmerT
Last active August 29, 2015 14:01
Show Gist options
  • Save JelmerT/b1ff2b8e4f2b8575956a to your computer and use it in GitHub Desktop.
Save JelmerT/b1ff2b8e4f2b8575956a to your computer and use it in GitHub Desktop.
var fs = require('fs'),
http = require('http'),
scraper = require('wsscraper'),
url = require('url'),
static = require('node-static');
//configuration
var amount = 4
var timeout = 60000
var detect_faces = 1
var skybio_key = -----YOUR SKYBIOMETRY KEY HERE-----
var skybio_secret = -----YOUR SKYBIOMETRY SECRET HERE-----
var index = '<meta http-equiv="refresh" content="'+timeout/1000+'" >'
if (detect_faces == 1) {var Canvas = require('canvas')}
setInterval(
function(){
index = '<meta http-equiv="refresh" content="'+timeout/1000+'" >'
var milliseconds = (new Date).getTime();
console.log(milliseconds)
scraper(
{
'uri': 'https://api-1-1.frenchgirlsapp.com/feed/recent/'+ milliseconds +'/'+ amount
, 'headers': {
'Key': 'bG9vay1hdC1teS1ob3JzZSwtbXktaG9yc2UtaXMtYW1hemluZyE=',
'Accept': 'application/json',
'Proxy-Connection': 'keep-alive',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en;q=1, nl;q=0.9, fr;q=0.8, de;q=0.7, ja;q=0.6, it;q=0.5',
'Connection': 'keep-alive',
'User-Agent': 'FrenchGirls/2.4.1 (iPhone; iOS 7.1.1; Scale/2.00)'}
}
, 'json'
, function(err, json_object, urlInfo) {
if (err) {
console.log(err)
return
}
for (var i=0; i < json_object.data.length; i++) {
for (j = 0; j < json_object.data[i].drawing_ids.length; j++) {
index = index + '<img src="'+json_object.data[i].url+'" '
index = index + 'onmouseover="this.src=\''+json_object.data[i].drawing_ids[j].url+
'\'" onmouseout="this.src=\''+json_object.data[i].url+'\'">'
}
};
if (detect_faces == 1){
makeOverlay(json_object.data)
}
}
)
if (detect_faces == 1){
for (i = 0; i < amount; i++) {
index = index + '<img style="position:absolute;left:'+ (9+(i*320)) +'px;top:9px;" src="/face'+i+'.png">'
}
}
}
,timeout);
function makeOverlay(data){
var url_list = ''
for (i = 0; i < amount; i++) {
url_list = url_list + data[i].url
if (i<amount-1){url_list = url_list + ','}
}
sky_url = 'http://api.skybiometry.com/fc/faces/detect.json?api_key='+skybio_key+'&api_secret='+skybio_secret+'&urls='+url_list
scraper(sky_url,'json',function(err, json_object, urlInfo){
if (err) {
console.log(err)
return
}
var fdata = json_object
if (fdata !==null){console.log('Calls left:', fdata.usage.remaining)}
for (i = 0; i < amount; i++) {
if((fdata !== null)&(fdata.photos[i] !== undefined)&(fdata.photos[i].tags[0]!== undefined)){
var w = fdata.photos[i].width;
var h = fdata.photos[i].height;
var faceX = w * fdata.photos[i].tags[0].center.x / 100;
var faceY = h * fdata.photos[i].tags[0].center.y / 100;
var faceAngle = fdata.photos[i].tags[0].roll * (3.14 / 180);
var faceW = w * fdata.photos[i].tags[0].width / 100;
var faceH = h * fdata.photos[i].tags[0].height / 100;
var eye_left_x = w * fdata.photos[i].tags[0].eye_left.x / 100;
var eye_left_y = h * fdata.photos[i].tags[0].eye_left.y / 100;
var eye_right_x = w * fdata.photos[i].tags[0].eye_right.x / 100;
var eye_right_y = h * fdata.photos[i].tags[0].eye_right.y / 100;
var nose_x = w * fdata.photos[i].tags[0].nose.x / 100;
var nose_y = h * fdata.photos[i].tags[0].nose.y / 100;
var mouth_x = w * fdata.photos[i].tags[0].mouth_center.x / 100;
var mouth_y = h * fdata.photos[i].tags[0].mouth_center.y / 100;
var canvas = new Canvas(w, h)
var ctx = canvas.getContext('2d')
ctx.fillStyle="#00ff00";
ctx.fillRect(eye_left_x,eye_left_y,5,5);
ctx.fillRect(eye_right_x,eye_right_y,5,5);
ctx.fillRect(nose_x,nose_y,5,5);
ctx.fillRect(mouth_x,mouth_y,5,5);
ctx.lineWidth = 3;
ctx.strokeStyle = '#00ff00';
ctx.translate(faceX, faceY);
ctx.rotate(faceAngle);
ctx.strokeRect(-faceW / 2, -faceH / 2, faceW, faceH);
var out = fs.createWriteStream(__dirname + '/public/face'+i+'.png')
var stream = canvas.createPNGStream().pipe(out);
console.log('Face detected')
}else{
var canvas = new Canvas(1, 1)
var out = fs.createWriteStream(__dirname + '/public/face'+i+'.png')
var stream = canvas.createPNGStream().pipe(out);
console.log('NO Face detected')
}
}
});
}
var file = new(static.Server)('./public', {cache: 20});
http.createServer(function(req, res) {
var request = url.parse(req.url, true);
var action = request.pathname;
if (action == '/') {
res.writeHead(200, {'Content-Type': 'text/html' });
res.write(index);
res.end();
}else{
req.addListener('end', function() {
file.serve(req, res);
}).resume();
}
}).listen(8888);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment