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
|
||||
};
|
||||
@@ -4,6 +4,7 @@ const { isVideo, isArchive } = require('../lib/extension');
|
||||
const StaticResponse = require('./static');
|
||||
const { getRandomProxy, getProxyAgent, getRandomUserAgent } = require('../lib/requestHelper');
|
||||
const { cacheWrapProxy, cacheUserAgent } = require('../lib/cache');
|
||||
const { getMagnetLink } = require('../lib/magnetHelper');
|
||||
|
||||
const KEY = 'alldebrid';
|
||||
|
||||
@@ -122,7 +123,8 @@ async function _findTorrent(AD, infoHash) {
|
||||
}
|
||||
|
||||
async function _createTorrent(AD, infoHash) {
|
||||
const uploadResponse = await AD.magnet.upload(infoHash);
|
||||
const magnetLink = await getMagnetLink(infoHash);
|
||||
const uploadResponse = await AD.magnet.upload(magnetLink);
|
||||
const torrentId = uploadResponse.data.magnets[0].id;
|
||||
return AD.magnet.status(torrentId).then(statusResponse => statusResponse.data.magnets);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
const PremiumizeClient = require('premiumize-api');
|
||||
const { encode } = require('magnet-uri');
|
||||
const { isVideo } = require('../lib/extension');
|
||||
const StaticResponse = require('./static');
|
||||
const { getRandomProxy, getProxyAgent, getRandomUserAgent } = require('../lib/requestHelper');
|
||||
const { cacheWrapProxy, cacheUserAgent } = require('../lib/cache');
|
||||
const { getMagnetLink } = require('../lib/magnetHelper');
|
||||
|
||||
async function getCachedStreams(streams, apiKey) {
|
||||
const options = await getDefaultOptions(apiKey);
|
||||
@@ -82,7 +82,8 @@ async function _findTorrent(PM, infoHash) {
|
||||
}
|
||||
|
||||
async function _createTorrent(PM, infoHash) {
|
||||
return PM.transfer.create(encode({ infoHash })).then(() => _findTorrent(PM, infoHash));
|
||||
const magnetLink = await getMagnetLink(infoHash);
|
||||
return PM.transfer.create(magnetLink).then(() => _findTorrent(PM, infoHash));
|
||||
}
|
||||
|
||||
async function _retryCreateTorrent(PM, infoHash, encodedFileName, fileIndex) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const PutioAPI = require('@putdotio/api-client').default
|
||||
const { encode } = require('magnet-uri');
|
||||
const { isVideo } = require('../lib/extension');
|
||||
const delay = require('./delay');
|
||||
const StaticResponse = require('./static');
|
||||
const { getMagnetLink } = require('../lib/magnetHelper');
|
||||
|
||||
async function getCachedStreams(streams, apiKey) {
|
||||
return streams
|
||||
@@ -64,7 +64,7 @@ async function _findTorrent(Putio, infoHash) {
|
||||
}
|
||||
|
||||
async function _createTorrent(Putio, infoHash) {
|
||||
const magnetLink = encode({ infoHash });
|
||||
const magnetLink = await getMagnetLink(infoHash);
|
||||
// Add the torrent and then delay for 3 secs for putio to process it and then check it's status.
|
||||
return Putio.Transfers.Add({ url: magnetLink })
|
||||
.then(response => _getNewTorrent(Putio, response.data.transfer.id));
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
const RealDebridClient = require('real-debrid-api');
|
||||
const { encode } = require('magnet-uri');
|
||||
const { Type } = require('../lib/types');
|
||||
const { isVideo, isArchive } = require('../lib/extension');
|
||||
const delay = require('./delay');
|
||||
const StaticResponse = require('./static');
|
||||
const { getRandomProxy, getProxyAgent, getRandomUserAgent, blacklistProxy } = require('../lib/requestHelper');
|
||||
const { cacheWrapProxy, cacheUserAgent, uncacheProxy } = require('../lib/cache');
|
||||
const { getMagnetLink } = require('../lib/magnetHelper');
|
||||
|
||||
const MIN_SIZE = 5 * 1024 * 1024; // 5 MB
|
||||
const CATALOG_MAX_PAGE = 5;
|
||||
@@ -192,7 +192,8 @@ async function _getTorrentInfo(RD, torrentId) {
|
||||
}
|
||||
|
||||
async function _createTorrentId(RD, infoHash, cachedFileIds) {
|
||||
const addedMagnet = await RD.torrents.addMagnet(encode({ infoHash }));
|
||||
const magnetLink = await getMagnetLink(infoHash);
|
||||
const addedMagnet = await RD.torrents.addMagnet(magnetLink);
|
||||
await _selectTorrentFiles(RD, { id: addedMagnet.id }, cachedFileIds);
|
||||
return addedMagnet.id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user