Created
January 16, 2018 07:21
-
-
Save jamesmr89/67d07283ce5bdaf20cac249cd5d13fbc to your computer and use it in GitHub Desktop.
This file contains 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
var express = require('express') | |
, request = require('request') | |
, multer = require('multer'); | |
var app = express(); | |
var upload = multer({ dest: '/tmp/' }); | |
var auth = "Basic " + new Buffer(process.env.USERNAME + ":" + process.env.PASSWORD).toString("base64"); | |
app.post('/', upload.single('thumb'), function (req, res, next) { | |
var payload = JSON.parse(req.body.payload); | |
console.log('Got webhook for', payload.event); | |
console.log('Got webhook from ', payload.Player); | |
// Player. | |
if (payload.Player.uuid == process.env.PLAYER && payload.Metadata.type != 'track') { | |
var options = { | |
method: 'GET', | |
headers : { | |
"Authorization" : auth | |
} | |
}; | |
if (payload.event == 'media.play' || payload.event == 'media.resume') { | |
console.log('Executing resume action'); | |
options.url = process.env.RESUME_URL; | |
request(options, function(err, res, body) { | |
console.log(options); | |
console.log(body); | |
}); | |
} else if (payload.event == 'media.pause' || payload.event == 'media.stop') { | |
console.log('Executing stop action.'); | |
options.url = process.env.STOP_URL; | |
request(options, function(err, res, body) { | |
console.log(options); | |
console.log(body); | |
}); | |
} else if (payload.event == 'media.pause' || payload.event == 'media.play') { | |
console.log('Executing play action.'); | |
options.url = process.env.PLAY_URL; | |
request(options, function(err, res, body) { | |
console.log(options); | |
console.log(body); | |
}); | |
} else if (payload.event == 'media.pause' || payload.event == 'media.pause') { | |
console.log('Executing pause action'); | |
options.url = process.env.PAUSE_URL; | |
request(options, function(err, res, body) { | |
console.log(options); | |
console.log(body); | |
}); | |
} | |
} | |
res.sendStatus(200); | |
}); | |
app.listen(8000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment