Skip to content

Instantly share code, notes, and snippets.

@tyzbit
Forked from Dirrk/plex-status.js
Last active February 9, 2016 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyzbit/3bce24834d8cf679043e to your computer and use it in GitHub Desktop.
Save tyzbit/3bce24834d8cf679043e to your computer and use it in GitHub Desktop.
Plex status.js
#!/usr/bin/node
/*
Install nodejs
create directory with this file in it and run the following commands:
npm install wreck@7.0.0 lodash@3.10.1
Setup with crontab:
* * * * * /usr/bin/node /home/dirrk/scripts/plex-info/plex-status.js >> /var/log/plex/plexstatus.log 2>/dev/null
Setup splunk to consume json with timestamp from utc on timestamp field
Example dashboard: http://imgur.com/E5jBA7S
Dashboard template: https://gist.github.com/Dirrk/2b60d50b5702f395d9b3
*/
var wreck = require('wreck'),
_ = require('lodash');
var options = {
json: true,
headers: {
Accept: 'application/json'
}
};
wreck.get('http://localhost:32400/status/sessions', options, function (err, response, payload) {
var timestamp = new Date().toISOString();
if (err || response.statusCode !== 200) {
process.exit();
}
payload._children.forEach(function (child) {
var output = {};
output.timestamp = timestamp;
output.title = child.title;
output.plexId = child.ratingKey;
output.plexType = child.type;
if (child.type === 'episode') {
output.show = child.grandparentTitle;
output.season = child.parentIndex.toString();
output.episode = child.index.toString();
}
var user = _.findWhere(child._children, { _elementType: 'User' });
if (user) {
output.user = user.title;
output.userId = user.id;
}
var player = _.findWhere(child._children, { _elementType: 'Player' });
if (player) {
output.platform = player.platform;
output.player = player.title;
output.status = player.state;
output.ipaddress = player.address;
output.device = player.device;
}
var transcode = _.findWhere(child._children, { _elementType: 'TranscodeSession' });
if (transcode) {
output.video_transcoding = transcode.videoDecision;
output.audio_transcoding = transcode.audioDecision;
output.throttled = transcode.throttled;
output.progress = Math.floor(transcode.progress);
}
var media = _.findWhere(child._children, { _elementType: 'Media' });
if (media) {
output.container = media.container;
output.resolution = media.videoResolution;
output.videoCodec = media.videoCodec;
output.audioCodec = media.audioCodec;
output.width = media.width;
output.height = media.height;
output.framerate = media.videoFrameRate;
output.bitrate = media.bitrate;
output.optimized = media.optimizedForStreaming;
media = _.first(media._children) || { file: 'unknown' };
output.file = media.file;
}
console.log(JSON.stringify(output));
});
});
@tyzbit
Copy link
Author

tyzbit commented Feb 9, 2016

@Dirrk merge this fork to get video/audio codecs for all media, along with resolution, framerate, bitrate, and an integer if the media is optimized for streaming

@Dirrk
Copy link

Dirrk commented Feb 9, 2016

make a pull request

@tyzbit
Copy link
Author

tyzbit commented Feb 9, 2016

@Dirrk can't pull a gist. also, merge from latest commit, I added more stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment