[addon] include trackers when downloading to debrid

This commit is contained in:
TheBeastLT
2020-12-24 17:32:15 +01:00
parent f8fe581313
commit c733d7e266
6 changed files with 37 additions and 9 deletions

View File

@@ -1,6 +1,9 @@
const needle = require('needle');
const magnet = require('magnet-uri');
const { getRandomProxy, getProxyAgent, getRandomUserAgent } = require('../lib/requestHelper');
const { cacheWrapProxy } = require('../lib/cache');
const { getTorrent } = require('../lib/repository');
const { Type } = require('../lib/types');
const TRACKERS_URL = 'https://ngosang.github.io/trackerslist/trackers_best.txt';
const ANIME_TRACKERS = [
@@ -18,6 +21,17 @@ function getAllTrackers() {
return ALL_TRACKERS;
}
async function getMagnetLink(infoHash) {
const torrent = getTorrent(infoHash).catch(() => ({ infoHash }));
const torrentTrackers = torrent.trackers && torrent.trackers.split(',');
const animeTrackers = torrent.type === Type.ANIME ? ALL_TRACKERS : undefined;
const trackers = torrentTrackers || animeTrackers;
return trackers
? magnet.encode({ infoHash: infoHash, announce: trackers })
: magnet.encode({ infoHash: infoHash });
}
async function initBestTrackers() {
const userAgent = getRandomUserAgent();
const proxy = await cacheWrapProxy('moch', () => getRandomProxy()).catch(() => getRandomProxy());
@@ -34,4 +48,4 @@ async function initBestTrackers() {
ALL_TRACKERS = BEST_TRACKERS.concat(ANIME_TRACKERS);
}
module.exports = { initBestTrackers, getAllTrackers };
module.exports = { initBestTrackers, getAllTrackers, getMagnetLink };

View File

@@ -44,6 +44,10 @@ const File = database.define('file',
Torrent.hasMany(File, { foreignKey: 'infoHash', constraints: false });
File.belongsTo(Torrent, { foreignKey: 'infoHash', constraints: false });
function getTorrent(infoHash) {
return Torrent.findOne({ where: { infoHash: infoHash } });
}
function getImdbIdMovieEntries(imdbId) {
return File.findAll({
where: {
@@ -87,4 +91,10 @@ function getKitsuIdSeriesEntries(kitsuId, episode) {
});
}
module.exports = { getImdbIdMovieEntries, getImdbIdSeriesEntries, getKitsuIdMovieEntries, getKitsuIdSeriesEntries };
module.exports = {
getTorrent,
getImdbIdMovieEntries,
getImdbIdSeriesEntries,
getKitsuIdMovieEntries,
getKitsuIdSeriesEntries
};