Rewrote most of this class. Now we have helper functions for getting info about items in plex. Used function is inPlex where we can input a tmdb item and it append if the item exsists in plex.
This commit is contained in:
@@ -3,9 +3,11 @@ const convertPlexToSeasoned = require('src/plex/convertPlexToSeasoned');
|
|||||||
const convertPlexToStream = require('src/plex/convertPlexToStream');
|
const convertPlexToStream = require('src/plex/convertPlexToStream');
|
||||||
var rp = require('request-promise');
|
var rp = require('request-promise');
|
||||||
|
|
||||||
|
const PLEX_METHODS = ['lookup', 'playing']
|
||||||
|
|
||||||
class PlexRepository {
|
class PlexRepository {
|
||||||
|
|
||||||
searchMedia(query) {
|
search(query, callback) {
|
||||||
var options = {
|
var options = {
|
||||||
uri: 'http://10.0.0.44:32400/search?query=' + query,
|
uri: 'http://10.0.0.44:32400/search?query=' + query,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -15,18 +17,40 @@ class PlexRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return rp(options)
|
return rp(options)
|
||||||
.then((result) => {
|
.then((result) => this.mapResults(result))
|
||||||
var seasonedMediaObjects = result.MediaContainer.Metadata.reduce(function(match, media_item) {
|
.then(([mappedResults, resultCount]) => {
|
||||||
if (media_item.type === 'movie' || media_item.type === 'show') {
|
return { 'results': mappedResults, 'total_results': resultCount }
|
||||||
match.push(convertPlexToSeasoned(media_item));
|
})
|
||||||
}
|
}
|
||||||
return match;
|
|
||||||
}, []);
|
compareTmdbToPlex(tmdb, plexResult) {
|
||||||
return seasonedMediaObjects;
|
return Promise.resolve()
|
||||||
})
|
.then(() => {
|
||||||
.catch((err) => {
|
plexResult.results.map((plexItem) => {
|
||||||
throw new Error(err);
|
if (tmdb.title === plexItem.title && tmdb.year === plexItem.year)
|
||||||
})
|
tmdb.matchedInPlex = true;
|
||||||
|
})
|
||||||
|
return tmdb
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
inPlex(tmdbResult) {
|
||||||
|
return Promise.resolve()
|
||||||
|
.then(() => this.search(tmdbResult.title))
|
||||||
|
.then((plexResult) => this.compareTmdbToPlex(tmdbResult, plexResult))
|
||||||
|
}
|
||||||
|
|
||||||
|
mapResults(response) {
|
||||||
|
return Promise.resolve()
|
||||||
|
.then(() => {
|
||||||
|
if (! response.MediaContainer.hasOwnProperty('Metadata')) return [[], 0]
|
||||||
|
|
||||||
|
const mappedResults = response.MediaContainer.Metadata.filter((element) => {
|
||||||
|
return (element.type === 'movie' || element.type === 'show')
|
||||||
|
}).map((element) => convertPlexToSeasoned(element))
|
||||||
|
return [mappedResults, mappedResults.length]
|
||||||
|
})
|
||||||
|
.catch((error) => {throw new Error(error)})
|
||||||
}
|
}
|
||||||
|
|
||||||
nowPlaying() {
|
nowPlaying() {
|
||||||
@@ -51,6 +75,13 @@ class PlexRepository {
|
|||||||
throw new Error('Error handling plex playing. Error: ' + err);
|
throw new Error('Error handling plex playing. Error: ' + err);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// multipleInPlex(tmdbResults) {
|
||||||
|
// const results = tmdbResults.results.map(async (tmdb) => {
|
||||||
|
// return this.inPlex(tmdb)
|
||||||
|
// })
|
||||||
|
// return Promise.all(results)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = PlexRepository;
|
module.exports = PlexRepository;
|
||||||
|
|||||||
Reference in New Issue
Block a user