@@ -1,17 +1,20 @@
|
||||
class Movie {
|
||||
constructor(title, year) {
|
||||
constructor(title, year, type) {
|
||||
this.id = undefined;
|
||||
this.title = title;
|
||||
this.year = year;
|
||||
this.type = type;
|
||||
this.release_date = undefined;
|
||||
this.library = undefined;
|
||||
this.type = 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;
|
||||
this.childTitle = undefined;
|
||||
this.season = undefined;
|
||||
this.episode = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
22
seasoned_api/src/media_classes/show.js
Normal file
22
seasoned_api/src/media_classes/show.js
Normal file
@@ -0,0 +1,22 @@
|
||||
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;
|
||||
@@ -1,22 +0,0 @@
|
||||
const Movie = require('src/media_classes/movie');
|
||||
|
||||
function convertPlexToMovie(plexMovie) {
|
||||
const movie = new Movie();
|
||||
movie.title = plexMovie.title;
|
||||
|
||||
if (plexMovie.type === 'episode') {
|
||||
movie.title = plexMovie.grandparentTitle;
|
||||
movie.childTitle = plexMovie.title;
|
||||
movie.season = plexMovie.parentIndex;
|
||||
movie.episode = plexMovie.index;
|
||||
}
|
||||
movie.year = plexMovie.year;
|
||||
movie.library = plexMovie.librarySectionTitle;
|
||||
movie.type = plexMovie.type;
|
||||
movie.poster = plexMovie.thumb;
|
||||
movie.background = plexMovie.art;
|
||||
|
||||
return movie;
|
||||
}
|
||||
|
||||
module.exports = convertPlexToMovie;
|
||||
39
seasoned_api/src/plex/convertPlexToSeasoned.js
Normal file
39
seasoned_api/src/plex/convertPlexToSeasoned.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const Movie = require('src/media_classes/movie');
|
||||
const Show = require('src/media_classes/show');
|
||||
|
||||
function convertPlexToSeasoned(plexObject) {
|
||||
|
||||
const mediaType = plexObject.type;
|
||||
// There are many diff types of content, we only want to look at movies and tv shows
|
||||
if (mediaType === 'movie') {
|
||||
const movie = new Movie(plexObject.title, plexObject.year, mediaType);
|
||||
|
||||
movie.summary = plexObject.summary;
|
||||
movie.rating = plexObject.rating;
|
||||
movie.poster = plexObject.thumb;
|
||||
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;
|
||||
@@ -1,11 +1,11 @@
|
||||
const convertPlexToMovie = require('src/plex/convertPlexToMovie');
|
||||
const convertPlexToSeasoned = require('src/plex/convertPlexToSeasoned');
|
||||
const convertStreamToMediaInfo = require('src/plex/convertStreamToMediaInfo');
|
||||
const convertStreamToPlayer = require('src/plex/stream/convertStreamToPlayer');
|
||||
const convertStreamToUser = require('src/plex/stream/convertStreamToUser');
|
||||
const ConvertStreamToPlayback = require('src/plex/stream/convertStreamToPlayback');
|
||||
|
||||
function convertPlexToStream(plexStream) {
|
||||
const stream = convertPlexToMovie(plexStream);
|
||||
const stream = convertPlexToSeasoned(plexStream);
|
||||
stream.mediaInfo = convertStreamToMediaInfo(plexStream.Media);
|
||||
stream.player = convertStreamToPlayer(plexStream.Player);
|
||||
stream.user = convertStreamToUser(plexStream.User);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const assert = require('assert');
|
||||
const convertPlexToMovie = require('src/plex/convertPlexToMovie');
|
||||
const convertPlexToSeasoned = require('src/plex/convertPlexToSeasoned');
|
||||
const convertPlexToStream = require('src/plex/convertPlexToStream');
|
||||
const configuration = require('src/config/configuration').getInstance();
|
||||
const TMDB = require('src/tmdb/tmdb');
|
||||
@@ -19,7 +19,13 @@ class PlexRepository {
|
||||
|
||||
return rp(options)
|
||||
.then((result) => {
|
||||
return result.MediaContainer.Metadata.map(convertPlexToMovie);
|
||||
var seasonedMediaObjects = result.MediaContainer.Metadata.reduce(function(match, media_item) {
|
||||
if (media_item.type === 'movie' || media_item.type === 'show') {
|
||||
match.push(convertPlexToSeasoned(media_item));
|
||||
}
|
||||
return match;
|
||||
}, []);
|
||||
return seasonedMediaObjects;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
|
||||
120
seasoned_api/src/plex/requestRepository.js
Normal file
120
seasoned_api/src/plex/requestRepository.js
Normal file
@@ -0,0 +1,120 @@
|
||||
const assert = require('assert');
|
||||
const PlexRepository = require('src/plex/plexRepository');
|
||||
const plexRepository = new PlexRepository();
|
||||
const configuration = require('src/config/configuration').getInstance();
|
||||
const TMDB = require('src/tmdb/tmdb');
|
||||
const tmdb = new TMDB(configuration.get('tmdb', 'apiKey'));
|
||||
var Promise = require('bluebird');
|
||||
var rp = require('request-promise');
|
||||
|
||||
const MailTemplate = require('src/plex/mailTemplate')
|
||||
|
||||
var pythonShell = require('python-shell');
|
||||
const nodemailer = require('nodemailer');
|
||||
|
||||
|
||||
class RequestRepository {
|
||||
|
||||
searchRequest(query, page, type) {
|
||||
// STRIP METADATA THAT IS NOT ALLOWED
|
||||
|
||||
return Promise.resolve()
|
||||
.then(() => tmdb.search(query, page, type))
|
||||
.then((tmdbMovies) => {
|
||||
return Promise.resolve()
|
||||
.then(() => plexRepository.searchMedia(query))
|
||||
.then((plexMedia) => {
|
||||
return Promise.each(tmdbMovies, function(tmdbMovie) {
|
||||
return Promise.each(plexMedia, function(plexMovie) {
|
||||
if (tmdbMovie.title == plexMovie.title && tmdbMovie.year == plexMovie.year) {
|
||||
tmdbMovie.matchedInPlex = true;
|
||||
console.log(tmdbMovie.title + ' : ' + tmdbMovie.year);
|
||||
}
|
||||
return tmdbMovie;
|
||||
})
|
||||
})
|
||||
})
|
||||
// This is pretty janky, but if there is a error because plex does not not get any results
|
||||
// the tmdbMovies list is just returned without checking plexStatus.
|
||||
.catch((error) => {
|
||||
return tmdbMovies;
|
||||
})
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
return error;
|
||||
});
|
||||
}
|
||||
|
||||
lookup(identifier, type = 'movie') {
|
||||
if (type === 'movie') { type = 'movieInfo'}
|
||||
else if (type === 'tv') { type = 'tvInfo'}
|
||||
return Promise.resolve()
|
||||
.then(() => tmdb.lookup(identifier, type))
|
||||
.then((tmdbMovie) => {
|
||||
return Promise.resolve(plexRepository.searchMedia(tmdbMovie.title))
|
||||
.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) => {
|
||||
return error;
|
||||
});
|
||||
return tmdbMovie;
|
||||
});
|
||||
}
|
||||
|
||||
sendRequest(identifier) {
|
||||
// TODO add to DB so can have a admin page
|
||||
// TODO try a cache hit on the movie item
|
||||
|
||||
tmdb.lookup(identifier).then(movie => {
|
||||
console.log(movie.title)
|
||||
|
||||
|
||||
// create reusable transporter object using the default SMTP transport
|
||||
let transporter = nodemailer.createTransport({
|
||||
host: configuration.get('mail', 'host'),
|
||||
port: 26,
|
||||
ignoreTLS: true,
|
||||
tls :{rejectUnauthorized: false},
|
||||
secure: false, // secure:true for port 465, secure:false for port 587
|
||||
auth: {
|
||||
user: configuration.get('mail', 'user'),
|
||||
pass: configuration.get('mail', 'password')
|
||||
}
|
||||
});
|
||||
|
||||
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 <support@kevinmidboe.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);
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
return Promise.resolve();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = RequestRepository;
|
||||
@@ -1,30 +0,0 @@
|
||||
const Movie = require('src/media_classes/movie');
|
||||
|
||||
function convertTmdbToMovie(tmdbMovie) {
|
||||
const movie = new Movie();
|
||||
movie.id = tmdbMovie.id;
|
||||
if (tmdbMovie.media_type === 'movie' || tmdbMovie.release_date !== undefined) {
|
||||
movie.title = tmdbMovie.title;
|
||||
movie.type = 'movie';
|
||||
|
||||
if (tmdbMovie.release_date !== undefined) {
|
||||
movie.release_date = new Date(tmdbMovie.release_date);
|
||||
movie.year = movie.release_date.getFullYear();
|
||||
}
|
||||
} else if (tmdbMovie.first_air_date !== undefined) {
|
||||
movie.title = tmdbMovie.name;
|
||||
movie.type = 'show';
|
||||
if (tmdbMovie.first_air_date !== undefined) {
|
||||
movie.release_date = new Date(tmdbMovie.first_air_date);
|
||||
movie.year = movie.release_date.getFullYear();
|
||||
}
|
||||
}
|
||||
|
||||
movie.poster = tmdbMovie.poster_path;
|
||||
movie.background = tmdbMovie.backdrop_path;
|
||||
movie.overview = tmdbMovie.overview;
|
||||
|
||||
return movie;
|
||||
}
|
||||
|
||||
module.exports = convertTmdbToMovie;
|
||||
38
seasoned_api/src/tmdb/convertTmdbToSeasoned.js
Normal file
38
seasoned_api/src/tmdb/convertTmdbToSeasoned.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const Movie = require('src/media_classes/movie');
|
||||
const Show = require('src/media_classes/show');
|
||||
|
||||
function convertTmdbToSeasoned(tmdbObject) {
|
||||
console.log(tmdbObject)
|
||||
|
||||
const mediaType = tmdbObject.media_type;
|
||||
|
||||
// There are many diff types of content, we only want to look at movies and tv shows
|
||||
if (mediaType === 'movie') {
|
||||
const year = new Date(tmdbObject.release_date).getFullYear();
|
||||
|
||||
const movie = new Movie(tmdbObject.title, year, mediaType);
|
||||
|
||||
movie.summary = tmdbObject.overview;
|
||||
movie.rating = tmdbObject.vote_average;
|
||||
movie.poster = tmdbObject.poster_path;
|
||||
movie.background = tmdbObject.backdrop_path;
|
||||
movie.genre = tmdbObject.genre_ids;
|
||||
|
||||
return movie;
|
||||
}
|
||||
else if (mediaType === 'tv') {
|
||||
const year = new Date(tmdbObject.first_air_date).getFullYear();
|
||||
|
||||
const show = new Show(tmdbObject.title, year, mediaType);
|
||||
|
||||
show.summary = tmdbObject.overview;
|
||||
show.rating = tmdbObject.vote_average;
|
||||
show.poster = tmdbObject.poster_path;
|
||||
show.background = tmdbObject.backdrop_path;
|
||||
show.genre = tmdbObject.genre_ids;
|
||||
|
||||
return show;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = convertTmdbToSeasoned;
|
||||
@@ -1,5 +1,5 @@
|
||||
const moviedb = require('moviedb');
|
||||
const convertTmdbToMovie = require('src/tmdb/convertTmdbToMovie');
|
||||
const convertTmdbToSeasoned = require('src/tmdb/convertTmdbToSeasoned');
|
||||
var methodTypes = { 'movie': 'searchMovie', 'tv': 'searchTv', 'multi': 'searchMulti', 'movieInfo': 'movieInfo',
|
||||
'tvInfo': 'tvInfo' };
|
||||
|
||||
@@ -16,8 +16,8 @@ class TMDB {
|
||||
.then((reponse) => {
|
||||
try {
|
||||
return reponse.results.filter(function(item) {
|
||||
return (item.popularity >= 1.15)
|
||||
}).map(convertTmdbToMovie);
|
||||
return ((item.vote_count >= 20 || item.popularity > 2) && (item.release_date !== undefined || item.first_air_date !== undefined))
|
||||
}).map(convertTmdbToSeasoned);
|
||||
} catch (parseError) {
|
||||
throw new Error('Could not parse result.');
|
||||
}
|
||||
@@ -39,7 +39,7 @@ class TMDB {
|
||||
.catch(() => { throw new Error('Could not find a movie with that id.'); })
|
||||
.then((response) => {
|
||||
try {
|
||||
return convertTmdbToMovie(response);
|
||||
return convertTmdbToSeasoned(response);
|
||||
} catch (parseError) {
|
||||
throw new Error('Could not parse movie.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user