mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[addon] include trackers when downloading to debrid
This commit is contained in:
@@ -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 };
|
||||
@@ -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
|
||||
};
|
||||
Reference in New Issue
Block a user