From 74c6ed02a8dd57e85f6d4040c82e7c6651b90217 Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Fri, 2 Jun 2017 08:52:54 +0200 Subject: [PATCH 01/22] 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 0022f656bdd812ca0ed1ec0ccbf7d62ceb90aab5 Mon Sep 17 00:00:00 2001 From: Kevin Date: Sun, 4 Jun 2017 00:16:16 +0200 Subject: [PATCH 02/22] 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 03/22] 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 04/22] 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 05/22] 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 06/22] 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 07/22] 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 08/22] 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 09/22] 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 10/22] 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 11/22] 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 12/22] 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 13/22] 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 14/22] 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 15/22] 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 16/22] 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 17/22] 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 18/22] 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 19/22] 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 20/22] 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 21/22] 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 1663f5931dcf4edc02c6e4634db7c1ca9059ff02 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sat, 1 Jul 2017 08:46:37 +0200 Subject: [PATCH 22/22] 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