Now makes a async call for python script and returns the ouput of the script when finished as a json object.

This commit is contained in:
2017-10-21 12:27:39 +02:00
parent 67d343e446
commit 67f5cef718

View File

@@ -1,34 +1,26 @@
const assert = require('assert'); const assert = require('assert');
var PythonShell = require('python-shell');
var async = require('async');
class PirateRepository { async function find(searchterm, callback) {
var PythonShell = require('python-shell');
search(query) { var options = {
console.log(query) // pythonPath: '/usr/bin/python3',
pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3',
args: [searchterm]
} }
searchMedia(query) { PythonShell.run('../app/pirateSearch.py', options, callback);
var options = { // PythonShell does not support return
uri: 'http://10.0.0.41:32400/search?query=' + query, };
headers: {
'Accept': 'application/json'
},
json: true
}
return rp(options) async function SearchPiratebay(query) {
.then((result) => { return await new Promise((resolve) => {
var seasonedMediaObjects = result.MediaContainer.Metadata.reduce(function(match, media_item) { return find(query, function(err, results) {
if (media_item.type === 'movie' || media_item.type === 'show') { resolve(JSON.parse(results, null, '\t'));
match.push(convertPlexToSeasoned(media_item)); })
} })
return match;
}, []);
return seasonedMediaObjects;
})
.catch((err) => {
throw new Error(err);
})
}
} }
module.exports = PirateRepository; module.exports = { SearchPiratebay }