forked from plexinc/webhooks-home-automation
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
67 lines (58 loc) · 2.33 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var express = require('express')
, request = require('request')
, multer = require('multer');
var app = express();
var upload = multer({ dest: '/tmp/' });
var key = '';
app.post('/', upload.single('thumb'), function (req, res, next) {
var payload = JSON.parse(req.body.payload);
//console.log('Got webhook for', payload.event);
var options = {
method: 'PUT',
json: true,
};
//Ensure IFTTT's Maker channel is set to digest Plex.Play, Plex.Resume, .. events
//If you want to control lights in particular 'Plex Rooms' you can look into payload.Player.title to send a customer event based on the player (ensure you have a unique name for each player configured in Plex).
switch (payload.event) {
case 'media.play':
// Trigger IFTTT_Plex.Play
//console.log('IFTTT_Plex.Play');
options.url = 'https://maker.ifttt.com/trigger/Plex.Play/with/key/' + key;
//options.body = { value1: payload.Account.title, value2: payload.Metadata.title, value3: payload.Player.title };
//request(options);
break;
case 'media.resume':
// Trigger IFTTT_Plex.Resume
//console.log('IFTTT_Plex.Resume');
options.url = 'https://maker.ifttt.com/trigger/Plex.Resume/with/key/' + key;
//request(options);
break;
case 'media.pause':
// Trigger IFTTT_Plex.Pause
//console.log('IFTTT_Plex.Pause');
options.url = 'https://maker.ifttt.com/trigger/Plex.Pause/with/key/' + key;
//request(options);
break;
case 'media.stop':
// Trigger IFTTT_Plex.Stop
//console.log('IFTTT_Plex.Stop');
options.url = 'https://maker.ifttt.com/trigger/Plex.Stop/with/key/' + key;
//request(options);
break;
}
switch (payload.Metadata.librarySectionType) {
case 'show':
options.body = { value1: payload.Account.title, value2: payload.Player.title, value3: (payload.Metadata.grandparentTitle + ' - ' + payload.Metadata.title) };
break;
case 'movie':
options.body = { value1: payload.Account.title, value2: payload.Player.title, value3: payload.Metadata.title };
break;
case 'artist':
options.body = { value1: payload.Account.title, value2: payload.Player.title, value3: (payload.Metadata.grandparentTitle + ' - ' + payload.Metadata.parentTitle + ' - ' + payload.Metadata.title) };
break;
default:
}
request(options);
res.sendStatus(200);
});
app.listen(12000);