Added a nowPlaying function that reads, maps to custom stream object and returns in stuborn promise way
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
const assert = require('assert');
|
||||
const convertPlexToMovie = require('src/plex/convertPlexToMovie');
|
||||
const convertPlexToStream = require('src/plex/convertPlexToStream');
|
||||
const configuration = require('src/config/configuration').getInstance();
|
||||
const TMDB = require('src/tmdb/tmdb');
|
||||
const tmdb = new TMDB(configuration.get('tmdb', 'apiKey'));
|
||||
var rp = require('request-promise');
|
||||
|
||||
class PlexRepository {
|
||||
@@ -21,6 +25,29 @@ class PlexRepository {
|
||||
throw new Error(err);
|
||||
})
|
||||
}
|
||||
|
||||
nowPlaying() {
|
||||
var options = {
|
||||
uri: 'http://10.0.0.41:32400/status/sessions',
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
json: true
|
||||
}
|
||||
|
||||
return rp(options)
|
||||
.then((result) => {
|
||||
if (result.MediaContainer.size > 0) {
|
||||
var playing = result.MediaContainer.Video.map(convertPlexToStream);
|
||||
return {'size': Object.keys(playing).length, 'video': playing };
|
||||
} else {
|
||||
return { 'size': 0, 'video': [] };
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PlexRepository;
|
||||
Reference in New Issue
Block a user