Jackett sometimes returns a link to self that redirects to a magnet. The response is now parsed for if it is a link and gets the url it redirects to.
This commit is contained in:
@@ -1,11 +1,27 @@
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const http = require('http');
|
||||||
|
const { URL } = require('url');
|
||||||
const PythonShell = require('python-shell');
|
const PythonShell = require('python-shell');
|
||||||
|
|
||||||
|
function getMagnetFromURL(url) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const options = new URL(url);
|
||||||
|
if (options.protocol.includes('magnet'))
|
||||||
|
resolve(url)
|
||||||
|
|
||||||
|
http.get(options, (res) => {
|
||||||
|
if (res.statusCode == 301) {
|
||||||
|
resolve(res.headers.location)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function find(searchterm, callback) {
|
async function find(searchterm, callback) {
|
||||||
const options = {
|
const options = {
|
||||||
pythonPath: '/usr/bin/python3',
|
pythonPath: '/usr/bin/python3',
|
||||||
// pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3',
|
// pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3',
|
||||||
args: [searchterm, '-s', 'piratebay', '--print'],
|
args: [searchterm, '-s', 'jackett', '--print'],
|
||||||
};
|
};
|
||||||
|
|
||||||
PythonShell.run('../app/torrent_search/torrentSearch/search.py', options, callback);
|
PythonShell.run('../app/torrent_search/torrentSearch/search.py', options, callback);
|
||||||
@@ -13,7 +29,9 @@ async function find(searchterm, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function callPythonAddMagnet(magnet, callback) {
|
async function callPythonAddMagnet(url, callback) {
|
||||||
|
getMagnetFromURL(url)
|
||||||
|
.then((magnet) => {
|
||||||
const options = {
|
const options = {
|
||||||
pythonPath: '/usr/bin/python',
|
pythonPath: '/usr/bin/python',
|
||||||
// pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3',
|
// pythonPath: '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3',
|
||||||
@@ -21,13 +39,18 @@ async function callPythonAddMagnet(magnet, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PythonShell.run('../app/magnet.py', options, callback);
|
PythonShell.run('../app/magnet.py', options, callback);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
throw new Error(err);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function SearchPiratebay(query) {
|
async function SearchPiratebay(query) {
|
||||||
return await new Promise((resolve, reject) => find(query, (err, results) => {
|
return await new Promise((resolve, reject) => find(query, (err, results) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
console.log('THERE WAS A FUCKING ERROR!');
|
console.log('THERE WAS A FUCKING ERROR!', err);
|
||||||
reject(Error('There was a error when searching for torrents'));
|
reject(Error('There was a error when searching for torrents'));
|
||||||
}
|
}
|
||||||
if (results) {
|
if (results) {
|
||||||
@@ -39,13 +62,14 @@ async function SearchPiratebay(query) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function AddMagnet(magnet) {
|
async function AddMagnet(magnet) {
|
||||||
return await new Promise(resolve => callPythonAddMagnet(magnet, (err, results) => {
|
return await new Promise((resolve, reject) => callPythonAddMagnet(magnet, (err, results) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
reject(Error('Enable to add torrent', err))
|
||||||
}
|
}
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
console.log(results);
|
console.log('result/error:', err, results);
|
||||||
resolve({ success: true });
|
resolve({ success: true });
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user