From 74c6ed02a8dd57e85f6d4040c82e7c6651b90217 Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Fri, 2 Jun 2017 08:52:54 +0200 Subject: [PATCH 01/42] Changed debug level and removed a unused exit --- classedStray.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classedStray.py b/classedStray.py index 851095c..1e0b847 100755 --- a/classedStray.py +++ b/classedStray.py @@ -147,7 +147,7 @@ def getDirContent(dir=env.show_dir): # TODO Log to error file logging.info('Error: "' + dir + '" is not a directory.') # TODO Remove this exit(0) - exit(0) + # exit(0) # Hashes the contents of media folder to easily check for changes. def directoryChecksum(): @@ -205,7 +205,7 @@ def main(): if __name__ == '__main__': if (os.path.exists(env.logfile)): - logging.basicConfig(filename=env.logfile, level=logging.INFO) + logging.basicConfig(filename=env.logfile, level=logging.DEBUG) else: print('Logfile could not be found at ' + env.logfile + '. Verifiy presence or disable logging in config.') exit(0) -- 2.34.1 From d05aa13c3944eacfa7ff02c402e26769f1e6f586 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sat, 3 Jun 2017 11:17:09 +0200 Subject: [PATCH 02/42] Changes to more strict origin policy. --- src/webserver/app.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/webserver/app.js b/src/webserver/app.js index 1b0fc39..3da8ccb 100644 --- a/src/webserver/app.js +++ b/src/webserver/app.js @@ -8,14 +8,18 @@ var bodyParser = require('body-parser'); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); -var port = 31459; // set our port +var port = 31459; // set our port var router = express.Router(); +var allowedOrigins = ['https://kevinmidboe.com', 'http://localhost:8080'] + router.use(function(req, res, next) { - // do logging console.log('Something is happening.'); - res.setHeader('Access-Control-Allow-Origin', 'https://kevinmidboe.com'); + var origin = req.headers.origin; + if (allowedOrigins.indexOf(origin) > -1) { + res.setHeader('Access-Control-Allow-Origin', origin); + } next(); }); -- 2.34.1 From 907bc73a7f125eb467572fee869e3b0b79505ae9 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sat, 3 Jun 2017 13:07:49 +0200 Subject: [PATCH 03/42] Added overview (description) from tmdb movie to movieObject. --- src/tmdb/convertTmdbToMovie.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tmdb/convertTmdbToMovie.js b/src/tmdb/convertTmdbToMovie.js index c7158d6..7740cca 100644 --- a/src/tmdb/convertTmdbToMovie.js +++ b/src/tmdb/convertTmdbToMovie.js @@ -22,6 +22,7 @@ function convertTmdbToMovie(tmdbMovie) { movie.poster = tmdbMovie.poster_path; movie.background = tmdbMovie.backdrop_path; + movie.overview = tmdbMovie.overview; return movie; } -- 2.34.1 From 9d294828579332e0e8d853b4a654d5c22ddd9fe1 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sat, 3 Jun 2017 13:12:10 +0200 Subject: [PATCH 04/42] Added overview of requested movie to be printed. --- client/app/components/MovieObject.jsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/app/components/MovieObject.jsx b/client/app/components/MovieObject.jsx index eaf4667..7784c5a 100644 --- a/client/app/components/MovieObject.jsx +++ b/client/app/components/MovieObject.jsx @@ -7,7 +7,8 @@ class MovieObject { this.year = object.year; // Check if object.poster != undefined this.poster = object.poster; - this.matchedInPlex = object.matchedInPlex + this.matchedInPlex = object.matchedInPlex; + this.overview = object.overview; } requestExisting(id) { @@ -35,6 +36,8 @@ class MovieObject { returnList.push() } + returnList.push({this.overview}); + returnList.push(

); return returnList; } -- 2.34.1 From 27edd29bd27581eb61b3f252a51f2039950bd2dd Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 4 Jun 2017 00:07:23 +0200 Subject: [PATCH 05/42] Started adding features for submitting a request to server --- client/app/components/MovieObject.jsx | 4 +++- client/app/components/SearchRequest.jsx | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client/app/components/MovieObject.jsx b/client/app/components/MovieObject.jsx index 7784c5a..4f3e8ea 100644 --- a/client/app/components/MovieObject.jsx +++ b/client/app/components/MovieObject.jsx @@ -16,7 +16,9 @@ class MovieObject { } requestMovie(id) { - console.log(id); + fetch('http://localhost:31459/api/v1/plex/request/' + id, { + method: 'POST' + }) } getElement() { diff --git a/client/app/components/SearchRequest.jsx b/client/app/components/SearchRequest.jsx index e105c0c..c6da4be 100644 --- a/client/app/components/SearchRequest.jsx +++ b/client/app/components/SearchRequest.jsx @@ -58,7 +58,7 @@ class SearchRequest extends React.Component { this._handleKeyPress(event)} - onChange={event => this.handleChange(event)} + onChange={(event) => this.handleChange(event)} value={this.state.searchQuery} /> -- 2.34.1 From 069d984c397ff43e32f3ef445811131ed98b79af Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 4 Jun 2017 00:10:35 +0200 Subject: [PATCH 06/42] Added for handling input of movie request, but still need to work on the way the python script is run. --- src/plex/requestRepository.js | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/plex/requestRepository.js b/src/plex/requestRepository.js index 0cc27dd..cd8372f 100644 --- a/src/plex/requestRepository.js +++ b/src/plex/requestRepository.js @@ -7,9 +7,23 @@ const TMDB = require('src/tmdb/tmdb'); const tmdb = new TMDB(configuration.get('tmdb', 'apiKey')); var Promise = require('bluebird'); var rp = require('request-promise'); +var pythonShell = require('python-shell'); + +const establishedDatabase = require('src/database/database'); class RequestRepository { + constructor(database) { + this.database = database || establishedDatabase; + this.queries = { + // 'read': 'SELECT * FROM stray_eps WHERE id = ?', + // 'readAll': 'SELECT id, name, season, episode, verified FROM stray_eps', + // 'readAllFiltered': 'SELECT id, name, season, episode, verified FROM stray_eps WHERE verified = ', + 'checkRequested': 'SELECT id, title FROM request WHERE id = ?', + 'request': 'UPDATE request SET matched = 1 WHERE id = ?', + }; + } + searchRequest(query, page, type) { return Promise.resolve() .then(() => tmdb.search(query, page, type)) @@ -55,6 +69,36 @@ class RequestRepository { }); } + submitRequest(movieId) { + console.log(movieId); + return Promise.resolve() + .then(() => { + pythonShell.run('moveSeasoned.py', function (err, results) { + // if (err) throw err; + // TODO Add error handling!! StrayRepository.ERROR + // results is an array consisting of messages collected during execution + console.log('results: %j', results); + }) + }) + .catch((error) => { + console.log(error); + return error; + }) + + // return this.database.get(this.queries.checkRequested, movieId).then((row) => { + // // TODO send back the name, not ID + // assert.notEqual(row, undefined, `Stray '${movieId}' already verified.`); + + // var options = { + // args: [movieId] + // } + + + + // return this.database.run(this.queries.verify, movieId); + // }) + } + } module.exports = RequestRepository; \ No newline at end of file -- 2.34.1 From 6496988e51bbcb5d6561cb9d5b9a8c757aa65a2f Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 4 Jun 2017 00:12:38 +0200 Subject: [PATCH 07/42] Changed variable names to better reflect their purpose --- src/webserver/controllers/plex/readRequest.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/webserver/controllers/plex/readRequest.js b/src/webserver/controllers/plex/readRequest.js index 0524a2f..32f1b05 100644 --- a/src/webserver/controllers/plex/readRequest.js +++ b/src/webserver/controllers/plex/readRequest.js @@ -8,9 +8,10 @@ const requestRepository = new RequestRepository(); * @returns {Callback} */ function readRequestController(req, res) { - const mediaId = req.params.mediaId; + const requestId = req.params.requestId; const { type } = req.query; - requestRepository.lookup(mediaId, type) + + requestRepository.lookup(requestId, type) .then((movies) => { res.send(movies); }).catch((error) => { -- 2.34.1 From 703e3d37858e381ab8d371cf88a6c8102439dc65 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 4 Jun 2017 00:13:02 +0200 Subject: [PATCH 08/42] Added a api endpoint for submitting a movie request. --- src/webserver/app.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/webserver/app.js b/src/webserver/app.js index 3da8ccb..0007e41 100644 --- a/src/webserver/app.js +++ b/src/webserver/app.js @@ -34,9 +34,12 @@ router.post('/v1/seasoned/verify/:strayId', require('./controllers/seasoned/veri router.get('/v1/plex/search', require('./controllers/plex/searchMedia.js')); router.get('/v1/plex/playing', require('./controllers/plex/plexPlaying.js')); + +// router.get('/v1/plex/request/all', require('./controllers/plex/searchRequest.js')); router.get('/v1/plex/request', require('./controllers/plex/searchRequest.js')); router.get('/v1/plex/request/:mediaId', require('./controllers/plex/readRequest.js')); -// router.post('/v1/plex/request/:mediaId', require('./controllers/plex/submitRequest.js')); +router.post('/v1/plex/request/:mediaId', require('./controllers/plex/submitRequest.js')); + router.get('/v1/plex/hook', require('./controllers/plex/hookDump.js')); router.get('/v1/tmdb/search', require('./controllers/tmdb/searchMedia.js')); -- 2.34.1 From 3bb43f08f2aa5404c5bd5ae2801d75ce04076bc0 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 4 Jun 2017 00:13:35 +0200 Subject: [PATCH 09/42] Controller for handling submits of item requests. --- .../controllers/plex/submitRequest.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/webserver/controllers/plex/submitRequest.js diff --git a/src/webserver/controllers/plex/submitRequest.js b/src/webserver/controllers/plex/submitRequest.js new file mode 100644 index 0000000..0a53446 --- /dev/null +++ b/src/webserver/controllers/plex/submitRequest.js @@ -0,0 +1,18 @@ +const configuration = require('src/config/configuration').getInstance(); +const RequestRepository = require('src/plex/requestRepository'); +const requestRepository = new RequestRepository(); + +function submitRequestController(req, res) { + const id = req.params.requestId; + + requestRepository.submitRequest(id) + .then(() => { + // Better sendback message. + res.send({ success: true, message: 'Request sent' }); + }) + .catch((error) => { + res.status(500).send({ success: false, error: error.message }); + }); +} + +module.exports = submitRequestController; -- 2.34.1 From 0022f656bdd812ca0ed1ec0ccbf7d62ceb90aab5 Mon Sep 17 00:00:00 2001 From: Kevin Date: Sun, 4 Jun 2017 00:16:16 +0200 Subject: [PATCH 10/42] Revert "Api" --- src/plex/requestRepository.js | 44 ------------------- src/webserver/app.js | 5 +-- src/webserver/controllers/plex/readRequest.js | 5 +-- .../controllers/plex/submitRequest.js | 18 -------- 4 files changed, 3 insertions(+), 69 deletions(-) delete mode 100644 src/webserver/controllers/plex/submitRequest.js diff --git a/src/plex/requestRepository.js b/src/plex/requestRepository.js index cd8372f..0cc27dd 100644 --- a/src/plex/requestRepository.js +++ b/src/plex/requestRepository.js @@ -7,23 +7,9 @@ const TMDB = require('src/tmdb/tmdb'); const tmdb = new TMDB(configuration.get('tmdb', 'apiKey')); var Promise = require('bluebird'); var rp = require('request-promise'); -var pythonShell = require('python-shell'); - -const establishedDatabase = require('src/database/database'); class RequestRepository { - constructor(database) { - this.database = database || establishedDatabase; - this.queries = { - // 'read': 'SELECT * FROM stray_eps WHERE id = ?', - // 'readAll': 'SELECT id, name, season, episode, verified FROM stray_eps', - // 'readAllFiltered': 'SELECT id, name, season, episode, verified FROM stray_eps WHERE verified = ', - 'checkRequested': 'SELECT id, title FROM request WHERE id = ?', - 'request': 'UPDATE request SET matched = 1 WHERE id = ?', - }; - } - searchRequest(query, page, type) { return Promise.resolve() .then(() => tmdb.search(query, page, type)) @@ -69,36 +55,6 @@ class RequestRepository { }); } - submitRequest(movieId) { - console.log(movieId); - return Promise.resolve() - .then(() => { - pythonShell.run('moveSeasoned.py', function (err, results) { - // if (err) throw err; - // TODO Add error handling!! StrayRepository.ERROR - // results is an array consisting of messages collected during execution - console.log('results: %j', results); - }) - }) - .catch((error) => { - console.log(error); - return error; - }) - - // return this.database.get(this.queries.checkRequested, movieId).then((row) => { - // // TODO send back the name, not ID - // assert.notEqual(row, undefined, `Stray '${movieId}' already verified.`); - - // var options = { - // args: [movieId] - // } - - - - // return this.database.run(this.queries.verify, movieId); - // }) - } - } module.exports = RequestRepository; \ No newline at end of file diff --git a/src/webserver/app.js b/src/webserver/app.js index 0007e41..3da8ccb 100644 --- a/src/webserver/app.js +++ b/src/webserver/app.js @@ -34,12 +34,9 @@ router.post('/v1/seasoned/verify/:strayId', require('./controllers/seasoned/veri router.get('/v1/plex/search', require('./controllers/plex/searchMedia.js')); router.get('/v1/plex/playing', require('./controllers/plex/plexPlaying.js')); - -// router.get('/v1/plex/request/all', require('./controllers/plex/searchRequest.js')); router.get('/v1/plex/request', require('./controllers/plex/searchRequest.js')); router.get('/v1/plex/request/:mediaId', require('./controllers/plex/readRequest.js')); -router.post('/v1/plex/request/:mediaId', require('./controllers/plex/submitRequest.js')); - +// router.post('/v1/plex/request/:mediaId', require('./controllers/plex/submitRequest.js')); router.get('/v1/plex/hook', require('./controllers/plex/hookDump.js')); router.get('/v1/tmdb/search', require('./controllers/tmdb/searchMedia.js')); diff --git a/src/webserver/controllers/plex/readRequest.js b/src/webserver/controllers/plex/readRequest.js index 32f1b05..0524a2f 100644 --- a/src/webserver/controllers/plex/readRequest.js +++ b/src/webserver/controllers/plex/readRequest.js @@ -8,10 +8,9 @@ const requestRepository = new RequestRepository(); * @returns {Callback} */ function readRequestController(req, res) { - const requestId = req.params.requestId; + const mediaId = req.params.mediaId; const { type } = req.query; - - requestRepository.lookup(requestId, type) + requestRepository.lookup(mediaId, type) .then((movies) => { res.send(movies); }).catch((error) => { diff --git a/src/webserver/controllers/plex/submitRequest.js b/src/webserver/controllers/plex/submitRequest.js deleted file mode 100644 index 0a53446..0000000 --- a/src/webserver/controllers/plex/submitRequest.js +++ /dev/null @@ -1,18 +0,0 @@ -const configuration = require('src/config/configuration').getInstance(); -const RequestRepository = require('src/plex/requestRepository'); -const requestRepository = new RequestRepository(); - -function submitRequestController(req, res) { - const id = req.params.requestId; - - requestRepository.submitRequest(id) - .then(() => { - // Better sendback message. - res.send({ success: true, message: 'Request sent' }); - }) - .catch((error) => { - res.status(500).send({ success: false, error: error.message }); - }); -} - -module.exports = submitRequestController; -- 2.34.1 From a6d21ed1818662309ed3e09616ec9289265668fb Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Mon, 12 Jun 2017 20:28:58 +0200 Subject: [PATCH 11/42] Added fix_ownership for setting the new folder to user, not root. --- moveSeasoned.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/moveSeasoned.py b/moveSeasoned.py index 149c61f..caaca70 100755 --- a/moveSeasoned.py +++ b/moveSeasoned.py @@ -3,7 +3,7 @@ # @Author: KevinMidboe # @Date: 2017-04-12 23:27:51 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-04-13 16:22:23 +# @Last Modified time: 2017-06-12 20:28:03 import sys, sqlite3, json, os import env_variables as env @@ -42,6 +42,11 @@ class episode(object): return url +def fix_ownership(path): + uid = int(os.environ.get('SUDO_UID')) + gid = int(os.environ.get('SUDO_GID')) + os.chown(path, uid, gid) + def moveStray(strayId): ep = episode(strayId) @@ -54,6 +59,7 @@ def moveStray(strayId): for item in ep.trash: os.remove(ep.typeDir('parent', mergeItem=item)) + fix_ownership(ep.typeDir('parent')) os.rmdir(ep.typeDir('parent')) if __name__ == '__main__': -- 2.34.1 From 7f14f647629f49c39fb8a82b991187f5428b13bb Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Tue, 13 Jun 2017 05:11:50 +0200 Subject: [PATCH 12/42] Set gid and uid to static vars --- moveSeasoned.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/moveSeasoned.py b/moveSeasoned.py index caaca70..4f79b43 100755 --- a/moveSeasoned.py +++ b/moveSeasoned.py @@ -45,7 +45,7 @@ class episode(object): def fix_ownership(path): uid = int(os.environ.get('SUDO_UID')) gid = int(os.environ.get('SUDO_GID')) - os.chown(path, uid, gid) + os.chown(path, '1000', '1000') def moveStray(strayId): ep = episode(strayId) @@ -63,4 +63,4 @@ def moveStray(strayId): os.rmdir(ep.typeDir('parent')) if __name__ == '__main__': - moveStray(sys.argv[-1]) \ No newline at end of file + moveStray(sys.argv[-1]) -- 2.34.1 From 90384e4ebc2c0379791a4f5d1881c392bf7b9a47 Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Tue, 13 Jun 2017 05:17:40 +0200 Subject: [PATCH 13/42] Calls fix_ownership after creating new directory --- moveSeasoned.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/moveSeasoned.py b/moveSeasoned.py index 4f79b43..bbaf43b 100755 --- a/moveSeasoned.py +++ b/moveSeasoned.py @@ -37,6 +37,7 @@ class episode(object): url = '/'.join(self.queries[dType]) if create and not os.path.isdir(url): os.makedirs(url) + fix_ownership(url) if mergeItem: return '/'.join([url, str(mergeItem)]) return url @@ -45,7 +46,7 @@ class episode(object): def fix_ownership(path): uid = int(os.environ.get('SUDO_UID')) gid = int(os.environ.get('SUDO_GID')) - os.chown(path, '1000', '1000') + os.chown(path, '1000', '113') def moveStray(strayId): ep = episode(strayId) -- 2.34.1 From 5a458566991cc060c778c47100936284c342eae5 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 18 Jun 2017 21:47:15 -0600 Subject: [PATCH 14/42] Pulled variable for subtitles path out of open() and retunes subfile without analysis on typeError. --- classedStray.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/classedStray.py b/classedStray.py index 3b3fb8c..d3c846c 100755 --- a/classedStray.py +++ b/classedStray.py @@ -3,7 +3,7 @@ # @Author: KevinMidboe # @Date: 2017-04-05 18:40:11 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-06-01 19:02:04 +# @Last Modified time: 2017-06-18 21:45:42 import os.path, hashlib, time, glob, sqlite3, re, json, tweepy import logging from functools import reduce @@ -91,7 +91,11 @@ class strayEpisode(object): def analyseSubtitles(self, subFile): # TODO verify that it is a file - f = open(os.path.join([env.show_dir, self.parent, subFile]), 'r', encoding='ISO-8859-15') + try: + subtitlesPath = os.path.join([env.show_dir, self.parent, subFile]) + except TypeError: + return removeUploadSign(subFile) + f = open(subtitlesPath, 'r', encoding='ISO-8859-15') language = detect(f.read()) f.close() -- 2.34.1 From 17b89748e133b39e0d7a345b090ecb9aeab7bd9a Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 18 Jun 2017 21:48:08 -0600 Subject: [PATCH 15/42] Added todo to analyseSubtitles function --- classedStray.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/classedStray.py b/classedStray.py index d3c846c..8c829d9 100755 --- a/classedStray.py +++ b/classedStray.py @@ -3,7 +3,7 @@ # @Author: KevinMidboe # @Date: 2017-04-05 18:40:11 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-06-18 21:45:42 +# @Last Modified time: 2017-06-18 21:47:48 import os.path, hashlib, time, glob, sqlite3, re, json, tweepy import logging from functools import reduce @@ -92,8 +92,9 @@ class strayEpisode(object): def analyseSubtitles(self, subFile): # TODO verify that it is a file try: - subtitlesPath = os.path.join([env.show_dir, self.parent, subFile]) + subtitlePath = os.path.join([env.show_dir, self.parent, subFile]) except TypeError: + # TODO don't get a list in subtitlePath return removeUploadSign(subFile) f = open(subtitlesPath, 'r', encoding='ISO-8859-15') language = detect(f.read()) -- 2.34.1 From d5ea7a6bbb86fd6c520fa2a94d0c706d26c144ed Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 18 Jun 2017 21:49:58 -0600 Subject: [PATCH 16/42] Error with function call --- classedStray.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classedStray.py b/classedStray.py index 8c829d9..dc92e00 100755 --- a/classedStray.py +++ b/classedStray.py @@ -3,7 +3,7 @@ # @Author: KevinMidboe # @Date: 2017-04-05 18:40:11 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-06-18 21:47:48 +# @Last Modified time: 2017-06-18 21:49:33 import os.path, hashlib, time, glob, sqlite3, re, json, tweepy import logging from functools import reduce @@ -95,7 +95,7 @@ class strayEpisode(object): subtitlePath = os.path.join([env.show_dir, self.parent, subFile]) except TypeError: # TODO don't get a list in subtitlePath - return removeUploadSign(subFile) + return self.removeUploadSign(subFile) f = open(subtitlesPath, 'r', encoding='ISO-8859-15') language = detect(f.read()) f.close() -- 2.34.1 From 80746252c032fc238f2170e3565684793c56694b Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 27 Jun 2017 15:22:02 -0600 Subject: [PATCH 17/42] Added excepts to all move and delete, so it can be run mulitple times and see no downside to having it run and logging it if not found. Also think I fixed a bug that renamed the folder that would be deleted, not the new folder --- moveSeasoned.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/moveSeasoned.py b/moveSeasoned.py index caaca70..de71619 100755 --- a/moveSeasoned.py +++ b/moveSeasoned.py @@ -3,9 +3,10 @@ # @Author: KevinMidboe # @Date: 2017-04-12 23:27:51 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-06-12 20:28:03 +# @Last Modified time: 2017-06-27 15:15:50 import sys, sqlite3, json, os +import logging import env_variables as env class episode(object): @@ -51,16 +52,35 @@ def moveStray(strayId): ep = episode(strayId) for item in ep.video_files: - os.rename(ep.typeDir('parent', mergeItem=item[0]), ep.typeDir('episode', mergeItem=item[1], create=True)) + try: + old_dir = ep.typeDir('parent', mergeItem=item[0]) + new_dir = ep.typeDir('episode', mergeItem=item[1], create=True) + os.rename(old_dir, new_dir) + except FileNotFoundError: + logging.warning(old_dir + ' does not exits, cannot be moved.') for item in ep.subtitles: - os.rename(ep.typeDir('parent', mergeItem=item[0]), ep.typeDir('episode', mergeItem=item[1], create=True)) + try: + old_dir = ep.typeDir('parent', mergeItem=item[0]) + new_dir = ep.typeDir('episode', mergeItem=item[1], create=True) + os.rename(old_dir, new_dir) + except FileNotFoundError: + logging.warning(old_dir + ' does not exits, cannot be moved.') for item in ep.trash: - os.remove(ep.typeDir('parent', mergeItem=item)) + try: + os.remove(ep.typeDir('parent', mergeItem=item)) + except FileNotFoundError: + logging.warning(ep.typeDir('parent', mergeItem=item) + 'does not exist, cannot be removed.') - fix_ownership(ep.typeDir('parent')) + fix_ownership(ep.typeDir('episode')) os.rmdir(ep.typeDir('parent')) if __name__ == '__main__': - moveStray(sys.argv[-1]) \ No newline at end of file + if (os.path.exists(env.logfile)): + logging.basicConfig(filename=env.logfile, level=logging.INFO) + else: + print('Logfile could not be found at ' + env.logfile + '. Verifiy presence or disable logging in config.') + + moveStray(sys.argv[-1]) + -- 2.34.1 From 3bc539323a68aa48b73b9cfdfc8ef4479755a327 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 27 Jun 2017 15:24:49 -0600 Subject: [PATCH 18/42] Changed user and group id to the wanted value. --- moveSeasoned.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/moveSeasoned.py b/moveSeasoned.py index de71619..6d7e5ed 100755 --- a/moveSeasoned.py +++ b/moveSeasoned.py @@ -3,7 +3,7 @@ # @Author: KevinMidboe # @Date: 2017-04-12 23:27:51 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-06-27 15:15:50 +# @Last Modified time: 2017-06-27 15:24:10 import sys, sqlite3, json, os import logging @@ -44,8 +44,8 @@ class episode(object): def fix_ownership(path): - uid = int(os.environ.get('SUDO_UID')) - gid = int(os.environ.get('SUDO_GID')) + uid = int(os.environ.get('1000')) + gid = int(os.environ.get('105')) os.chown(path, uid, gid) def moveStray(strayId): -- 2.34.1 From 8a53cc4765b3f20b031204f4c7b5b03ca0ee812a Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 27 Jun 2017 15:25:19 -0600 Subject: [PATCH 19/42] Added todo for fix_ownership --- moveSeasoned.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/moveSeasoned.py b/moveSeasoned.py index 6d7e5ed..923cf9e 100755 --- a/moveSeasoned.py +++ b/moveSeasoned.py @@ -3,7 +3,7 @@ # @Author: KevinMidboe # @Date: 2017-04-12 23:27:51 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-06-27 15:24:10 +# @Last Modified time: 2017-06-27 15:25:04 import sys, sqlite3, json, os import logging @@ -44,6 +44,7 @@ class episode(object): def fix_ownership(path): + # TODO find this from username from config uid = int(os.environ.get('1000')) gid = int(os.environ.get('105')) os.chown(path, uid, gid) -- 2.34.1 From 4b54339b72f301515ed2b67b116b1fdf6b427e37 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 27 Jun 2017 15:30:34 -0600 Subject: [PATCH 20/42] Opps, changed to use the int value of uid and gid, not looking up the int value and then converting to int. Does not make sense. --- moveSeasoned.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/moveSeasoned.py b/moveSeasoned.py index 923cf9e..e59e12b 100755 --- a/moveSeasoned.py +++ b/moveSeasoned.py @@ -3,7 +3,7 @@ # @Author: KevinMidboe # @Date: 2017-04-12 23:27:51 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-06-27 15:25:04 +# @Last Modified time: 2017-06-27 15:29:47 import sys, sqlite3, json, os import logging @@ -45,8 +45,8 @@ class episode(object): def fix_ownership(path): # TODO find this from username from config - uid = int(os.environ.get('1000')) - gid = int(os.environ.get('105')) + uid = 1000 + gid = 105 os.chown(path, uid, gid) def moveStray(strayId): -- 2.34.1 From c1cd821d8a52379faed80c738040e1338fa0b4f1 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 27 Jun 2017 15:33:50 -0600 Subject: [PATCH 21/42] Changed group id to the wanted value. --- moveSeasoned.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/moveSeasoned.py b/moveSeasoned.py index e59e12b..995f8dc 100755 --- a/moveSeasoned.py +++ b/moveSeasoned.py @@ -3,7 +3,7 @@ # @Author: KevinMidboe # @Date: 2017-04-12 23:27:51 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-06-27 15:29:47 +# @Last Modified time: 2017-06-27 15:33:12 import sys, sqlite3, json, os import logging @@ -46,7 +46,7 @@ class episode(object): def fix_ownership(path): # TODO find this from username from config uid = 1000 - gid = 105 + gid = 113 os.chown(path, uid, gid) def moveStray(strayId): -- 2.34.1 From 979a95a468c829886fe60751586ad92aa09d4584 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 27 Jun 2017 15:37:55 -0600 Subject: [PATCH 22/42] Added a try except to remove and a todo to remind of need improvements. --- moveSeasoned.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/moveSeasoned.py b/moveSeasoned.py index 995f8dc..c3995a8 100755 --- a/moveSeasoned.py +++ b/moveSeasoned.py @@ -3,7 +3,7 @@ # @Author: KevinMidboe # @Date: 2017-04-12 23:27:51 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-06-27 15:33:12 +# @Last Modified time: 2017-06-27 15:37:26 import sys, sqlite3, json, os import logging @@ -75,7 +75,14 @@ def moveStray(strayId): logging.warning(ep.typeDir('parent', mergeItem=item) + 'does not exist, cannot be removed.') fix_ownership(ep.typeDir('episode')) - os.rmdir(ep.typeDir('parent')) + + + # TODO because we might jump over same files, the dir might no longer + # be empty and cannot remove dir like this. + try: + os.rmdir(ep.typeDir('parent')) + except FileNotFoundError: + logging.warning('Cannot remove ' + ep.typeDir('parent') + ', file no longer exists.') if __name__ == '__main__': if (os.path.exists(env.logfile)): -- 2.34.1 From 7023b135b4f1c76414ca9bdb6456ef4dc5d12ef9 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 27 Jun 2017 15:48:25 -0600 Subject: [PATCH 23/42] Now all subfiles also have their permission chagned. --- moveSeasoned.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/moveSeasoned.py b/moveSeasoned.py index c3995a8..27f9386 100755 --- a/moveSeasoned.py +++ b/moveSeasoned.py @@ -3,7 +3,7 @@ # @Author: KevinMidboe # @Date: 2017-04-12 23:27:51 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-06-27 15:37:26 +# @Last Modified time: 2017-06-27 15:48:00 import sys, sqlite3, json, os import logging @@ -75,6 +75,8 @@ def moveStray(strayId): logging.warning(ep.typeDir('parent', mergeItem=item) + 'does not exist, cannot be removed.') fix_ownership(ep.typeDir('episode')) + for item in ep.typeDir('episode'): + fix_ownership(item) # TODO because we might jump over same files, the dir might no longer -- 2.34.1 From 7cda4accdb0d19b9010a29fdb99ae473d1aa97f2 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 27 Jun 2017 15:49:34 -0600 Subject: [PATCH 24/42] Added print for debugging purposes --- moveSeasoned.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/moveSeasoned.py b/moveSeasoned.py index 27f9386..1e6f203 100755 --- a/moveSeasoned.py +++ b/moveSeasoned.py @@ -3,7 +3,7 @@ # @Author: KevinMidboe # @Date: 2017-04-12 23:27:51 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-06-27 15:48:00 +# @Last Modified time: 2017-06-27 15:49:19 import sys, sqlite3, json, os import logging @@ -76,6 +76,7 @@ def moveStray(strayId): fix_ownership(ep.typeDir('episode')) for item in ep.typeDir('episode'): + print(item) fix_ownership(item) -- 2.34.1 From 31e16e2784b58b893996f36d30729ef73a134429 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 27 Jun 2017 15:52:17 -0600 Subject: [PATCH 25/42] Now the for loop actually goes through dir not just the string of file name. *facepalm* --- moveSeasoned.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/moveSeasoned.py b/moveSeasoned.py index 1e6f203..f9556ab 100755 --- a/moveSeasoned.py +++ b/moveSeasoned.py @@ -3,7 +3,7 @@ # @Author: KevinMidboe # @Date: 2017-04-12 23:27:51 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-06-27 15:49:19 +# @Last Modified time: 2017-06-27 15:51:21 import sys, sqlite3, json, os import logging @@ -75,9 +75,9 @@ def moveStray(strayId): logging.warning(ep.typeDir('parent', mergeItem=item) + 'does not exist, cannot be removed.') fix_ownership(ep.typeDir('episode')) - for item in ep.typeDir('episode'): - print(item) - fix_ownership(item) + for root, dirs, files in os.walk(ep.typeDir('episode')): + print(files) + fix_ownership(files) # TODO because we might jump over same files, the dir might no longer -- 2.34.1 From 34ab8be0979c4d20b55aed020cb160d7ec150dad Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 27 Jun 2017 15:53:52 -0600 Subject: [PATCH 26/42] Fix_ownership got a list of files, now it iterates through this list and sends each item to the function --- moveSeasoned.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/moveSeasoned.py b/moveSeasoned.py index f9556ab..da2eeaf 100755 --- a/moveSeasoned.py +++ b/moveSeasoned.py @@ -3,7 +3,7 @@ # @Author: KevinMidboe # @Date: 2017-04-12 23:27:51 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-06-27 15:51:21 +# @Last Modified time: 2017-06-27 15:53:17 import sys, sqlite3, json, os import logging @@ -77,7 +77,8 @@ def moveStray(strayId): fix_ownership(ep.typeDir('episode')) for root, dirs, files in os.walk(ep.typeDir('episode')): print(files) - fix_ownership(files) + for item in files: + fix_ownership(item) # TODO because we might jump over same files, the dir might no longer -- 2.34.1 From 04066b8da43faa4d189b9314d99cfd45a34d0bce Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 27 Jun 2017 15:56:06 -0600 Subject: [PATCH 27/42] Now the full path is sent to fix ownership, not just the file path --- moveSeasoned.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/moveSeasoned.py b/moveSeasoned.py index da2eeaf..3b28d33 100755 --- a/moveSeasoned.py +++ b/moveSeasoned.py @@ -3,7 +3,7 @@ # @Author: KevinMidboe # @Date: 2017-04-12 23:27:51 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-06-27 15:53:17 +# @Last Modified time: 2017-06-27 15:55:41 import sys, sqlite3, json, os import logging @@ -76,9 +76,8 @@ def moveStray(strayId): fix_ownership(ep.typeDir('episode')) for root, dirs, files in os.walk(ep.typeDir('episode')): - print(files) for item in files: - fix_ownership(item) + fix_ownership(os.path.join([ep.typeDir('episode'), item]) # TODO because we might jump over same files, the dir might no longer -- 2.34.1 From f884406c069a6fed19b91795163c256319b09e91 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 27 Jun 2017 15:56:47 -0600 Subject: [PATCH 28/42] Missed a syntax errro --- moveSeasoned.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/moveSeasoned.py b/moveSeasoned.py index 3b28d33..af6eafe 100755 --- a/moveSeasoned.py +++ b/moveSeasoned.py @@ -3,7 +3,7 @@ # @Author: KevinMidboe # @Date: 2017-04-12 23:27:51 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-06-27 15:55:41 +# @Last Modified time: 2017-06-27 15:56:33 import sys, sqlite3, json, os import logging @@ -77,7 +77,7 @@ def moveStray(strayId): fix_ownership(ep.typeDir('episode')) for root, dirs, files in os.walk(ep.typeDir('episode')): for item in files: - fix_ownership(os.path.join([ep.typeDir('episode'), item]) + fix_ownership(os.path.join([ep.typeDir('episode'), item])) # TODO because we might jump over same files, the dir might no longer -- 2.34.1 From be839ba2dd90dac54a787aefb224e27a0d57c42c Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 27 Jun 2017 15:58:40 -0600 Subject: [PATCH 29/42] Trying to fix bug with os.join, now has a two args, not list --- moveSeasoned.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/moveSeasoned.py b/moveSeasoned.py index af6eafe..bb002ee 100755 --- a/moveSeasoned.py +++ b/moveSeasoned.py @@ -3,9 +3,9 @@ # @Author: KevinMidboe # @Date: 2017-04-12 23:27:51 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-06-27 15:56:33 +# @Last Modified time: 2017-06-27 15:58:09 -import sys, sqlite3, json, os +import sys, sqlite3, json, os.path import logging import env_variables as env @@ -77,7 +77,7 @@ def moveStray(strayId): fix_ownership(ep.typeDir('episode')) for root, dirs, files in os.walk(ep.typeDir('episode')): for item in files: - fix_ownership(os.path.join([ep.typeDir('episode'), item])) + fix_ownership(os.path.join(ep.typeDir('episode'), item)) # TODO because we might jump over same files, the dir might no longer -- 2.34.1 From b358c61efb020540b1a877d8a8b86f8058aa7bde Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sat, 1 Jul 2017 08:29:49 +0200 Subject: [PATCH 30/42] Had a bug that when searched and empty return it tried to map the empty array. Now we check for the contents of the response before we map the items. --- client/app/components/SearchRequest.jsx | 58 +++++++++++++++++++------ 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/client/app/components/SearchRequest.jsx b/client/app/components/SearchRequest.jsx index c6da4be..13a5c56 100644 --- a/client/app/components/SearchRequest.jsx +++ b/client/app/components/SearchRequest.jsx @@ -13,12 +13,13 @@ class SearchRequest extends React.Component { componentDidMount(){ var that = this; - fetch("https://apollo.kevinmidboe.com/api/v1/plex/request?query=interstellar") - .then(response => response.json()) - .then(data => this.setState({ - items: data - }) - ).catch(err => console.error('Error load: ', err.toString())); + this.setState({items: []}) + // fetch("https://apollo.kevinmidboe.com/api/v1/plex/request?query=interstellar") + // .then(response => response.json()) + // .then(data => this.setState({ + // items: data + // }) + // ).catch(err => console.error('Error load: ', err.toString())); } _handleKeyPress(e) { @@ -27,15 +28,32 @@ class SearchRequest extends React.Component { } } + handleErrors(response) { + if (!response.ok) { + throw Error(response.statusText); + } + return response; + } + fetchQuery() { var query = 'https://apollo.kevinmidboe.com/api/v1/plex/request?query=' + this.state.searchQuery; fetch(query) - .then(response => response.json()) - .then(data => this.setState({ - items: data - }) - ).catch(err => console.error('Error submit: ', err.toString())); + // Check if the response is ok + .then(response => this.handleErrors(response)) + .then(response => response.json()) // Convert to json object and pass to next then + .then(data => { // Parse the data of the JSON response + if (data.length > 0) { + this.setState({ + items: data + }) + } else { + this.setState({ + items: null + }) + } + }) + .catch(error => console.log('Error submit: ', error.toString())); } printMovies(item) { @@ -52,13 +70,27 @@ class SearchRequest extends React.Component { }); } + mapResponseToMovies() { + // Here we have some movie response items in our state + if (this.state.items) { + console.log('something') + } + // And here we are going to print a 404 message because the response was empty + else { + console.log('nothing') + } + for (var i = this.state.items.length - 1; i >= 0; i--) { + this.printMovies(this.state.items[i]) + } + } + render(){ return(
this._handleKeyPress(event)} - onChange={(event) => this.handleChange(event)} + onChange={event => this.handleChange(event)} value={this.state.searchQuery} /> @@ -67,7 +99,7 @@ class SearchRequest extends React.Component { {this.state.searchQuery}

- {this.state.items.map((item) => this.printMovies(item))} + {this.mapResponseToMovies()}
) } -- 2.34.1 From ba3a1fa028a94c322ad2a90caa8d5dd9708d49db Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sat, 1 Jul 2017 08:37:29 +0200 Subject: [PATCH 31/42] If search request returns empty array from tmdb, then send a 404 reponse with error message back to client. --- src/webserver/controllers/tmdb/searchMedia.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/webserver/controllers/tmdb/searchMedia.js b/src/webserver/controllers/tmdb/searchMedia.js index 4e80017..f09b859 100644 --- a/src/webserver/controllers/tmdb/searchMedia.js +++ b/src/webserver/controllers/tmdb/searchMedia.js @@ -14,6 +14,11 @@ function searchMoviesController(req, res) { Promise.resolve() .then(() => tmdb.search(query, page, type)) .then((movies) => { + if (movies.length > 0) { + res.send(movies); + } else { + res.status(404).send({ success: false, error: 'Search query did not return any results.'}) + } res.send(movies); }) .catch((error) => { -- 2.34.1 From 1663f5931dcf4edc02c6e4634db7c1ca9059ff02 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sat, 1 Jul 2017 08:46:37 +0200 Subject: [PATCH 32/42] Verify that respond has content, if so send the content back. If no content was found, send 404 status and error message --- src/webserver/controllers/plex/searchRequest.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/webserver/controllers/plex/searchRequest.js b/src/webserver/controllers/plex/searchRequest.js index 9e93d82..5fde129 100644 --- a/src/webserver/controllers/plex/searchRequest.js +++ b/src/webserver/controllers/plex/searchRequest.js @@ -7,7 +7,14 @@ function searchRequestController(req, res) { requestRepository.searchRequest(query, page, type) .then((movies) => { - res.send(movies); + // Verify that respond has content, if so send the content back + if (movies.length > 0 && movies != null) { + res.send(movies); + } + // If no content was found, send 404 status and error message + else { + res.status(404).send({success: false, error: 'Search query did not return any results.'}) + } }) .catch((error) => { res.status(500).send({success: false, error: error.message }); -- 2.34.1 From 29e575cbf108ed4bacabfbd41db55710d3f7c189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Midb=C3=B8e?= Date: Wed, 12 Jul 2017 00:11:05 +0200 Subject: [PATCH 33/42] Start of fire script to move bulk files to wanted dir, while creating the respected folder names. --- seasonMover.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 seasonMover.py diff --git a/seasonMover.py b/seasonMover.py new file mode 100755 index 0000000..9205ff1 --- /dev/null +++ b/seasonMover.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# @Author: KevinMidboe +# @Date: 2017-07-11 19:16:23 +# @Last Modified by: KevinMidboe +# @Last Modified time: 2017-07-11 19:16:23 + +import fire, re, os + +class seasonMover(object): + ''' Moving multiple files to multiple folders with + identifer ''' + workingDir = os.getcwd() + + def create(self, name, interval): + pass + + def move(self, fileSyntax, folderName): + episodeRange = self.findInterval(fileSyntax) + + self.motherMover(fileSyntax, folderName, episodeRange) + + def findInterval(self, item): + if (re.search(r'\((.*)\)', item) is None): + raise ValueError('Need to declare an identifier e.g. (1..3) in: \n\t' + item) + + start = int(re.search('\((\d+)\.\.', item).group(1)) + end = int(re.search('\.\.(\d+)\)', item).group(1)) + + return list(range(start, end+1)) + + def removeUploadSign(self, file): + match = re.search('-[a-zA-Z\[\]\-]*.[a-z]{3}', file) + if match: + uploader = match.group(0)[:-4] + return re.sub(uploader, '', file) + + return file + + def motherMover(self, fileSyntax, folderName, episodeRange): + # Call for sub of fileList + # TODO check if range is same as folderContent + for episode in episodeRange: + leadingZeroNumber = "%02d" % episode + fileName = re.sub(r'\((.*)\)', leadingZeroNumber, fileSyntax) + + oldPath = os.path.join(self.workingDir,fileName) + newFolder = os.path.join(self.workingDir, folderName + leadingZeroNumber) + newPath = os.path.join(newFolder, self.removeUploadSign(fileName)) + + os.makedirs(newFolder) + os.rename(oldPath, newPath) + # print(newFolder) + # print(oldPath + ' --> ' + newPath) + +if __name__ == '__main__': + fire.Fire(seasonMover) \ No newline at end of file -- 2.34.1 From c97ab972ef337b91b2e9cb3831d9e3b2a3151b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Midb=C3=B8e?= Date: Sun, 16 Jul 2017 10:51:02 +0200 Subject: [PATCH 34/42] Changed movieObject ot pass full object, not just it's id when clicked --- client/app/components/MovieObject.jsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/app/components/MovieObject.jsx b/client/app/components/MovieObject.jsx index 4f3e8ea..51a98d4 100644 --- a/client/app/components/MovieObject.jsx +++ b/client/app/components/MovieObject.jsx @@ -11,8 +11,8 @@ class MovieObject { this.overview = object.overview; } - requestExisting(id) { - console.log('Exists', id) + requestExisting(movie) { + console.log('Exists', movie) } requestMovie(id) { @@ -33,9 +33,9 @@ class MovieObject { returnList.push(); if (this.matchedInPlex) { - returnList.push() + returnList.push() } else { - returnList.push() + returnList.push() } returnList.push({this.overview}); -- 2.34.1 From 97dea47a7a2d0939e4a9e6db560328be41f52f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Midb=C3=B8e?= Date: Sun, 16 Jul 2017 10:54:44 +0200 Subject: [PATCH 35/42] Updated inherits in yarn config file --- client/yarn.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/yarn.lock b/client/yarn.lock index 0c88685..bddfae4 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -1757,11 +1757,11 @@ inflight@^1.0.4: once "^1.3.0" wrappy "1" -inherits@2, inherits@2.0.3, inherits@~2.0.0, inherits@~2.0.1: +inherits@2, inherits@2.0.3, inherits@~2.0.0: version "2.0.3" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" -inherits@2.0.1, inherits@^2.0.1: +inherits@2.0.1, inherits@^2.0.1, inherits@~2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1" -- 2.34.1 From 2c97803d82bf082e2847f766c505ee4fe080def7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Midb=C3=B8e?= Date: Sun, 16 Jul 2017 11:03:30 +0200 Subject: [PATCH 36/42] Added a sendRequest function for handliing the post of a movie request --- src/plex/requestRepository.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/plex/requestRepository.js b/src/plex/requestRepository.js index 0cc27dd..a4f1872 100644 --- a/src/plex/requestRepository.js +++ b/src/plex/requestRepository.js @@ -8,6 +8,8 @@ const tmdb = new TMDB(configuration.get('tmdb', 'apiKey')); var Promise = require('bluebird'); var rp = require('request-promise'); +var pythonShell = require('python-shell'); + class RequestRepository { searchRequest(query, page, type) { @@ -55,6 +57,30 @@ class RequestRepository { }); } + sendRequest(identifier) { + // TODO try a cache hit on the movie item + + console.log(identifier) + tmdb.lookup(identifier).then(movie => { + console.log(movie.title) + + var options = { + args: [movie.title, movie.year, movie.poster] + } + + pythonShell.run('sendRequest.py', options, function (err, results) { + if (err) throw err; + // TODO Add error handling!! RequestRepository.ERROR + // results is an array consisting of messages collected during execution + + console.log('results: %j', results) + }) + return true; + }) + + + } + } module.exports = RequestRepository; \ No newline at end of file -- 2.34.1 From 3047dce1475f0db678550150395ab9f7ca402bd4 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 16 Jul 2017 11:04:56 +0200 Subject: [PATCH 37/42] Opened the POST endpoint for requesting a movie in the server --- src/webserver/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webserver/app.js b/src/webserver/app.js index 1b0fc39..1867154 100644 --- a/src/webserver/app.js +++ b/src/webserver/app.js @@ -32,7 +32,7 @@ router.get('/v1/plex/search', require('./controllers/plex/searchMedia.js')); router.get('/v1/plex/playing', require('./controllers/plex/plexPlaying.js')); router.get('/v1/plex/request', require('./controllers/plex/searchRequest.js')); router.get('/v1/plex/request/:mediaId', require('./controllers/plex/readRequest.js')); -// router.post('/v1/plex/request/:mediaId', require('./controllers/plex/submitRequest.js')); +router.post('/v1/plex/request/:mediaId', require('./controllers/plex/submitRequest.js')); router.get('/v1/plex/hook', require('./controllers/plex/hookDump.js')); router.get('/v1/tmdb/search', require('./controllers/tmdb/searchMedia.js')); -- 2.34.1 From 91606fc9b888137fcf4fea373fee3174560754ab Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 16 Jul 2017 11:05:30 +0200 Subject: [PATCH 38/42] Removed unused import --- src/webserver/controllers/seasoned/verifyStray.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/webserver/controllers/seasoned/verifyStray.js b/src/webserver/controllers/seasoned/verifyStray.js index ca9977d..a0e5178 100644 --- a/src/webserver/controllers/seasoned/verifyStray.js +++ b/src/webserver/controllers/seasoned/verifyStray.js @@ -1,4 +1,3 @@ -const configuration = require('src/config/configuration').getInstance(); const StrayRepository = require('src/seasoned/strayRepository'); const strayRepository = new StrayRepository(); -- 2.34.1 From c45df8a131c82f003a012f115a970969c5140417 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 16 Jul 2017 11:08:14 +0200 Subject: [PATCH 39/42] Added controller for calling POST request function for media items. --- .../controllers/plex/submitRequest.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/webserver/controllers/plex/submitRequest.js diff --git a/src/webserver/controllers/plex/submitRequest.js b/src/webserver/controllers/plex/submitRequest.js new file mode 100644 index 0000000..80e1355 --- /dev/null +++ b/src/webserver/controllers/plex/submitRequest.js @@ -0,0 +1,24 @@ +const RequestRepository = require('src/plex/requestRepository.js'); +const requestRepository = new RequestRepository(); + +/** + * Controller: POST a media id to be donwloaded + * @param {Request} req http request variable + * @param {Response} res + * @returns {Callback} + */ + +function submitRequestController(req, res) { + // This is the id that is the param of the url + const id = req.params.mediaId; + + requestRepository.sendRequest(id) + .then(() => { + res.send({ success: true, message: 'Media item sucessfully requested!' }); + }) + .catch((error) => { + res.status(500).send({ success: false, error: error.message }); + }); +} + +module.exports = submitRequestController; \ No newline at end of file -- 2.34.1 From b34e23077bdd0b7eace8cd632aa0e069a806102b Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 16 Jul 2017 11:08:36 +0200 Subject: [PATCH 40/42] Updated gitignore with dist folder --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 23b7eaf..46158bf 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ node_modules *.pyc npm-debug.log webpage/js/env_variables.js +client/dist +src/webserver/access.log -- 2.34.1 From 90546755cced40360579e130b4661feaa4b132b8 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 16 Jul 2017 11:11:43 +0200 Subject: [PATCH 41/42] Rewrote much of the fetching of media items for the rendered request page. --- client/app/components/SearchRequest.jsx | 97 ++++++++++++------------- 1 file changed, 46 insertions(+), 51 deletions(-) diff --git a/client/app/components/SearchRequest.jsx b/client/app/components/SearchRequest.jsx index 13a5c56..0b313a0 100644 --- a/client/app/components/SearchRequest.jsx +++ b/client/app/components/SearchRequest.jsx @@ -5,101 +5,96 @@ import MovieObject from './MovieObject.jsx'; class SearchRequest extends React.Component { constructor(props){ super(props) + // Constructor with states holding the search query and the element of reponse. this.state = { searchQuery: '', - items: [] + responseMovieList: null + } + + this.URLs = { + request: 'https://apollo.kevinmidboe.com/api/v1/plex/request?query=', + sendRequest: 'https://apollo.kevinmidboe.com/api/v1/plex/request?query=' } } componentDidMount(){ var that = this; - this.setState({items: []}) - // fetch("https://apollo.kevinmidboe.com/api/v1/plex/request?query=interstellar") - // .then(response => response.json()) - // .then(data => this.setState({ - // items: data - // }) - // ).catch(err => console.error('Error load: ', err.toString())); + this.setState({responseMovieList: null}) } - - _handleKeyPress(e) { - if (e.key === 'Enter') { - this.fetchQuery(); - } - } - + + // Handles all errors of the response of a fetch call handleErrors(response) { if (!response.ok) { - throw Error(response.statusText); + throw Error(response.status); } return response; } fetchQuery() { - var query = 'https://apollo.kevinmidboe.com/api/v1/plex/request?query=' + this.state.searchQuery; + let url = this.URLs.request + this.state.searchQuery - fetch(query) + fetch(url) // Check if the response is ok .then(response => this.handleErrors(response)) .then(response => response.json()) // Convert to json object and pass to next then .then(data => { // Parse the data of the JSON response + // If it is something here it updates the state variable with the HTML list of all + // movie objects that where returned by the search request if (data.length > 0) { - this.setState({ - items: data + this.setState({ + responseMovieList: data.map(item => this.createMovieObjects(item)) }) - } else { - this.setState({ - items: null - }) } }) - .catch(error => console.log('Error submit: ', error.toString())); + // If the -------- + .catch(error => { + console.log(error) + this.setState({ + responseMovieList:

Not Found

+ }) + + console.log('Error submit: ', error.toString()); + }); } - printMovies(item) { - if (item != undefined) { - let a = new MovieObject(item); - return a.getElement(); - } - } - - - handleChange(event){ + // Updates the internal state of the query search field. + updateQueryState(event){ this.setState({ searchQuery: event.target.value }); } - mapResponseToMovies() { - // Here we have some movie response items in our state - if (this.state.items) { - console.log('something') - } - // And here we are going to print a 404 message because the response was empty - else { - console.log('nothing') - } - for (var i = this.state.items.length - 1; i >= 0; i--) { - this.printMovies(this.state.items[i]) - } + // For checking if the enter key was pressed in the search field. + _handleQueryKeyPress(e) { + if (e.key === 'Enter') { + this.fetchQuery(); + } } + // When called passes the variable to MovieObject and calls it's interal function for + // generating the wanted HTML + createMovieObjects(item) { + let movie = new MovieObject(item); + return movie.getElement(); + } + + render(){ return(
this._handleKeyPress(event)} - onChange={event => this.handleChange(event)} + onKeyPress={(event) => this._handleQueryKeyPress(event)} + onChange={event => this.updateQueryState(event)} value={this.state.searchQuery} />

- {this.state.searchQuery}

- - {this.mapResponseToMovies()} + + {this.state.responseMovieList} +
) } -- 2.34.1 From f2cc05307bf70a8bb2f8c7f28211a93ca1eb949c Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 16 Jul 2017 11:18:14 +0200 Subject: [PATCH 42/42] Added TODO --- client/app/components/SearchRequest.jsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/app/components/SearchRequest.jsx b/client/app/components/SearchRequest.jsx index 0b313a0..1e30183 100644 --- a/client/app/components/SearchRequest.jsx +++ b/client/app/components/SearchRequest.jsx @@ -2,6 +2,8 @@ import React from 'react'; import MovieObject from './MovieObject.jsx'; +// TODO add option for searching multi, movies or tv shows + class SearchRequest extends React.Component { constructor(props){ super(props) -- 2.34.1