Merge branch 'master' of github.com:kevinmidboe/seasonedShows
This commit is contained in:
@@ -1,3 +1,12 @@
|
|||||||
{
|
{
|
||||||
"extends": "airbnb-base"
|
"extends": [
|
||||||
|
"airbnb-base"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"indent": ["error", 3],
|
||||||
|
"prefer-destructuring": 0,
|
||||||
|
"camelcase": 0,
|
||||||
|
"import/no-unresolved": 0,
|
||||||
|
"import/no-extraneous-dependencies": 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
"start": "cross-env SEASONED_CONFIG=conf/development.json NODE_PATH=. node src/webserver/server.js",
|
"start": "cross-env SEASONED_CONFIG=conf/development.json NODE_PATH=. node src/webserver/server.js",
|
||||||
"test": "cross-env SEASONED_CONFIG=conf/development.json NODE_PATH=. mocha --recursive test/system",
|
"test": "cross-env SEASONED_CONFIG=conf/development.json NODE_PATH=. mocha --recursive test/system",
|
||||||
"coverage": "cross-env PLANFLIX_CONFIG=conf/test.json NODE_PATH=. istanbul cover -x script/autogenerate-documentation.js --include-all-sources --dir test/.coverage node_modules/mocha/bin/_mocha --recursive test/**/* -- --report lcovonly && cat test/.coverage/lcov.info | coveralls && rm -rf test/.coverage",
|
"coverage": "cross-env PLANFLIX_CONFIG=conf/test.json NODE_PATH=. istanbul cover -x script/autogenerate-documentation.js --include-all-sources --dir test/.coverage node_modules/mocha/bin/_mocha --recursive test/**/* -- --report lcovonly && cat test/.coverage/lcov.info | coveralls && rm -rf test/.coverage",
|
||||||
"lint": "./node_modules/.bin/eslint src/webserver/"
|
"lint": "./node_modules/.bin/eslint src/"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bcrypt-nodejs": "^0.0.3",
|
"bcrypt-nodejs": "^0.0.3",
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ class Config {
|
|||||||
throw new Error(`Filed "${section} => ${option}" does not exist.`);
|
throw new Error(`Filed "${section} => ${option}" does not exist.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const field = new Field(this.fields[section][option])
|
const field = new Field(this.fields[section][option]);
|
||||||
|
|
||||||
if (field.value === '') {
|
if (field.value === '') {
|
||||||
const envField = process.env[[section.toUpperCase(), option.toUpperCase()].join('_')]
|
const envField = process.env[[section.toUpperCase(), option.toUpperCase()].join('_')];
|
||||||
if (envField !== undefined && envField.length !== 0) { return envField }
|
if (envField !== undefined && envField.length !== 0) { return envField; }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field.value === undefined) {
|
if (field.value === undefined) {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
class EnvironmentVariables {
|
class EnvironmentVariables {
|
||||||
|
|
||||||
constructor(variables) {
|
constructor(variables) {
|
||||||
this.variables = variables || process.env;
|
this.variables = variables || process.env;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ const Filters = require('./filters.js');
|
|||||||
const EnvironmentVariables = require('./environmentVariables.js');
|
const EnvironmentVariables = require('./environmentVariables.js');
|
||||||
|
|
||||||
class Field {
|
class Field {
|
||||||
|
|
||||||
constructor(rawValue, environmentVariables) {
|
constructor(rawValue, environmentVariables) {
|
||||||
this.rawValue = rawValue;
|
this.rawValue = rawValue;
|
||||||
this.filters = new Filters(rawValue);
|
this.filters = new Filters(rawValue);
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
class Filters {
|
class Filters {
|
||||||
|
|
||||||
constructor(value) {
|
constructor(value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.delimiter = '|';
|
this.delimiter = '|';
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const configuration = require('src/config/configuration').getInstance();
|
const configuration = require('src/config/configuration').getInstance();
|
||||||
const SqliteDatabase = require('src/database/sqliteDatabase');
|
const SqliteDatabase = require('src/database/sqliteDatabase');
|
||||||
|
|
||||||
const database = new SqliteDatabase(configuration.get('database', 'host'));
|
const database = new SqliteDatabase(configuration.get('database', 'host'));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,7 +10,7 @@ const database = new SqliteDatabase(configuration.get('database', 'host'));
|
|||||||
* If the tables already exists, it simply proceeds.
|
* If the tables already exists, it simply proceeds.
|
||||||
*/
|
*/
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
.then(() => database.connect())
|
.then(() => database.connect())
|
||||||
.then(() => database.setUp());
|
.then(() => database.setUp());
|
||||||
|
|
||||||
module.exports = database;
|
module.exports = database;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ CREATE TABLE IF NOT EXISTS search_history (
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS requests(
|
CREATE TABLE IF NOT EXISTS requests(
|
||||||
id TEXT,
|
id TEXT,
|
||||||
name TEXT,
|
title TEXT,
|
||||||
year NUMBER,
|
year NUMBER,
|
||||||
poster_path TEXT DEFAULT NULL,
|
poster_path TEXT DEFAULT NULL,
|
||||||
background_path TEXT DEFAULT NULL,
|
background_path TEXT DEFAULT NULL,
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
const assert = require('assert');
|
|
||||||
|
|
||||||
class GitRepository {
|
class GitRepository {
|
||||||
|
static dumpHook(body) {
|
||||||
dumpHook(body) {
|
/* eslint-disable no-console */
|
||||||
console.log(body);
|
console.log(body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
seasoned_api/src/media_classes/media.js
Normal file
19
seasoned_api/src/media_classes/media.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
class Media {
|
||||||
|
constructor(title, year, type) {
|
||||||
|
this.title = title;
|
||||||
|
this.year = year;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
toString() {
|
||||||
|
return `N: ${this.title} | Y: ${this.year} | T: ${this.type}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
print() {
|
||||||
|
/* eslint-disable no-console */
|
||||||
|
console.log(this.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Media;
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
class Movie {
|
|
||||||
constructor(title, year, type) {
|
|
||||||
this.id = undefined;
|
|
||||||
this.title = title;
|
|
||||||
this.year = year;
|
|
||||||
this.type = type;
|
|
||||||
this.release_date = undefined;
|
|
||||||
this.summary = undefined;
|
|
||||||
this.rating = undefined;
|
|
||||||
this.poster = undefined;
|
|
||||||
this.background = undefined;
|
|
||||||
this.genre = undefined;
|
|
||||||
this.date_added = undefined;
|
|
||||||
|
|
||||||
this.mediaInfo = undefined;
|
|
||||||
|
|
||||||
this.matchedInPlex = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Movie;
|
|
||||||
@@ -6,7 +6,6 @@ class Player {
|
|||||||
this.product = undefined;
|
this.product = undefined;
|
||||||
this.title = undefined;
|
this.title = undefined;
|
||||||
this.state = undefined;
|
this.state = undefined;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
22
seasoned_api/src/media_classes/plex.js
Normal file
22
seasoned_api/src/media_classes/plex.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
const Media = require('src/media_classes/media');
|
||||||
|
|
||||||
|
class Plex extends Media {
|
||||||
|
constructor(title, year, type, summary, poster_path, background_path, added, seasons, episodes) {
|
||||||
|
super(title, year, type);
|
||||||
|
|
||||||
|
this.summary = summary;
|
||||||
|
this.poster_path = poster_path;
|
||||||
|
this.background_path = background_path;
|
||||||
|
this.added = added;
|
||||||
|
|
||||||
|
this.seasons = seasons;
|
||||||
|
this.episodes = episodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
print() {
|
||||||
|
super.print();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Plex;
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
class Movie {
|
|
||||||
constructor(title, year, type) {
|
|
||||||
this.id = undefined;
|
|
||||||
this.title = title;
|
|
||||||
this.year = year;
|
|
||||||
this.type = type;
|
|
||||||
this.release_date = undefined;
|
|
||||||
this.summary = undefined;
|
|
||||||
this.rating = undefined;
|
|
||||||
this.poster = undefined;
|
|
||||||
this.background = undefined;
|
|
||||||
this.genre = undefined;
|
|
||||||
this.added = undefined;
|
|
||||||
|
|
||||||
this.seasons = undefined;
|
|
||||||
this.episodes = undefined;
|
|
||||||
|
|
||||||
this.matchedInPlex = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Movie;
|
|
||||||
33
seasoned_api/src/media_classes/tmdb.js
Normal file
33
seasoned_api/src/media_classes/tmdb.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
const Media = require('src/media_classes/media');
|
||||||
|
|
||||||
|
class TMDB extends Media {
|
||||||
|
// constructor(...args) {
|
||||||
|
constructor(title, year, type, id, summary, poster_path, background_path, popularity, score, release_status, tagline, seasons, episodes) {
|
||||||
|
super(title, year, type);
|
||||||
|
|
||||||
|
this.id = id;
|
||||||
|
this.summary = summary;
|
||||||
|
this.poster_path = poster_path;
|
||||||
|
this.background_path = background_path;
|
||||||
|
this.popularity = popularity;
|
||||||
|
this.score = score;
|
||||||
|
|
||||||
|
this.release_status = release_status;
|
||||||
|
this.tagline = tagline;
|
||||||
|
|
||||||
|
this.seasons = seasons;
|
||||||
|
this.episodes = episodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
toString() {
|
||||||
|
return `${super.toString()} | ID: ${this.id}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
print() {
|
||||||
|
/* eslint-disable no-console */
|
||||||
|
console.log(this.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = TMDB;
|
||||||
@@ -1,54 +1,53 @@
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
var PythonShell = require('python-shell');
|
const PythonShell = require('python-shell');
|
||||||
var async = require('async');
|
|
||||||
|
|
||||||
async function find(searchterm, callback) {
|
async function find(searchterm, callback) {
|
||||||
|
const options = {
|
||||||
var options = {
|
|
||||||
pythonPath: '/usr/bin/python3',
|
pythonPath: '/usr/bin/python3',
|
||||||
// pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3',
|
// pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3',
|
||||||
args: [searchterm, '-s', 'piratebay', '--print']
|
args: [searchterm, '-s', 'piratebay', '--print'],
|
||||||
}
|
};
|
||||||
|
|
||||||
PythonShell.run('../app/torrent_search/torrentSearch/search.py', options, callback);
|
PythonShell.run('../app/torrent_search/torrentSearch/search.py', options, callback);
|
||||||
// PythonShell does not support return
|
// PythonShell does not support return
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
async function callPythonAddMagnet(magnet, callback) {
|
async function callPythonAddMagnet(magnet, callback) {
|
||||||
var options = {
|
const options = {
|
||||||
pythonPath: '/usr/bin/python',
|
pythonPath: '/usr/bin/python',
|
||||||
// pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3',
|
// pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3',
|
||||||
args: [magnet]
|
args: [magnet],
|
||||||
}
|
};
|
||||||
|
|
||||||
PythonShell.run('../app/magnet.py', options, callback);
|
PythonShell.run('../app/magnet.py', options, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function SearchPiratebay(query) {
|
async function SearchPiratebay(query) {
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => find(query, (err, results) => {
|
||||||
return find(query, function(err, results) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('THERE WAS A FUCKING ERROR!')
|
/* eslint-disable no-console */
|
||||||
reject(Error('There was a error when searching for torrents'))
|
console.log('THERE WAS A FUCKING ERROR!');
|
||||||
|
reject(Error('There was a error when searching for torrents'));
|
||||||
}
|
}
|
||||||
if (results) {
|
if (results) {
|
||||||
|
/* eslint-disable no-console */
|
||||||
console.log('result', results);
|
console.log('result', results);
|
||||||
resolve(JSON.parse(results, null, '\t'));
|
resolve(JSON.parse(results, null, '\t'));
|
||||||
}
|
}
|
||||||
})
|
}));
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function AddMagnet(magnet) {
|
async function AddMagnet(magnet) {
|
||||||
return await new Promise((resolve) => {
|
return await new Promise(resolve => callPythonAddMagnet(magnet, (err, results) => {
|
||||||
return callPythonAddMagnet(magnet, function(err, results) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err)
|
/* eslint-disable no-console */
|
||||||
|
console.log(err);
|
||||||
}
|
}
|
||||||
resolve({ success: true })
|
/* eslint-disable no-console */
|
||||||
})
|
console.log(results);
|
||||||
})
|
resolve({ success: true });
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { SearchPiratebay, AddMagnet }
|
module.exports = { SearchPiratebay, AddMagnet };
|
||||||
|
|||||||
@@ -1,39 +1,24 @@
|
|||||||
const Movie = require('src/media_classes/movie');
|
const Plex = require('src/media_classes/plex');
|
||||||
const Show = require('src/media_classes/show');
|
|
||||||
|
|
||||||
function convertPlexToSeasoned(plexObject) {
|
function translateAdded(date_string) {
|
||||||
|
return new Date(date_string * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
const mediaType = plexObject.type;
|
function convertPlexToSeasoned(plex) {
|
||||||
// There are many diff types of content, we only want to look at movies and tv shows
|
const title = plex.title;
|
||||||
if (mediaType === 'movie') {
|
const year = plex.year;
|
||||||
const movie = new Movie(plexObject.title, plexObject.year, mediaType);
|
const type = plex.type;
|
||||||
|
const summary = plex.summary;
|
||||||
|
const poster_path = plex.thumb;
|
||||||
|
const background_path = plex.art;
|
||||||
|
const added = translateAdded(plex.addedAt);
|
||||||
|
// const genre = plex.genre;
|
||||||
|
const seasons = plex.childCount;
|
||||||
|
const episodes = plex.leafCount;
|
||||||
|
|
||||||
movie.summary = plexObject.summary;
|
const seasoned = new Plex(title, year, type, summary, poster_path, background_path, added, seasons, episodes);
|
||||||
movie.rating = plexObject.rating;
|
// seasoned.print();
|
||||||
movie.poster = plexObject.thumb;
|
return seasoned;
|
||||||
movie.background = plexObject.art;
|
|
||||||
movie.genre = plexObject.genre;
|
|
||||||
movie.added = new Date(plexObject.addedAt * 1000);
|
|
||||||
|
|
||||||
movie.mediaInfo = plexObject.Media;
|
|
||||||
|
|
||||||
return movie;
|
|
||||||
}
|
|
||||||
else if (mediaType === 'show') {
|
|
||||||
const show = new Show(plexObject.title, plexObject.year, mediaType);
|
|
||||||
|
|
||||||
show.summary = plexObject.summary;
|
|
||||||
show.rating = plexObject.rating;
|
|
||||||
show.poster = plexObject.thumb;
|
|
||||||
show.background = plexObject.art;
|
|
||||||
show.genre = plexObject.genre;
|
|
||||||
show.added = new Date(plexObject.addedAt * 1000);
|
|
||||||
|
|
||||||
show.seasons = plexObject.childCount;
|
|
||||||
show.episodes = plexObject.leafCount;
|
|
||||||
|
|
||||||
return show;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = convertPlexToSeasoned;
|
module.exports = convertPlexToSeasoned;
|
||||||
@@ -5,8 +5,8 @@ const convertStreamToUser = require('src/plex/stream/convertStreamToUser');
|
|||||||
const ConvertStreamToPlayback = require('src/plex/stream/convertStreamToPlayback');
|
const ConvertStreamToPlayback = require('src/plex/stream/convertStreamToPlayback');
|
||||||
|
|
||||||
function convertPlexToStream(plexStream) {
|
function convertPlexToStream(plexStream) {
|
||||||
const stream = convertPlexToSeasoned(plexStream)
|
const stream = convertPlexToSeasoned(plexStream);
|
||||||
const plexStreamMedia = plexStream.Media[0]
|
const plexStreamMedia = plexStream.Media[0];
|
||||||
stream.mediaInfo = convertStreamToMediaInfo(plexStreamMedia);
|
stream.mediaInfo = convertStreamToMediaInfo(plexStreamMedia);
|
||||||
stream.player = convertStreamToPlayer(plexStream.Player);
|
stream.player = convertStreamToPlayer(plexStream.Player);
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
/*
|
|
||||||
* @Author: KevinMidboe
|
|
||||||
* @Date: 2017-05-03 23:26:46
|
|
||||||
* @Last Modified by: KevinMidboe
|
|
||||||
* @Last Modified time: 2017-05-03 23:27:59
|
|
||||||
*/
|
|
||||||
|
|
||||||
const configuration = require('src/config/configuration').getInstance();
|
const configuration = require('src/config/configuration').getInstance();
|
||||||
|
|
||||||
function hookDumpController(req, res) {
|
function hookDumpController(req, res) {
|
||||||
|
|||||||
@@ -1,25 +1,24 @@
|
|||||||
class mailTemplate {
|
class mailTemplate {
|
||||||
|
|
||||||
constructor(mediaItem) {
|
constructor(mediaItem) {
|
||||||
this.mediaItem = mediaItem;
|
this.mediaItem = mediaItem;
|
||||||
this.posterURL = 'https://image.tmdb.org/t/p/w600';
|
this.posterURL = 'https://image.tmdb.org/t/p/w600';
|
||||||
}
|
}
|
||||||
|
|
||||||
toText() {
|
toText() {
|
||||||
return this.mediaItem.title + ' (' + this.mediaItem.year + ')'; // plain text body
|
return `${this.mediaItem.title} (${this.mediaItem.year})`; // plain text body
|
||||||
}
|
}
|
||||||
|
|
||||||
toHTML() {
|
toHTML() {
|
||||||
const info = {
|
const info = {
|
||||||
name: this.mediaItem.title,
|
name: this.mediaItem.title,
|
||||||
year: '(' + this.mediaItem.year + ')',
|
year: `(${this.mediaItem.year})`,
|
||||||
poster: this.posterURL + this.mediaItem.poster
|
poster: this.posterURL + this.mediaItem.poster,
|
||||||
}
|
};
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<h1>${info.name} ${info.year}</h1>
|
<h1>${info.name} ${info.year}</h1>
|
||||||
<img src="${info.poster}">
|
<img src="${info.poster}">
|
||||||
`
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,56 +1,80 @@
|
|||||||
const assert = require('assert');
|
|
||||||
const convertPlexToSeasoned = require('src/plex/convertPlexToSeasoned');
|
const convertPlexToSeasoned = require('src/plex/convertPlexToSeasoned');
|
||||||
const convertPlexToStream = require('src/plex/convertPlexToStream');
|
const convertPlexToStream = require('src/plex/convertPlexToStream');
|
||||||
var rp = require('request-promise');
|
const rp = require('request-promise');
|
||||||
|
|
||||||
class PlexRepository {
|
class PlexRepository {
|
||||||
|
inPlex(tmdbResult) {
|
||||||
searchMedia(query) {
|
return Promise.resolve()
|
||||||
var options = {
|
.then(() => this.search(tmdbResult.title))
|
||||||
uri: 'http://10.0.0.42:32400/search?query=' + query,
|
.then(plexResult => this.compareTmdbToPlex(tmdbResult, plexResult));
|
||||||
headers: {
|
|
||||||
'Accept': 'application/json'
|
|
||||||
},
|
|
||||||
json: true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
search(query) {
|
||||||
|
const options = {
|
||||||
|
uri: `http://10.0.0.44:32400/search?query=${query}`,
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
},
|
||||||
|
json: true,
|
||||||
|
};
|
||||||
|
|
||||||
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]) => ({ results: mappedResults, total_results: resultCount }));
|
||||||
if (media_item.type === 'movie' || media_item.type === 'show') {
|
|
||||||
match.push(convertPlexToSeasoned(media_item));
|
|
||||||
}
|
}
|
||||||
return match;
|
|
||||||
}, []);
|
static 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;
|
||||||
|
});
|
||||||
|
return tmdb;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static 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() {
|
||||||
var options = {
|
const options = {
|
||||||
uri: 'http://10.0.0.42:32400/status/sessions',
|
uri: 'http://10.0.0.44:32400/status/sessions',
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json'
|
Accept: 'application/json',
|
||||||
},
|
},
|
||||||
json: true
|
json: true,
|
||||||
}
|
};
|
||||||
|
|
||||||
return rp(options)
|
return rp(options)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
if (result.MediaContainer.size > 0) {
|
if (result.MediaContainer.size > 0) {
|
||||||
var playing = result.MediaContainer.Video.map(convertPlexToStream);
|
const playing = result.MediaContainer.Video.map(convertPlexToStream);
|
||||||
return {'size': Object.keys(playing).length, 'video': playing };
|
return { size: Object.keys(playing).length, video: playing };
|
||||||
} else {
|
|
||||||
return { 'size': 0, 'video': [] };
|
|
||||||
}
|
}
|
||||||
|
return { size: 0, video: [] };
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
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;
|
||||||
|
|||||||
@@ -1,106 +1,55 @@
|
|||||||
const assert = require('assert');
|
|
||||||
const PlexRepository = require('src/plex/plexRepository');
|
const PlexRepository = require('src/plex/plexRepository');
|
||||||
const plexRepository = new PlexRepository();
|
|
||||||
const configuration = require('src/config/configuration').getInstance();
|
|
||||||
const Cache = require('src/tmdb/cache');
|
const Cache = require('src/tmdb/cache');
|
||||||
|
const configuration = require('src/config/configuration').getInstance();
|
||||||
const TMDB = require('src/tmdb/tmdb');
|
const TMDB = require('src/tmdb/tmdb');
|
||||||
const cache = new Cache();
|
|
||||||
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
|
|
||||||
var Promise = require('bluebird');
|
|
||||||
var rp = require('request-promise');
|
|
||||||
|
|
||||||
const establishedDatabase = require('src/database/database');
|
const establishedDatabase = require('src/database/database');
|
||||||
|
|
||||||
const MailTemplate = require('src/plex/mailTemplate')
|
const plexRepository = new PlexRepository();
|
||||||
|
const cache = new Cache();
|
||||||
|
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
|
||||||
|
|
||||||
var pythonShell = require('python-shell');
|
const MailTemplate = require('src/plex/mailTemplate');
|
||||||
const nodemailer = require('nodemailer');
|
const nodemailer = require('nodemailer');
|
||||||
|
|
||||||
|
|
||||||
class RequestRepository {
|
class RequestRepository {
|
||||||
|
|
||||||
constructor(cache, database) {
|
constructor(cache, database) {
|
||||||
this.database = database || establishedDatabase;
|
this.database = database || establishedDatabase;
|
||||||
this.queries = {
|
this.queries = {
|
||||||
'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?, ?)",
|
insertRequest: "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?, ?)",
|
||||||
'fetchRequstedItems': "SELECT * FROM requests",
|
fetchRequstedItems: 'SELECT * FROM requests',
|
||||||
'updateRequestedById': "UPDATE requests SET status = ? WHERE id is ? AND type is ?",
|
updateRequestedById: 'UPDATE requests SET status = ? WHERE id is ? AND type is ?',
|
||||||
}
|
checkIfIdRequested: 'SELECT * FROM requests WHERE id IS ? AND type IS ?',
|
||||||
}
|
};
|
||||||
|
|
||||||
searchRequest(text, page, type) {
|
|
||||||
// STRIP METADATA THAT IS NOT ALLOWED
|
|
||||||
|
|
||||||
// Do a search in the tmdb api and return the results of the object
|
|
||||||
let getTmdbResults = function() {
|
|
||||||
return tmdb.search(text, page, type)
|
|
||||||
.then((tmdbSearch) => {
|
|
||||||
return tmdbSearch.results;
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Take inputs and verify them with a list. Now we are for every item in tmdb result
|
|
||||||
// runnning through the entire plex loop. Many loops, but safe.
|
|
||||||
let checkIfMatchesPlexObjects = function(title, year, plexarray) {
|
|
||||||
// Iterate all elements in plexarray
|
|
||||||
for (let plexItem of plexarray) {
|
|
||||||
// If matches with our title and year return true
|
|
||||||
if (plexItem.title === title && plexItem.year === year)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// If no matches were found, return false
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
search(query, type, page) {
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => plexRepository.searchMedia(text))
|
.then(() => tmdb.search(query, type, page))
|
||||||
// Get the list of plexItems matching the query passed.
|
// .then((tmdbResult) => plexRepository.multipleInPlex(tmdbResult))
|
||||||
.then((plexItem) => {
|
.then(result => result)
|
||||||
let tmdbSearchResult = getTmdbResults();
|
.catch(error => `error in the house${error}`);
|
||||||
|
|
||||||
// When we get the result from tmdbSearchResult we pass it along and iterate over each
|
|
||||||
// element, and updates the matchedInPlex status of a item.
|
|
||||||
return tmdbSearchResult.then((tmdbResult) => {
|
|
||||||
for (var i = 0; i < tmdbResult.length; i++) {
|
|
||||||
let foundMatchInPlex = checkIfMatchesPlexObjects(tmdbResult[i].title, tmdbResult[i].year, plexItem);
|
|
||||||
tmdbResult[i].matchedInPlex = foundMatchInPlex;
|
|
||||||
}
|
|
||||||
return { 'results': tmdbResult, 'page': 1 };
|
|
||||||
})
|
|
||||||
// TODO log error
|
|
||||||
.catch((error) => {
|
|
||||||
console.log(error);
|
|
||||||
throw new Error('Search query did not give any results.');
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
let tmdbSearchResult = getTmdbResults();
|
|
||||||
|
|
||||||
// Catch if empty, then 404
|
|
||||||
return tmdbSearchResult.then((tmdbResult) => {
|
|
||||||
return {'results': tmdbResult, 'page': 1 };
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lookup(identifier, type = 'movie') {
|
lookup(identifier, type = 'movie') {
|
||||||
if (type === 'movie') { type = 'movieInfo'}
|
|
||||||
else if (type === 'tv') { type = 'tvInfo'}
|
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => tmdb.lookup(identifier, type))
|
.then(() => tmdb.lookup(identifier, type))
|
||||||
.then((tmdbMovie) => {
|
.then(tmdbMovie => this.checkID(tmdbMovie))
|
||||||
return Promise.resolve(plexRepository.searchMedia(tmdbMovie.title))
|
.then(tmdbMovie => plexRepository.inPlex(tmdbMovie))
|
||||||
.then((plexMovies) => {
|
|
||||||
for (var i = 0; i < plexMovies.length; i++) {
|
|
||||||
if (tmdbMovie.title === plexMovies[i].title && tmdbMovie.year === plexMovies[i].year) {
|
|
||||||
tmdbMovie.matchedInPlex = true;
|
|
||||||
return tmdbMovie;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
return error;
|
throw new Error(error);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
checkID(tmdbMovie) {
|
||||||
|
return Promise.resolve()
|
||||||
|
.then(() => this.database.get(this.queries.checkIfIdRequested, [tmdbMovie.id, tmdbMovie.type]))
|
||||||
|
.then((result, error) => {
|
||||||
|
if (error) { throw new Error(error); }
|
||||||
|
let already_requested = false;
|
||||||
|
if (result) { already_requested = true; }
|
||||||
|
|
||||||
|
tmdbMovie.requested = already_requested;
|
||||||
return tmdbMovie;
|
return tmdbMovie;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -111,22 +60,19 @@ class RequestRepository {
|
|||||||
* @returns {Promise} If nothing has gone wrong.
|
* @returns {Promise} If nothing has gone wrong.
|
||||||
*/
|
*/
|
||||||
sendRequest(identifier, type, ip, user_agent, user) {
|
sendRequest(identifier, type, ip, user_agent, user) {
|
||||||
tmdb.lookup(identifier, type).then(movie => {
|
tmdb.lookup(identifier, type).then((movie) => {
|
||||||
|
if (user === 'false') { user = 'NULL'; }
|
||||||
if (user === 'false')
|
|
||||||
user = 'NULL';
|
|
||||||
console.log(user)
|
|
||||||
// Add request to database
|
// Add request to database
|
||||||
this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster, movie.background, user, ip, user_agent, movie.type])
|
this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster_path, movie.background_path, user, ip, user_agent, movie.type]);
|
||||||
|
|
||||||
|
|
||||||
// create reusable transporter object using the default SMTP transport
|
// create reusable transporter object using the default SMTP transport
|
||||||
let transporter = nodemailer.createTransport({
|
const transporter = nodemailer.createTransport({
|
||||||
service: 'gmail',
|
service: 'gmail',
|
||||||
auth: {
|
auth: {
|
||||||
user: configuration.get('mail', 'user_pi'),
|
user: configuration.get('mail', 'user_pi'),
|
||||||
pass: configuration.get('mail', 'password_pi')
|
pass: configuration.get('mail', 'password_pi'),
|
||||||
}
|
},
|
||||||
// host: configuration.get('mail', 'host'),
|
// host: configuration.get('mail', 'host'),
|
||||||
// port: 26,
|
// port: 26,
|
||||||
// ignoreTLS: true,
|
// ignoreTLS: true,
|
||||||
@@ -134,16 +80,16 @@ class RequestRepository {
|
|||||||
// secure: false, // secure:true for port 465, secure:false for port 587
|
// secure: false, // secure:true for port 465, secure:false for port 587
|
||||||
});
|
});
|
||||||
|
|
||||||
const mailTemplate = new MailTemplate(movie)
|
const mailTemplate = new MailTemplate(movie);
|
||||||
|
|
||||||
// setup email data with unicode symbols
|
// setup email data with unicode symbols
|
||||||
let mailOptions = {
|
const mailOptions = {
|
||||||
// TODO get the mail adr from global location (easy to add)
|
// TODO get the mail adr from global location (easy to add)
|
||||||
from: 'MovieRequester <pi.midboe@gmail.com>', // sender address
|
from: 'MovieRequester <pi.midboe@gmail.com>', // sender address
|
||||||
to: 'kevin.midboe@gmail.com', // list of receivers
|
to: 'kevin.midboe@gmail.com', // list of receivers
|
||||||
subject: 'Download request', // Subject line
|
subject: 'Download request', // Subject line
|
||||||
text: mailTemplate.toText(),
|
text: mailTemplate.toText(),
|
||||||
html: mailTemplate.toHTML()
|
html: mailTemplate.toHTML(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// send mail with defined transport object
|
// send mail with defined transport object
|
||||||
@@ -153,12 +99,10 @@ class RequestRepository {
|
|||||||
}
|
}
|
||||||
console.log('Message %s sent: %s', info.messageId, info.response);
|
console.log('Message %s sent: %s', info.messageId, info.response);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
})
|
|
||||||
|
|
||||||
// TODO add better response when done.
|
// TODO add better response when done.
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchRequested() {
|
fetchRequested() {
|
||||||
@@ -168,7 +112,6 @@ class RequestRepository {
|
|||||||
updateRequestedById(id, type, status) {
|
updateRequestedById(id, type, status) {
|
||||||
return this.database.run(this.queries.updateRequestedById, [status, id, type]);
|
return this.database.run(this.queries.updateRequestedById, [status, id, type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = RequestRepository;
|
module.exports = RequestRepository;
|
||||||
@@ -8,7 +8,6 @@ class convertStreamToPlayback {
|
|||||||
this.videoProfile = plexStream.videoProfile;
|
this.videoProfile = plexStream.videoProfile;
|
||||||
this.duration = plexStream.duration;
|
this.duration = plexStream.duration;
|
||||||
this.container = plexStream.container;
|
this.container = plexStream.container;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
const establishedDatabase = require('src/database/database');
|
const establishedDatabase = require('src/database/database');
|
||||||
|
|
||||||
class SearchHistory {
|
class SearchHistory {
|
||||||
|
|
||||||
constructor(database) {
|
constructor(database) {
|
||||||
this.database = database || establishedDatabase;
|
this.database = database || establishedDatabase;
|
||||||
this.queries = {
|
this.queries = {
|
||||||
@@ -27,13 +26,13 @@ class SearchHistory {
|
|||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
create(user, searchQuery) {
|
create(user, searchQuery) {
|
||||||
return this.database.run(this.queries.create, [searchQuery, user]).catch((error) => {
|
return this.database.run(this.queries.create, [searchQuery, user])
|
||||||
|
.catch((error) => {
|
||||||
if (error.message.includes('FOREIGN')) {
|
if (error.message.includes('FOREIGN')) {
|
||||||
throw new Error('Could not create search history.');
|
throw new Error('Could not create search history.');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = SearchHistory;
|
module.exports = SearchHistory;
|
||||||
|
|||||||
@@ -1,22 +1,17 @@
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const Stray = require('src/seasoned/stray');
|
const Stray = require('src/seasoned/stray');
|
||||||
const establishedDatabase = require('src/database/database');
|
const establishedDatabase = require('src/database/database');
|
||||||
var pythonShell = require('python-shell');
|
const pythonShell = require('python-shell');
|
||||||
|
|
||||||
function foo(e) {
|
|
||||||
throw('Foooo');
|
|
||||||
}
|
|
||||||
|
|
||||||
class StrayRepository {
|
class StrayRepository {
|
||||||
|
|
||||||
constructor(database) {
|
constructor(database) {
|
||||||
this.database = database || establishedDatabase;
|
this.database = database || establishedDatabase;
|
||||||
this.queries = {
|
this.queries = {
|
||||||
'read': 'SELECT * FROM stray_eps WHERE id = ?',
|
read: 'SELECT * FROM stray_eps WHERE id = ?',
|
||||||
'readAll': 'SELECT id, name, season, episode, verified FROM stray_eps',
|
readAll: 'SELECT id, name, season, episode, verified FROM stray_eps',
|
||||||
'readAllFiltered': 'SELECT id, name, season, episode, verified FROM stray_eps WHERE verified = ',
|
readAllFiltered: 'SELECT id, name, season, episode, verified FROM stray_eps WHERE verified = ',
|
||||||
'checkVerified': 'SELECT id FROM stray_eps WHERE verified = 0 AND id = ?',
|
checkVerified: 'SELECT id FROM stray_eps WHERE verified = 0 AND id = ?',
|
||||||
'verify': 'UPDATE stray_eps SET verified = 1 WHERE id = ?',
|
verify: 'UPDATE stray_eps SET verified = 1 WHERE id = ?',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,11 +19,11 @@ class StrayRepository {
|
|||||||
return this.database.get(this.queries.read, strayId).then((row) => {
|
return this.database.get(this.queries.read, strayId).then((row) => {
|
||||||
assert.notEqual(row, undefined, `Could not find list with id ${strayId}.`);
|
assert.notEqual(row, undefined, `Could not find list with id ${strayId}.`);
|
||||||
return row;
|
return row;
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
readAll(verified = null, page = 1) {
|
readAll(verified = null) {
|
||||||
var dbSearchQuery = this.queries.readAll;
|
let dbSearchQuery = this.queries.readAll;
|
||||||
if (verified != null) {
|
if (verified != null) {
|
||||||
dbSearchQuery = this.queries.readAllFiltered + verified.toString();
|
dbSearchQuery = this.queries.readAllFiltered + verified.toString();
|
||||||
}
|
}
|
||||||
@@ -40,19 +35,19 @@ class StrayRepository {
|
|||||||
stray.episode = row.episode;
|
stray.episode = row.episode;
|
||||||
stray.verified = row.verified;
|
stray.verified = row.verified;
|
||||||
return stray;
|
return stray;
|
||||||
}))
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
verifyStray(strayId) {
|
verifyStray(strayId) {
|
||||||
return this.database.get(this.queries.checkVerified, strayId).then((row) => {
|
return this.database.get(this.queries.checkVerified, strayId).then((row) => {
|
||||||
assert.notEqual(row, undefined, `Stray '${strayId}' already verified.`);
|
assert.notEqual(row, undefined, `Stray '${strayId}' already verified.`);
|
||||||
|
|
||||||
var options = {
|
const options = {
|
||||||
pythonPath: '/usr/bin/python3',
|
pythonPath: '/usr/bin/python3',
|
||||||
args: [strayId]
|
args: [strayId],
|
||||||
}
|
};
|
||||||
|
|
||||||
pythonShell.run('../app/moveSeasoned.py', options, function (err, results) {
|
pythonShell.run('../app/moveSeasoned.py', options, (err, results) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
// TODO Add error handling!! StrayRepository.ERROR
|
// TODO Add error handling!! StrayRepository.ERROR
|
||||||
// results is an array consisting of messages collected during execution
|
// results is an array consisting of messages collected during execution
|
||||||
@@ -60,7 +55,7 @@ class StrayRepository {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return this.database.run(this.queries.verify, strayId);
|
return this.database.run(this.queries.verify, strayId);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ const establishedDatabase = require('src/database/database');
|
|||||||
|
|
||||||
class Cache {
|
class Cache {
|
||||||
constructor(database) {
|
constructor(database) {
|
||||||
this.database = database || establishedDatabase
|
this.database = database || establishedDatabase;
|
||||||
this.queries = {
|
this.queries = {
|
||||||
'read': 'SELECT value, time_to_live, created_at, DATETIME("now", "localtime") as now, ' +
|
read: 'SELECT value, time_to_live, created_at, DATETIME("now", "localtime") as now, ' +
|
||||||
'DATETIME(created_at, "+" || time_to_live || " seconds") as expires ' +
|
'DATETIME(created_at, "+" || time_to_live || " seconds") as expires ' +
|
||||||
'FROM cache WHERE key = ? AND now < expires',
|
'FROM cache WHERE key = ? AND now < expires',
|
||||||
'create': 'INSERT OR REPLACE INTO cache (key, value, time_to_live) VALUES (?, ?, ?)',
|
create: 'INSERT OR REPLACE INTO cache (key, value, time_to_live) VALUES (?, ?, ?)',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ class Cache {
|
|||||||
.then((row) => {
|
.then((row) => {
|
||||||
assert(row, 'Could not find cache enrty with that key.');
|
assert(row, 'Could not find cache enrty with that key.');
|
||||||
return JSON.parse(row.value);
|
return JSON.parse(row.value);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,7 +31,7 @@ class Cache {
|
|||||||
* @param {String} key of the cache entry
|
* @param {String} key of the cache entry
|
||||||
* @param {String} value of the cache entry
|
* @param {String} value of the cache entry
|
||||||
* @param {Number} timeToLive the number of seconds before entry expires
|
* @param {Number} timeToLive the number of seconds before entry expires
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
set(key, value, timeToLive = 172800) {
|
set(key, value, timeToLive = 172800) {
|
||||||
const json = JSON.stringify(value);
|
const json = JSON.stringify(value);
|
||||||
|
|||||||
@@ -1,57 +1,39 @@
|
|||||||
const Movie = require('src/media_classes/movie');
|
|
||||||
const Show = require('src/media_classes/show');
|
|
||||||
|
|
||||||
function convertTmdbToSeasoned(tmdbObject, strictType=undefined) {
|
const TMDB = require('src/media_classes/tmdb');
|
||||||
// TODO create a default fallback class to set the when falls to else as both are undefined
|
|
||||||
if (tmdbObject.media_type !== undefined)
|
|
||||||
var mediaType = tmdbObject.media_type;
|
|
||||||
else if (strictType !== undefined)
|
|
||||||
var mediaType = strictType;
|
|
||||||
else
|
|
||||||
var mediaType = 'movie';
|
|
||||||
|
|
||||||
// There are many diff types of content, we only want to look at movies and tv shows
|
function translateYear(tmdbReleaseDate) {
|
||||||
if (mediaType === 'movie') {
|
return new Date(tmdbReleaseDate).getFullYear();
|
||||||
const year = new Date(tmdbObject.release_date).getFullYear();
|
}
|
||||||
|
|
||||||
if (tmdbObject.title !== undefined) {
|
function translateGenre(tmdbGenres) {
|
||||||
var title = tmdbObject.title;
|
return tmdbGenres.map(genre => genre.name);
|
||||||
} else if (tmdbObject.name !== undefined) {
|
}
|
||||||
var title = tmdbObject.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
const movie = new Movie(title, year, mediaType);
|
function convertTmdbToSeasoned(tmdb, manualType = undefined) {
|
||||||
|
const title = tmdb.title || tmdb.name;
|
||||||
|
const year = translateYear(tmdb.release_date || tmdb.first_air_date);
|
||||||
|
const type = tmdb.media_type || manualType;
|
||||||
|
|
||||||
movie.id = tmdbObject.id;
|
const id = tmdb.id;
|
||||||
movie.summary = tmdbObject.overview;
|
const summary = tmdb.overview;
|
||||||
movie.rating = tmdbObject.vote_average;
|
const poster_path = tmdb.poster_path;
|
||||||
movie.poster = tmdbObject.poster_path;
|
const background_path = tmdb.backdrop_path;
|
||||||
movie.background = tmdbObject.backdrop_path;
|
const popularity = tmdb.popularity;
|
||||||
movie.genre = tmdbObject.genre_ids;
|
const score = tmdb.vote_average;
|
||||||
|
// const genres = translateGenre(tmdb.genres);
|
||||||
|
const release_status = tmdb.status;
|
||||||
|
const tagline = tmdb.tagline;
|
||||||
|
|
||||||
movie.popularity = tmdbObject.popularity;
|
const seasons = tmdb.number_of_seasons;
|
||||||
movie.vote_count = tmdbObject.vote_count;
|
const episodes = tmdb.episodes;
|
||||||
|
|
||||||
return movie;
|
const seasoned = new TMDB(
|
||||||
}
|
title, year, type, id, summary, poster_path, background_path,
|
||||||
else if (mediaType === 'tv' || mediaType === 'show') {
|
popularity, score, release_status, tagline, seasons, episodes,
|
||||||
const year = new Date(tmdbObject.first_air_date).getFullYear();
|
);
|
||||||
|
|
||||||
const show = new Show(tmdbObject.name, year, 'show');
|
// seasoned.print()
|
||||||
|
return seasoned;
|
||||||
show.id = tmdbObject.id;
|
|
||||||
show.summary = tmdbObject.overview;
|
|
||||||
show.rating = tmdbObject.vote_average;
|
|
||||||
show.poster = tmdbObject.poster_path;
|
|
||||||
show.background = tmdbObject.backdrop_path;
|
|
||||||
show.genre = tmdbObject.genre_ids;
|
|
||||||
|
|
||||||
show.popularity = tmdbObject.popularity;
|
|
||||||
show.vote_count = tmdbObject.vote_count;
|
|
||||||
|
|
||||||
return show;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = convertTmdbToSeasoned;
|
module.exports = convertTmdbToSeasoned;
|
||||||
|
|
||||||
|
|||||||
@@ -1,33 +1,53 @@
|
|||||||
const moviedb = require('moviedb');
|
const moviedb = require('moviedb');
|
||||||
const convertTmdbToSeasoned = require('src/tmdb/convertTmdbToSeasoned');
|
const convertTmdbToSeasoned = require('src/tmdb/convertTmdbToSeasoned');
|
||||||
var methodTypes = { 'movie': 'searchMovie', 'show': 'searchTv', 'multi': 'searchMulti', 'movieInfo': 'movieInfo',
|
|
||||||
'tvInfo': 'tvInfo', 'upcomingMovies': 'miscUpcomingMovies', 'discoverMovie': 'discoverMovie',
|
|
||||||
'discoverShow': 'discoverTv', 'popularMovies': 'miscPopularMovies', 'popularShows': 'miscPopularTvs',
|
|
||||||
'nowPlayingMovies': 'miscNowPlayingMovies', 'nowAiringShows': 'tvOnTheAir', 'movieSimilar': 'movieSimilar',
|
|
||||||
'showSimilar': 'tvSimilar' };
|
|
||||||
|
|
||||||
|
const TMDB_METHODS = {
|
||||||
const TYPE_LIST = ['upcoming', 'discover', 'popular', 'nowplaying', 'similar']
|
upcoming: { movie: 'miscUpcomingMovies' },
|
||||||
const TMDB_TYPE_LIST = {
|
discover: { movie: 'discoverMovie', show: 'discoverTv' },
|
||||||
'upcomingmovie': 'miscUpcomingMovies', 'discovermovie': 'discoverMovie',
|
popular: { movie: 'miscPopularMovies', show: 'miscPopularTvs' },
|
||||||
'discovershow': 'discoverTv', 'popularmovie': 'miscPopularMovies',
|
nowplaying: { movie: 'miscNowPlayingMovies', show: 'tvOnTheAir' },
|
||||||
'popularshow': 'miscPopularTvs', 'nowplayingmovie': 'miscNowPlayingMovies',
|
similar: { movie: 'movieSimilar', show: 'tvSimilar' },
|
||||||
'nowplayingshow': 'tvOnTheAir', 'similarmovie': 'movieSimilar', 'similarshow': 'tvSimilar',
|
search: { movie: 'searchMovie', show: 'searchTv', multi: 'searchMulti' },
|
||||||
|
info: { movie: 'movieInfo', show: 'tvInfo' },
|
||||||
};
|
};
|
||||||
|
|
||||||
class TMDB {
|
class TMDB {
|
||||||
|
|
||||||
constructor(cache, apiKey, tmdbLibrary) {
|
constructor(cache, apiKey, tmdbLibrary) {
|
||||||
this.cache = cache
|
this.cache = cache;
|
||||||
this.tmdbLibrary = tmdbLibrary || moviedb(apiKey);
|
this.tmdbLibrary = tmdbLibrary || moviedb(apiKey);
|
||||||
this.cacheTags = {
|
this.cacheTags = {
|
||||||
'search': 'se',
|
search: 'se',
|
||||||
'info': 'i',
|
info: 'i',
|
||||||
'upcoming': 'u',
|
upcoming: 'u',
|
||||||
'discover': 'd',
|
discover: 'd',
|
||||||
'popular': 'p',
|
popular: 'p',
|
||||||
'nowplaying': 'n',
|
nowplaying: 'n',
|
||||||
'similar': 'si',
|
similar: 'si',
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a specific movie by id from TMDB.
|
||||||
|
* @param {Number} identifier of the movie you want to retrieve
|
||||||
|
* @returns {Promise} succeeds if movie was found
|
||||||
|
*/
|
||||||
|
lookup(identifier, type = 'movie') {
|
||||||
|
const query = { id: identifier };
|
||||||
|
const cacheKey = `${this.cacheTags.info}:${type}:${identifier}`;
|
||||||
|
return Promise.resolve()
|
||||||
|
.then(() => this.cache.get(cacheKey))
|
||||||
|
.catch(() => this.tmdb(this.tmdbMethod('info', type), query))
|
||||||
|
.catch(() => { throw new Error('Could not find a movie with that id.'); })
|
||||||
|
.then(response => this.cache.set(cacheKey, response))
|
||||||
|
.then((response) => {
|
||||||
|
try {
|
||||||
|
return convertTmdbToSeasoned(response, type);
|
||||||
|
} catch (parseError) {
|
||||||
|
console.error(parseError);
|
||||||
|
throw new Error('Could not parse movie.');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,98 +56,46 @@ class TMDB {
|
|||||||
* @returns {Promise} dict with query results, current page and total_pages
|
* @returns {Promise} dict with query results, current page and total_pages
|
||||||
*/
|
*/
|
||||||
search(text, page = 1, type = 'multi') {
|
search(text, page = 1, type = 'multi') {
|
||||||
const query = { 'query': text, 'page': page };
|
const query = { query: text, page };
|
||||||
const cacheKey = `${this.cacheTags.search}:${page}:${type}:${text}`;
|
const cacheKey = `${this.cacheTags.search}:${page}:${type}:${text}`;
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => this.cache.get(cacheKey))
|
.then(() => this.cache.get(cacheKey))
|
||||||
.catch(() => this.tmdb(methodTypes[type], query))
|
.catch(() => this.tmdb(this.tmdbMethod('search', type), query))
|
||||||
.catch(() => { throw new Error('Could not search for movies/shows at tmdb.'); })
|
.catch(() => { throw new Error('Could not search for movies/shows at tmdb.'); })
|
||||||
.then((response) => this.cache.set(cacheKey, response))
|
.then(response => this.cache.set(cacheKey, response))
|
||||||
.then((response) => {
|
.then(response => this.mapResults(response, type))
|
||||||
try {
|
.catch((error) => { throw new Error(error); })
|
||||||
let filteredTmdbItems = response.results.filter(function(tmdbResultItem) {
|
.then(([mappedResults, pagenumber, totalpages, total_results]) => ({
|
||||||
return ((tmdbResultItem.vote_count >= 10 || tmdbResultItem.popularity > 2) && (tmdbResultItem.release_date !== undefined || tmdbResultItem.first_air_date !== undefined))
|
results: mappedResults, page: pagenumber, total_results, total_pages: totalpages,
|
||||||
})
|
}));
|
||||||
|
|
||||||
let seasonedItems = filteredTmdbItems.map((tmdbItem) => {
|
|
||||||
if (type === 'movie')
|
|
||||||
return convertTmdbToSeasoned(tmdbItem, 'movie');
|
|
||||||
else if (type === 'show')
|
|
||||||
return convertTmdbToSeasoned(tmdbItem, 'show');
|
|
||||||
else
|
|
||||||
return convertTmdbToSeasoned(tmdbItem);
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO add page number if results are larger than 20
|
|
||||||
return { 'results': seasonedItems, 'number_of_items_on_page': seasonedItems.length,
|
|
||||||
'page': 1, 'total_pages': 1 };
|
|
||||||
|
|
||||||
} catch (parseError) {
|
|
||||||
throw new Error('Could not parse result.');
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a specific movie by id from TMDB.
|
* Fetches a given list from tmdb.
|
||||||
* @param {Number} identifier of the movie you want to retrieve
|
* @param {listName} List we want to fetch.
|
||||||
* @returns {Promise} succeeds if movie was found
|
* @param {type} The to specify in the request for discover (default 'movie').
|
||||||
|
* @param {id} When finding similar a id can be added to query
|
||||||
|
* @param {page} Page number we want to fetch.
|
||||||
|
* @returns {Promise} dict with query results, current page and total_pages
|
||||||
*/
|
*/
|
||||||
lookup(identifier, queryType = 'movie') {
|
listSearch(listName, type = 'movie', id, page = '1') {
|
||||||
var type;
|
const params = { id, page };
|
||||||
if (queryType === 'movie') { type = 'movieInfo'}
|
const cacheKey = `${this.cacheTags[listName]}:${type}:${id}:${page}`;
|
||||||
else if (queryType === 'show') { type = 'tvInfo'}
|
|
||||||
else {
|
|
||||||
return Promise.resolve()
|
|
||||||
.then(() => {
|
|
||||||
throw new Error('Invalid type declaration.')
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const query = { id: identifier };
|
|
||||||
const cacheKey = `${this.cacheTags.lookup}:${type}:${identifier}`;
|
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => this.cache.get(cacheKey))
|
.then(() => this.cache.get(cacheKey))
|
||||||
.catch(() => this.tmdb(type, query))
|
.catch(() => this.tmdb(this.tmdbMethod(listName, type), params))
|
||||||
.catch(() => { throw new Error('Could not find a movie with that id.'); })
|
.then(response => this.cache.set(cacheKey, response))
|
||||||
.then((response) => this.cache.set(cacheKey, response))
|
.then(response => this.mapResults(response, type))
|
||||||
.then((response) => {
|
.catch((error) => { throw new Error(error); })
|
||||||
try {
|
.then(([mappedResults, pagenumber, totalpages, total_results]) => ({
|
||||||
var car = convertTmdbToSeasoned(response, queryType);
|
results: mappedResults, page: pagenumber, total_pages: totalpages, total_results,
|
||||||
console.log(car);
|
}));
|
||||||
return car;
|
|
||||||
} catch (parseError) {
|
|
||||||
throw new Error('Could not parse movie.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
tmdbMethod(apiMethod, type) {
|
||||||
* Verifies that a list_name corresponds to a tmdb list and calls the tmdb
|
const method = TMDB_METHODS[apiMethod][type];
|
||||||
* api with list name and paramters.
|
if (method !== undefined) return method;
|
||||||
* @param {list_name} The name of a list we want to search for.
|
throw new Error('Could not find tmdb api method.');
|
||||||
* @param {media_type} The type declared in listSearch.
|
|
||||||
* @param {params} Params is page and id given as parameters in listSearch.
|
|
||||||
* @returns {Promise} dict with raw tmdb results.
|
|
||||||
*/
|
|
||||||
searchTmdbList(list_name, media_type, params) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
if (TYPE_LIST.includes(list_name) && ['movie', 'show'].includes(media_type)) {
|
|
||||||
const searchQuery = list_name.toLowerCase() + media_type.toLowerCase();
|
|
||||||
const tmdbList = TMDB_TYPE_LIST[searchQuery]
|
|
||||||
|
|
||||||
return Promise.resolve()
|
|
||||||
.then(() => this.tmdb(tmdbList, params))
|
|
||||||
.then((response) => {
|
|
||||||
resolve(response)
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
return reject('Error while fetching from tmdb list.')
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return reject('Did not find tmdb list matching query.')
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -139,37 +107,10 @@ class TMDB {
|
|||||||
mapResults(response, type) {
|
mapResults(response, type) {
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const mappedResults = response.results.map((result) => {
|
const mappedResults = response.results.map(result => convertTmdbToSeasoned(result, type));
|
||||||
return convertTmdbToSeasoned(result, type)
|
return [mappedResults, response.page, response.total_pages, response.total_results];
|
||||||
})
|
|
||||||
|
|
||||||
return [mappedResults, response.page, response.total_pages]
|
|
||||||
})
|
|
||||||
.catch((error) => { throw new Error(error)})
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches a given list from tmdb.
|
|
||||||
* @param {list_name} List we want to fetch.
|
|
||||||
* @param {media_type} The to specify in the request for discover (default 'movie').
|
|
||||||
* @param {id} When finding similar a id can be added to query
|
|
||||||
* @param {page} Page number we want to fetch.
|
|
||||||
* @returns {Promise} dict with query results, current page and total_pages
|
|
||||||
*/
|
|
||||||
listSearch(list_name, media_type='movie', id, page='1') {
|
|
||||||
const params = {'id': id, 'page': page}
|
|
||||||
const cacheKey = `${this.cacheTags[list_name]}:${media_type}:${id}:${page}`;
|
|
||||||
return Promise.resolve()
|
|
||||||
.then(() => this.cache.get(cacheKey))
|
|
||||||
.catch(() => this.searchTmdbList(list_name, media_type, params))
|
|
||||||
.then((response) => this.cache.set(cacheKey, response))
|
|
||||||
.then((response) => this.mapResults(response, media_type))
|
|
||||||
.catch((error) => { throw new Error(error); })
|
|
||||||
.then(([mappedResults, pagenumber, totalpages]) => {
|
|
||||||
return {'results': mappedResults, 'page': pagenumber, 'total_pages': totalpages}
|
|
||||||
})
|
})
|
||||||
|
.catch((error) => { throw new Error(error); });
|
||||||
}
|
}
|
||||||
|
|
||||||
tmdb(method, argument) {
|
tmdb(method, argument) {
|
||||||
@@ -178,7 +119,7 @@ class TMDB {
|
|||||||
if (error) {
|
if (error) {
|
||||||
return reject(error);
|
return reject(error);
|
||||||
}
|
}
|
||||||
resolve(reponse);
|
return resolve(reponse);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!argument) {
|
if (!argument) {
|
||||||
@@ -186,7 +127,7 @@ class TMDB {
|
|||||||
} else {
|
} else {
|
||||||
this.tmdbLibrary[method](argument, callback);
|
this.tmdbLibrary[method](argument, callback);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ const User = require('src/user/user');
|
|||||||
const jwt = require('jsonwebtoken');
|
const jwt = require('jsonwebtoken');
|
||||||
|
|
||||||
class Token {
|
class Token {
|
||||||
|
|
||||||
constructor(user) {
|
constructor(user) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ const assert = require('assert');
|
|||||||
const establishedDatabase = require('src/database/database');
|
const establishedDatabase = require('src/database/database');
|
||||||
|
|
||||||
class UserRepository {
|
class UserRepository {
|
||||||
|
|
||||||
constructor(database) {
|
constructor(database) {
|
||||||
this.database = database || establishedDatabase;
|
this.database = database || establishedDatabase;
|
||||||
this.queries = {
|
this.queries = {
|
||||||
@@ -53,7 +52,6 @@ class UserRepository {
|
|||||||
changePassword(user, password) {
|
changePassword(user, password) {
|
||||||
return this.database.run(this.queries.change, [password, user.username]);
|
return this.database.run(this.queries.change, [password, user.username]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = UserRepository;
|
module.exports = UserRepository;
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ const bcrypt = require('bcrypt-nodejs');
|
|||||||
const UserRepository = require('src/user/userRepository');
|
const UserRepository = require('src/user/userRepository');
|
||||||
|
|
||||||
class UserSecurity {
|
class UserSecurity {
|
||||||
|
|
||||||
constructor(database) {
|
constructor(database) {
|
||||||
this.userRepository = new UserRepository(database);
|
this.userRepository = new UserRepository(database);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const configuration = require('src/config/configuration').getInstance();
|
|||||||
|
|
||||||
// TODO: Have our raven router check if there is a value, if not don't enable raven.
|
// TODO: Have our raven router check if there is a value, if not don't enable raven.
|
||||||
Raven.config(configuration.get('raven', 'DSN')).install();
|
Raven.config(configuration.get('raven', 'DSN')).install();
|
||||||
|
|
||||||
const app = express(); // define our app using express
|
const app = express(); // define our app using express
|
||||||
app.use(Raven.requestHandler());
|
app.use(Raven.requestHandler());
|
||||||
// this will let us get the data from a POST
|
// this will let us get the data from a POST
|
||||||
@@ -18,7 +19,6 @@ app.use(bodyParser.json());
|
|||||||
/* Decode the Authorization header if provided */
|
/* Decode the Authorization header if provided */
|
||||||
// router.use(tokenToUser);
|
// router.use(tokenToUser);
|
||||||
|
|
||||||
const port = 31459; // set our port
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const allowedOrigins = ['https://kevinmidboe.com', 'http://localhost:8080'];
|
const allowedOrigins = ['https://kevinmidboe.com', 'http://localhost:8080'];
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ app.use(bodyParser.urlencoded({ extended: true }));
|
|||||||
|
|
||||||
|
|
||||||
// This is probably a correct middleware/router setup
|
// This is probably a correct middleware/router setup
|
||||||
/* Decode the Authorization header if provided */
|
/* Translate the user token to a user name */
|
||||||
router.use(tokenToUser);
|
router.use(tokenToUser);
|
||||||
|
|
||||||
// TODO: Should have a separate middleware/router for handling headers.
|
// TODO: Should have a separate middleware/router for handling headers.
|
||||||
@@ -61,7 +61,7 @@ app.use(function onError(err, req, res, next) {
|
|||||||
*/
|
*/
|
||||||
router.post('/v1/user', require('./controllers/user/register.js'));
|
router.post('/v1/user', require('./controllers/user/register.js'));
|
||||||
router.post('/v1/user/login', require('./controllers/user/login.js'));
|
router.post('/v1/user/login', require('./controllers/user/login.js'));
|
||||||
router.get('/v1/user/history', mustBeAuthenticated, require('./controllers/user/history.js'));
|
router.get('/v1/user/history', require('./controllers/user/history.js'));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Seasoned
|
* Seasoned
|
||||||
@@ -83,7 +83,7 @@ router.get('/v1/plex/hook', require('./controllers/plex/hookDump.js'));
|
|||||||
/**
|
/**
|
||||||
* Requests
|
* Requests
|
||||||
*/
|
*/
|
||||||
router.get('/v1/plex/requests/all', mustBeAuthenticated, require('./controllers/plex/fetchRequested.js'));
|
router.get('/v1/plex/requests/all', require('./controllers/plex/fetchRequested.js'));
|
||||||
router.put('/v1/plex/request/:requestId', mustBeAuthenticated, require('./controllers/plex/updateRequested.js'));
|
router.put('/v1/plex/request/:requestId', mustBeAuthenticated, require('./controllers/plex/updateRequested.js'));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ const requestRepository = new RequestRepository();
|
|||||||
* @returns {Callback}
|
* @returns {Callback}
|
||||||
*/
|
*/
|
||||||
function historyController(req, res) {
|
function historyController(req, res) {
|
||||||
const user = req.loggedInUser;
|
// const user = req.loggedInUser;
|
||||||
|
|
||||||
requestRepository.fetchRequested()
|
requestRepository.fetchRequested()
|
||||||
.then((requestedItems) => {
|
.then((requestedItems) => {
|
||||||
res.send({ success: true, requestedItems });
|
res.send({ success: true, results: requestedItems, total_results: requestedItems.length });
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
res.status(401).send({ success: false, error: error.message });
|
res.status(401).send({ success: false, error: error.message });
|
||||||
|
|||||||
@@ -2,11 +2,9 @@
|
|||||||
* @Author: KevinMidboe
|
* @Author: KevinMidboe
|
||||||
* @Date: 2017-05-03 23:26:46
|
* @Date: 2017-05-03 23:26:46
|
||||||
* @Last Modified by: KevinMidboe
|
* @Last Modified by: KevinMidboe
|
||||||
* @Last Modified time: 2017-05-03 23:27:59
|
* @Last Modified time: 2018-02-06 20:54:22
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const configuration = require('src/config/configuration').getInstance();
|
|
||||||
|
|
||||||
function hookDumpController(req, res) {
|
function hookDumpController(req, res) {
|
||||||
console.log(req);
|
console.log(req);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const PlexRepository = require('src/plex/plexRepository');
|
const PlexRepository = require('src/plex/plexRepository');
|
||||||
|
|
||||||
const plexRepository = new PlexRepository();
|
const plexRepository = new PlexRepository();
|
||||||
|
|
||||||
function playingController(req, res) {
|
function playingController(req, res) {
|
||||||
@@ -7,8 +8,8 @@ function playingController(req, res) {
|
|||||||
res.send(movies);
|
res.send(movies);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
res.status(500).send({success: false, error: error.message });
|
res.status(500).send({ success: false, error: error.message });
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = playingController;
|
module.exports = playingController;
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
const RequestRepository = require('src/plex/requestRepository');
|
const RequestRepository = require('src/plex/requestRepository');
|
||||||
|
|
||||||
const requestRepository = new RequestRepository();
|
const requestRepository = new RequestRepository();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const PlexRepository = require('src/plex/plexRepository');
|
const PlexRepository = require('src/plex/plexRepository');
|
||||||
|
|
||||||
const plexRepository = new PlexRepository();
|
const plexRepository = new PlexRepository();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,19 +10,19 @@ const plexRepository = new PlexRepository();
|
|||||||
* @returns {Callback}
|
* @returns {Callback}
|
||||||
*/
|
*/
|
||||||
function searchMediaController(req, res) {
|
function searchMediaController(req, res) {
|
||||||
const { query, page } = req.query;
|
const { query } = req.query;
|
||||||
|
|
||||||
plexRepository.searchMedia(query)
|
plexRepository.search(query)
|
||||||
.then((media) => {
|
.then((media) => {
|
||||||
if (media !== undefined || media.length > 0) {
|
if (media !== undefined || media.length > 0) {
|
||||||
res.send(media);
|
res.send(media);
|
||||||
} else {
|
} else {
|
||||||
res.status(404).send({ success: false, error: 'Search query did not return any results.'})
|
res.status(404).send({ success: false, error: 'Search query did not return any results.' });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
res.status(500).send({success: false, error: error.message });
|
res.status(500).send({ success: false, error: error.message });
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = searchMediaController;
|
module.exports = searchMediaController;
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
const SearchHistory = require('src/searchHistory/searchHistory');
|
const SearchHistory = require('src/searchHistory/searchHistory');
|
||||||
const Cache = require('src/tmdb/cache');
|
const Cache = require('src/tmdb/cache');
|
||||||
const RequestRepository = require('src/plex/requestRepository.js');
|
const RequestRepository = require('src/plex/requestRepository.js');
|
||||||
|
|
||||||
const cache = new Cache();
|
const cache = new Cache();
|
||||||
const requestRepository = new RequestRepository(cache);
|
const requestRepository = new RequestRepository(cache);
|
||||||
const searchHistory = new SearchHistory();
|
const searchHistory = new SearchHistory();
|
||||||
@@ -9,26 +10,16 @@ const searchHistory = new SearchHistory();
|
|||||||
function searchRequestController(req, res) {
|
function searchRequestController(req, res) {
|
||||||
const user = req.headers.loggedinuser;
|
const user = req.headers.loggedinuser;
|
||||||
const { query, page, type } = req.query;
|
const { query, page, type } = req.query;
|
||||||
console.log('searchReq: ' + query, page, type);
|
|
||||||
|
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
.then(() => {
|
.then(() => searchHistory.create(user, query))
|
||||||
if (user !== 'false') {
|
.then(() => requestRepository.search(query, page, type))
|
||||||
searchHistory.create(user, query);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(() => requestRepository.searchRequest(query, page, type))
|
|
||||||
.then((searchResult) => {
|
.then((searchResult) => {
|
||||||
if (searchResult.results.length > 0) {
|
|
||||||
res.send(searchResult);
|
res.send(searchResult);
|
||||||
}
|
|
||||||
else {
|
|
||||||
res.status(404).send({success: false, error: 'Search query did not return any results.'})
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
res.status(500).send({success: false, error: error.message });
|
res.status(500).send({ success: false, error: error.message });
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = searchRequestController;
|
module.exports = searchRequestController;
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
const RequestRepository = require('src/plex/requestRepository.js');
|
const RequestRepository = require('src/plex/requestRepository.js');
|
||||||
|
|
||||||
const requestRepository = new RequestRepository();
|
const requestRepository = new RequestRepository();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,7 +14,7 @@ function submitRequestController(req, res) {
|
|||||||
const id = req.params.mediaId;
|
const id = req.params.mediaId;
|
||||||
const type = req.query.type;
|
const type = req.query.type;
|
||||||
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
||||||
const user_agent = req.headers['user-agent']
|
const user_agent = req.headers['user-agent'];
|
||||||
const user = req.headers.loggedinuser;
|
const user = req.headers.loggedinuser;
|
||||||
|
|
||||||
requestRepository.sendRequest(id, type, ip, user_agent, user)
|
requestRepository.sendRequest(id, type, ip, user_agent, user)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const RequestRepository = require('src/plex/requestRepository');
|
const RequestRepository = require('src/plex/requestRepository');
|
||||||
|
|
||||||
const requestRepository = new RequestRepository();
|
const requestRepository = new RequestRepository();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const StrayRepository = require('src/seasoned/strayRepository');
|
const StrayRepository = require('src/seasoned/strayRepository');
|
||||||
|
|
||||||
const strayRepository = new StrayRepository();
|
const strayRepository = new StrayRepository();
|
||||||
|
|
||||||
|
|
||||||
@@ -9,7 +10,7 @@ function readStraysController(req, res) {
|
|||||||
res.send(strays);
|
res.send(strays);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
res.status(500).send({success: false, error: error.message });
|
res.status(500).send({ success: false, error: error.message });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const configuration = require('src/config/configuration').getInstance();
|
|
||||||
const StrayRepository = require('src/seasoned/strayRepository');
|
const StrayRepository = require('src/seasoned/strayRepository');
|
||||||
|
|
||||||
const strayRepository = new StrayRepository();
|
const strayRepository = new StrayRepository();
|
||||||
|
|
||||||
function strayByIdController(req, res) {
|
function strayByIdController(req, res) {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
const configuration = require('src/config/configuration').getInstance();
|
const configuration = require('src/config/configuration').getInstance();
|
||||||
const Cache = require('src/tmdb/cache');
|
const Cache = require('src/tmdb/cache');
|
||||||
const TMDB = require('src/tmdb/tmdb');
|
const TMDB = require('src/tmdb/tmdb');
|
||||||
|
|
||||||
const cache = new Cache();
|
const cache = new Cache();
|
||||||
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
|
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller: Retrieve nowplaying movies / now airing shows
|
* Controller: Retrieve nowplaying movies / now airing shows
|
||||||
* @param {Request} req http request variable
|
* @param {Request} req http request variable
|
||||||
@@ -14,7 +14,6 @@ const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
|
|||||||
function listSearchController(req, res) {
|
function listSearchController(req, res) {
|
||||||
const listname = req.params.listname;
|
const listname = req.params.listname;
|
||||||
const { type, id, page } = req.query;
|
const { type, id, page } = req.query;
|
||||||
console.log(listname, type, id, page)
|
|
||||||
tmdb.listSearch(listname, type, id, page)
|
tmdb.listSearch(listname, type, id, page)
|
||||||
.then((results) => {
|
.then((results) => {
|
||||||
res.send(results);
|
res.send(results);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const configuration = require('src/config/configuration').getInstance();
|
const configuration = require('src/config/configuration').getInstance();
|
||||||
const Cache = require('src/tmdb/cache');
|
const Cache = require('src/tmdb/cache');
|
||||||
const TMDB = require('src/tmdb/tmdb');
|
const TMDB = require('src/tmdb/tmdb');
|
||||||
|
|
||||||
const cache = new Cache();
|
const cache = new Cache();
|
||||||
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
|
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const configuration = require('src/config/configuration').getInstance();
|
const configuration = require('src/config/configuration').getInstance();
|
||||||
const Cache = require('src/tmdb/cache');
|
const Cache = require('src/tmdb/cache');
|
||||||
const TMDB = require('src/tmdb/tmdb');
|
const TMDB = require('src/tmdb/tmdb');
|
||||||
|
|
||||||
const cache = new Cache();
|
const cache = new Cache();
|
||||||
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
|
const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ function searchMediaController(req, res) {
|
|||||||
if (movies !== undefined || movies.length > 0) {
|
if (movies !== undefined || movies.length > 0) {
|
||||||
res.send(movies);
|
res.send(movies);
|
||||||
} else {
|
} else {
|
||||||
res.status(404).send({ success: false, error: 'Search query did not return any results.'})
|
res.status(404).send({ success: false, error: 'Search query did not return any results.' });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const SearchHistory = require('src/searchHistory/searchHistory');
|
const SearchHistory = require('src/searchHistory/searchHistory');
|
||||||
|
|
||||||
const searchHistory = new SearchHistory();
|
const searchHistory = new SearchHistory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const User = require('src/user/user');
|
|||||||
const Token = require('src/user/token');
|
const Token = require('src/user/token');
|
||||||
const UserSecurity = require('src/user/userSecurity');
|
const UserSecurity = require('src/user/userSecurity');
|
||||||
const configuration = require('src/config/configuration').getInstance();
|
const configuration = require('src/config/configuration').getInstance();
|
||||||
|
|
||||||
const secret = configuration.get('authentication', 'secret');
|
const secret = configuration.get('authentication', 'secret');
|
||||||
const userSecurity = new UserSecurity();
|
const userSecurity = new UserSecurity();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const User = require('src/user/user');
|
const User = require('src/user/user');
|
||||||
const UserSecurity = require('src/user/userSecurity');
|
const UserSecurity = require('src/user/userSecurity');
|
||||||
|
|
||||||
const userSecurity = new UserSecurity();
|
const userSecurity = new UserSecurity();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
const mustBeAuthenticated = (req, res, next) => {
|
const mustBeAuthenticated = (req, res, next) => {
|
||||||
|
|
||||||
if (req.loggedInUser === undefined) {
|
if (req.loggedInUser === undefined) {
|
||||||
return res.status(401).send({
|
return res.status(401).send({
|
||||||
success: false,
|
success: false,
|
||||||
error: 'You must be logged in.',
|
error: 'You must be logged in.',
|
||||||
}); }
|
});
|
||||||
|
}
|
||||||
return next();
|
return next();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/* eslint-disable no-param-reassign */
|
/* eslint-disable no-param-reassign */
|
||||||
const configuration = require('src/config/configuration').getInstance();
|
const configuration = require('src/config/configuration').getInstance();
|
||||||
|
|
||||||
const secret = configuration.get('authentication', 'secret');
|
const secret = configuration.get('authentication', 'secret');
|
||||||
const Token = require('src/user/token');
|
const Token = require('src/user/token');
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ const config = require('src/config/configuration').getInstance();
|
|||||||
const app = require('./app');
|
const app = require('./app');
|
||||||
|
|
||||||
module.exports = app.listen(config.get('webserver', 'port'), () => {
|
module.exports = app.listen(config.get('webserver', 'port'), () => {
|
||||||
|
/* eslint-disable no-console */
|
||||||
console.log('seasonedAPI');
|
console.log('seasonedAPI');
|
||||||
|
/* eslint-disable no-console */
|
||||||
console.log(`Database is located at ${config.get('database', 'host')}`);
|
console.log(`Database is located at ${config.get('database', 'host')}`);
|
||||||
|
/* eslint-disable no-console */
|
||||||
console.log(`Webserver is listening on ${config.get('webserver', 'port')}`);
|
console.log(`Webserver is listening on ${config.get('webserver', 'port')}`);
|
||||||
})
|
});
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -8,7 +8,7 @@ describe('As a user I want a forbidden error if the token is malformed', () => {
|
|||||||
|
|
||||||
it('should return 401', () =>
|
it('should return 401', () =>
|
||||||
request(app)
|
request(app)
|
||||||
.get('/api/v1/plex/requests/all')
|
.get('/api/v1/pirate/search?query=test')
|
||||||
.set('Authorization', 'maLfOrMed TOKEN')
|
.set('Authorization', 'maLfOrMed TOKEN')
|
||||||
.expect(401)
|
.expect(401)
|
||||||
.then(response => assert.equal(response.body.error, 'You must be logged in.'))
|
.then(response => assert.equal(response.body.error, 'You must be logged in.'))
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ describe('As a user I want to request a movie', () => {
|
|||||||
|
|
||||||
it('should return 200 when item is requested', () =>
|
it('should return 200 when item is requested', () =>
|
||||||
request(app)
|
request(app)
|
||||||
.post('/api/v1/plex/request/31749')
|
.post('/api/v1/plex/request/329865')
|
||||||
.set('Authorization', createToken('test_user', 'secret'))
|
.set('Authorization', createToken('test_user', 'secret'))
|
||||||
.expect(200)
|
.expect(200)
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user