Linted all plex scripts.
This commit is contained in:
@@ -5,15 +5,15 @@ const convertStreamToUser = require('src/plex/stream/convertStreamToUser');
|
||||
const ConvertStreamToPlayback = require('src/plex/stream/convertStreamToPlayback');
|
||||
|
||||
function convertPlexToStream(plexStream) {
|
||||
const stream = convertPlexToSeasoned(plexStream)
|
||||
const plexStreamMedia = plexStream.Media[0]
|
||||
stream.mediaInfo = convertStreamToMediaInfo(plexStreamMedia);
|
||||
stream.player = convertStreamToPlayer(plexStream.Player);
|
||||
const stream = convertPlexToSeasoned(plexStream);
|
||||
const plexStreamMedia = plexStream.Media[0];
|
||||
stream.mediaInfo = convertStreamToMediaInfo(plexStreamMedia);
|
||||
stream.player = convertStreamToPlayer(plexStream.Player);
|
||||
|
||||
stream.user = convertStreamToUser(plexStream.User);
|
||||
stream.playback = new ConvertStreamToPlayback(plexStreamMedia.Part[0]);
|
||||
stream.user = convertStreamToUser(plexStream.User);
|
||||
stream.playback = new ConvertStreamToPlayback(plexStreamMedia.Part[0]);
|
||||
|
||||
return stream;
|
||||
return stream;
|
||||
}
|
||||
|
||||
module.exports = convertPlexToStream;
|
||||
module.exports = convertPlexToStream;
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
const MediaInfo = require('src/media_classes/mediaInfo');
|
||||
|
||||
function convertStreamToMediaInfo(plexStream) {
|
||||
const mediaInfo = new MediaInfo();
|
||||
|
||||
mediaInfo.duration = plexStream.duration;
|
||||
mediaInfo.height = plexStream.height;
|
||||
mediaInfo.width = plexStream.width;
|
||||
const mediaInfo = new MediaInfo();
|
||||
|
||||
if (plexStream.bitrate) {
|
||||
mediaInfo.bitrate = plexStream.bitrate;
|
||||
}
|
||||
mediaInfo.resolution = plexStream.videoResolution;
|
||||
mediaInfo.framerate = plexStream.videoFrameRate;
|
||||
mediaInfo.protocol = plexStream.protocol;
|
||||
mediaInfo.container = plexStream.container;
|
||||
mediaInfo.audioCodec = plexStream.audioCodec;
|
||||
mediaInfo.duration = plexStream.duration;
|
||||
mediaInfo.height = plexStream.height;
|
||||
mediaInfo.width = plexStream.width;
|
||||
|
||||
return mediaInfo;
|
||||
if (plexStream.bitrate) {
|
||||
mediaInfo.bitrate = plexStream.bitrate;
|
||||
}
|
||||
mediaInfo.resolution = plexStream.videoResolution;
|
||||
mediaInfo.framerate = plexStream.videoFrameRate;
|
||||
mediaInfo.protocol = plexStream.protocol;
|
||||
mediaInfo.container = plexStream.container;
|
||||
mediaInfo.audioCodec = plexStream.audioCodec;
|
||||
|
||||
return mediaInfo;
|
||||
}
|
||||
|
||||
module.exports = convertStreamToMediaInfo;
|
||||
module.exports = convertStreamToMediaInfo;
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/*
|
||||
* @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();
|
||||
|
||||
function hookDumpController(req, res) {
|
||||
console.log(req);
|
||||
console.log(req);
|
||||
}
|
||||
|
||||
module.exports = hookDumpController;
|
||||
module.exports = hookDumpController;
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
class mailTemplate {
|
||||
|
||||
constructor(mediaItem) {
|
||||
this.mediaItem = mediaItem;
|
||||
this.posterURL = 'https://image.tmdb.org/t/p/w600';
|
||||
}
|
||||
constructor(mediaItem) {
|
||||
this.mediaItem = mediaItem;
|
||||
this.posterURL = 'https://image.tmdb.org/t/p/w600';
|
||||
}
|
||||
|
||||
toText() {
|
||||
return this.mediaItem.title + ' (' + this.mediaItem.year + ')'; // plain text body
|
||||
}
|
||||
toText() {
|
||||
return `${this.mediaItem.title} (${this.mediaItem.year})`; // plain text body
|
||||
}
|
||||
|
||||
toHTML() {
|
||||
const info = {
|
||||
name: this.mediaItem.title,
|
||||
year: '(' + this.mediaItem.year + ')',
|
||||
poster: this.posterURL + this.mediaItem.poster
|
||||
}
|
||||
toHTML() {
|
||||
const info = {
|
||||
name: this.mediaItem.title,
|
||||
year: `(${this.mediaItem.year})`,
|
||||
poster: this.posterURL + this.mediaItem.poster,
|
||||
};
|
||||
|
||||
return `
|
||||
<h1>${info.name} ${info.year}</h1>
|
||||
<img src="${info.poster}">
|
||||
`
|
||||
}
|
||||
return `
|
||||
<h1>${info.name} ${info.year}</h1>
|
||||
<img src="${info.poster}">
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = mailTemplate;
|
||||
module.exports = mailTemplate;
|
||||
|
||||
@@ -1,87 +1,80 @@
|
||||
const assert = require('assert');
|
||||
const convertPlexToSeasoned = require('src/plex/convertPlexToSeasoned');
|
||||
const convertPlexToStream = require('src/plex/convertPlexToStream');
|
||||
var rp = require('request-promise');
|
||||
|
||||
const PLEX_METHODS = ['lookup', 'playing']
|
||||
const rp = require('request-promise');
|
||||
|
||||
class PlexRepository {
|
||||
inPlex(tmdbResult) {
|
||||
return Promise.resolve()
|
||||
.then(() => this.search(tmdbResult.title))
|
||||
.then(plexResult => this.compareTmdbToPlex(tmdbResult, plexResult));
|
||||
}
|
||||
|
||||
search(query, callback) {
|
||||
var options = {
|
||||
uri: 'http://10.0.0.44:32400/search?query=' + query,
|
||||
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)
|
||||
.then((result) => this.mapResults(result))
|
||||
.then(([mappedResults, resultCount]) => {
|
||||
return { 'results': mappedResults, 'total_results': resultCount }
|
||||
})
|
||||
}
|
||||
return rp(options)
|
||||
.then(result => this.mapResults(result))
|
||||
.then(([mappedResults, resultCount]) => ({ results: mappedResults, total_results: resultCount }));
|
||||
}
|
||||
|
||||
compareTmdbToPlex(tmdb, plexResult) {
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
plexResult.results.map((plexItem) => {
|
||||
if (tmdb.title === plexItem.title && tmdb.year === plexItem.year)
|
||||
tmdb.matchedInPlex = true;
|
||||
})
|
||||
return tmdb
|
||||
})
|
||||
}
|
||||
static compareTmdbToPlex(tmdb, plexResult) {
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
plexResult.results.map((plexItem) => {
|
||||
if (tmdb.title === plexItem.title && tmdb.year === plexItem.year) { tmdb.matchedInPlex = true; }
|
||||
return tmdb;
|
||||
});
|
||||
return tmdb;
|
||||
});
|
||||
}
|
||||
|
||||
inPlex(tmdbResult) {
|
||||
return Promise.resolve()
|
||||
.then(() => this.search(tmdbResult.title))
|
||||
.then((plexResult) => this.compareTmdbToPlex(tmdbResult, plexResult))
|
||||
}
|
||||
static mapResults(response) {
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
if (!response.MediaContainer.hasOwnProperty('Metadata')) return [[], 0];
|
||||
|
||||
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); });
|
||||
}
|
||||
|
||||
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() {
|
||||
const options = {
|
||||
uri: 'http://10.0.0.44:32400/status/sessions',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
},
|
||||
json: true,
|
||||
};
|
||||
|
||||
nowPlaying() {
|
||||
var options = {
|
||||
uri: 'http://10.0.0.44:32400/status/sessions',
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
json: true
|
||||
}
|
||||
return rp(options)
|
||||
.then((result) => {
|
||||
if (result.MediaContainer.size > 0) {
|
||||
const playing = result.MediaContainer.Video.map(convertPlexToStream);
|
||||
return { size: Object.keys(playing).length, video: playing };
|
||||
}
|
||||
return { size: 0, video: [] };
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new Error(`Error handling plex playing. Error: ${err}`);
|
||||
});
|
||||
}
|
||||
|
||||
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('Error handling plex playing. Error: ' + err);
|
||||
})
|
||||
}
|
||||
|
||||
// multipleInPlex(tmdbResults) {
|
||||
// const results = tmdbResults.results.map(async (tmdb) => {
|
||||
// return this.inPlex(tmdb)
|
||||
// })
|
||||
// return Promise.all(results)
|
||||
// }
|
||||
// multipleInPlex(tmdbResults) {
|
||||
// const results = tmdbResults.results.map(async (tmdb) => {
|
||||
// return this.inPlex(tmdb)
|
||||
// })
|
||||
// return Promise.all(results)
|
||||
// }
|
||||
}
|
||||
|
||||
module.exports = PlexRepository;
|
||||
|
||||
@@ -1,132 +1,117 @@
|
||||
const assert = require('assert');
|
||||
const PlexRepository = require('src/plex/plexRepository');
|
||||
const plexRepository = new PlexRepository();
|
||||
const configuration = require('src/config/configuration').getInstance();
|
||||
const Cache = require('src/tmdb/cache');
|
||||
const configuration = require('src/config/configuration').getInstance();
|
||||
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 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');
|
||||
|
||||
|
||||
class RequestRepository {
|
||||
constructor(cache, database) {
|
||||
this.database = database || establishedDatabase;
|
||||
this.queries = {
|
||||
insertRequest: "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?, ?)",
|
||||
fetchRequstedItems: 'SELECT * FROM requests',
|
||||
updateRequestedById: 'UPDATE requests SET status = ? WHERE id is ? AND type is ?',
|
||||
checkIfIdRequested: 'SELECT * FROM requests WHERE id IS ? AND type IS ?',
|
||||
};
|
||||
}
|
||||
|
||||
constructor(cache, database) {
|
||||
this.database = database || establishedDatabase;
|
||||
this.queries = {
|
||||
'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?, ?)",
|
||||
'fetchRequstedItems': "SELECT * FROM requests",
|
||||
'updateRequestedById': "UPDATE requests SET status = ? WHERE id is ? AND type is ?",
|
||||
'checkIfIdRequested': "SELECT * FROM requests WHERE id IS ? AND type IS ?",
|
||||
}
|
||||
}
|
||||
search(query, type, page) {
|
||||
return Promise.resolve()
|
||||
.then(() => tmdb.search(query, type, page))
|
||||
// .then((tmdbResult) => plexRepository.multipleInPlex(tmdbResult))
|
||||
.then(result => result)
|
||||
.catch(error => `error in the house${error}`);
|
||||
}
|
||||
|
||||
search(query, type, page) {
|
||||
return Promise.resolve()
|
||||
.then(() => tmdb.search(query, type, page))
|
||||
// .then((tmdbResult) => plexRepository.multipleInPlex(tmdbResult))
|
||||
.then((result) => {
|
||||
return result
|
||||
})
|
||||
.catch((error) => {return 'error in the house' + error})
|
||||
}
|
||||
lookup(identifier, type = 'movie') {
|
||||
return Promise.resolve()
|
||||
.then(() => tmdb.lookup(identifier, type))
|
||||
.then(tmdbMovie => this.checkID(tmdbMovie))
|
||||
.then(tmdbMovie => plexRepository.inPlex(tmdbMovie))
|
||||
.catch((error) => {
|
||||
throw new Error(error);
|
||||
});
|
||||
}
|
||||
|
||||
lookup(identifier, type = 'movie') {
|
||||
return Promise.resolve()
|
||||
.then(() => tmdb.lookup(identifier, type))
|
||||
.then((tmdbMovie) => this.checkID(tmdbMovie))
|
||||
.then((tmdbMovie) => plexRepository.inPlex(tmdbMovie))
|
||||
.catch((error) => {
|
||||
console.log(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; }
|
||||
|
||||
checkID(tmdbMovie) {
|
||||
return Promise.resolve()
|
||||
.then(() => this.database.get(this.queries.checkIfIdRequested, [tmdbMovie.id, tmdbMovie.type]))
|
||||
.then((result, error) => {
|
||||
let already_requested = false;
|
||||
if (result)
|
||||
already_requested = true
|
||||
tmdbMovie.requested = already_requested;
|
||||
return tmdbMovie;
|
||||
});
|
||||
}
|
||||
|
||||
tmdbMovie.requested = already_requested;
|
||||
return tmdbMovie;
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Send request for given media id.
|
||||
* @param {identifier, type} the id of the media object and type of media must be defined
|
||||
* @returns {Promise} If nothing has gone wrong.
|
||||
*/
|
||||
sendRequest(identifier, type, ip, user_agent, user) {
|
||||
tmdb.lookup(identifier, type).then(movie => {
|
||||
|
||||
if (user === 'false')
|
||||
user = 'NULL';
|
||||
console.log(user)
|
||||
// Add request to database
|
||||
this.database.run(this.queries.insertRequest, [movie.id, movie.title, movie.year, movie.poster_path, movie.background_path, user, ip, user_agent, movie.type])
|
||||
/**
|
||||
* Send request for given media id.
|
||||
* @param {identifier, type} the id of the media object and type of media must be defined
|
||||
* @returns {Promise} If nothing has gone wrong.
|
||||
*/
|
||||
sendRequest(identifier, type, ip, user_agent, user) {
|
||||
tmdb.lookup(identifier, type).then((movie) => {
|
||||
if (user === 'false') { user = 'NULL'; }
|
||||
// Add request to database
|
||||
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
|
||||
let transporter = nodemailer.createTransport({
|
||||
service: 'gmail',
|
||||
auth: {
|
||||
user: configuration.get('mail', 'user_pi'),
|
||||
pass: configuration.get('mail', 'password_pi')
|
||||
}
|
||||
// host: configuration.get('mail', 'host'),
|
||||
// port: 26,
|
||||
// ignoreTLS: true,
|
||||
// tls :{rejectUnauthorized: false},
|
||||
// secure: false, // secure:true for port 465, secure:false for port 587
|
||||
});
|
||||
// create reusable transporter object using the default SMTP transport
|
||||
const transporter = nodemailer.createTransport({
|
||||
service: 'gmail',
|
||||
auth: {
|
||||
user: configuration.get('mail', 'user_pi'),
|
||||
pass: configuration.get('mail', 'password_pi'),
|
||||
},
|
||||
// host: configuration.get('mail', 'host'),
|
||||
// port: 26,
|
||||
// ignoreTLS: true,
|
||||
// tls :{rejectUnauthorized: false},
|
||||
// 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
|
||||
let mailOptions = {
|
||||
// TODO get the mail adr from global location (easy to add)
|
||||
from: 'MovieRequester <pi.midboe@gmail.com>', // sender address
|
||||
to: 'kevin.midboe@gmail.com', // list of receivers
|
||||
subject: 'Download request', // Subject line
|
||||
text: mailTemplate.toText(),
|
||||
html: mailTemplate.toHTML()
|
||||
};
|
||||
// setup email data with unicode symbols
|
||||
const mailOptions = {
|
||||
// TODO get the mail adr from global location (easy to add)
|
||||
from: 'MovieRequester <pi.midboe@gmail.com>', // sender address
|
||||
to: 'kevin.midboe@gmail.com', // list of receivers
|
||||
subject: 'Download request', // Subject line
|
||||
text: mailTemplate.toText(),
|
||||
html: mailTemplate.toHTML(),
|
||||
};
|
||||
|
||||
// send mail with defined transport object
|
||||
transporter.sendMail(mailOptions, (error, info) => {
|
||||
if (error) {
|
||||
return console.log(error);
|
||||
}
|
||||
console.log('Message %s sent: %s', info.messageId, info.response);
|
||||
});
|
||||
// send mail with defined transport object
|
||||
transporter.sendMail(mailOptions, (error, info) => {
|
||||
if (error) {
|
||||
return console.log(error);
|
||||
}
|
||||
console.log('Message %s sent: %s', info.messageId, info.response);
|
||||
});
|
||||
});
|
||||
|
||||
})
|
||||
// TODO add better response when done.
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
// TODO add better response when done.
|
||||
return Promise.resolve();
|
||||
|
||||
}
|
||||
|
||||
fetchRequested() {
|
||||
return this.database.all(this.queries.fetchRequstedItems);
|
||||
}
|
||||
|
||||
updateRequestedById(id, type, status) {
|
||||
return this.database.run(this.queries.updateRequestedById, [status, id, type]);
|
||||
}
|
||||
fetchRequested() {
|
||||
return this.database.all(this.queries.fetchRequstedItems);
|
||||
}
|
||||
|
||||
updateRequestedById(id, type, status) {
|
||||
return this.database.run(this.queries.updateRequestedById, [status, id, type]);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RequestRepository;
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
class convertStreamToPlayback {
|
||||
constructor(plexStream) {
|
||||
this.bitrate = plexStream.bitrate;
|
||||
this.width = plexStream.width;
|
||||
this.height = plexStream.height;
|
||||
this.decision = plexStream.decision;
|
||||
this.audioProfile = plexStream.audioProfile;
|
||||
this.videoProfile = plexStream.videoProfile;
|
||||
this.duration = plexStream.duration;
|
||||
this.container = plexStream.container;
|
||||
|
||||
}
|
||||
constructor(plexStream) {
|
||||
this.bitrate = plexStream.bitrate;
|
||||
this.width = plexStream.width;
|
||||
this.height = plexStream.height;
|
||||
this.decision = plexStream.decision;
|
||||
this.audioProfile = plexStream.audioProfile;
|
||||
this.videoProfile = plexStream.videoProfile;
|
||||
this.duration = plexStream.duration;
|
||||
this.container = plexStream.container;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = convertStreamToPlayback;
|
||||
module.exports = convertStreamToPlayback;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
const Player = require('src/media_classes/player');
|
||||
|
||||
function convertStreamToPlayer(plexStream) {
|
||||
const player = new Player(plexStream.device, plexStream.address);
|
||||
player.platform = plexStream.platform;
|
||||
player.product = plexStream.product;
|
||||
player.title = plexStream.title;
|
||||
player.state = plexStream.state;
|
||||
const player = new Player(plexStream.device, plexStream.address);
|
||||
player.platform = plexStream.platform;
|
||||
player.product = plexStream.product;
|
||||
player.title = plexStream.title;
|
||||
player.state = plexStream.state;
|
||||
|
||||
return player;
|
||||
return player;
|
||||
}
|
||||
|
||||
module.exports = convertStreamToPlayer;
|
||||
module.exports = convertStreamToPlayer;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const User = require('src/media_classes/user');
|
||||
|
||||
function convertStreamToUser(plexStream) {
|
||||
return new User(plexStream.id, plexStream.title);
|
||||
return new User(plexStream.id, plexStream.title);
|
||||
}
|
||||
|
||||
module.exports = convertStreamToUser;
|
||||
module.exports = convertStreamToUser;
|
||||
|
||||
Reference in New Issue
Block a user