Moved eveything related to the api to a seperate folder seasoned_api.

This commit is contained in:
2017-08-06 16:45:02 +02:00
parent f53ab55d96
commit 47aa638fd8
44 changed files with 7 additions and 7 deletions

View File

@@ -0,0 +1,53 @@
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 {
searchMedia(query) {
var options = {
uri: 'http://10.0.0.41:32400/search?query=' + query,
headers: {
'Accept': 'application/json'
},
json: true
}
return rp(options)
.then((result) => {
return result.MediaContainer.Metadata.map(convertPlexToMovie);
})
.catch((err) => {
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;