mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[addon] includes trackers for anime torrents
This commit is contained in:
@@ -3,7 +3,7 @@ const { addonBuilder } = require('stremio-addon-sdk');
|
|||||||
const { Type } = require('./lib/types');
|
const { Type } = require('./lib/types');
|
||||||
const { dummyManifest, DefaultProviders } = require('./lib/manifest');
|
const { dummyManifest, DefaultProviders } = require('./lib/manifest');
|
||||||
const { cacheWrapStream } = require('./lib/cache');
|
const { cacheWrapStream } = require('./lib/cache');
|
||||||
const { toStreamInfo } = require('./lib/streamInfo');
|
const { toStreamInfo, applyStaticInfo } = require('./lib/streamInfo');
|
||||||
const repository = require('./lib/repository');
|
const repository = require('./lib/repository');
|
||||||
const applySorting = require('./lib/sort');
|
const applySorting = require('./lib/sort');
|
||||||
const { applyMochs, getMochCatalog, getMochItemMeta } = require('./moch/moch');
|
const { applyMochs, getMochCatalog, getMochItemMeta } = require('./moch/moch');
|
||||||
@@ -17,7 +17,7 @@ const defaultProviders = DefaultProviders.map(provider => provider.toLowerCase()
|
|||||||
const builder = new addonBuilder(dummyManifest());
|
const builder = new addonBuilder(dummyManifest());
|
||||||
const limiter = new Bottleneck({
|
const limiter = new Bottleneck({
|
||||||
maxConcurrent: process.env.LIMIT_MAX_CONCURRENT || 20,
|
maxConcurrent: process.env.LIMIT_MAX_CONCURRENT || 20,
|
||||||
highWater: process.env.LIMIT_QUEUE_SIZE || 100,
|
highWater: process.env.LIMIT_QUEUE_SIZE || 50,
|
||||||
strategy: Bottleneck.strategy.OVERFLOW
|
strategy: Bottleneck.strategy.OVERFLOW
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -32,6 +32,7 @@ builder.defineStreamHandler((args) => {
|
|||||||
.map(record => toStreamInfo(record)))))
|
.map(record => toStreamInfo(record)))))
|
||||||
.then(streams => filterByProvider(streams, args.extra.providers || defaultProviders))
|
.then(streams => filterByProvider(streams, args.extra.providers || defaultProviders))
|
||||||
.then(streams => applySorting(streams, args.extra))
|
.then(streams => applySorting(streams, args.extra))
|
||||||
|
.then(streams => applyStaticInfo(streams))
|
||||||
.then(streams => applyMochs(streams, args.extra))
|
.then(streams => applyMochs(streams, args.extra))
|
||||||
.then(streams => ({
|
.then(streams => ({
|
||||||
streams: streams,
|
streams: streams,
|
||||||
@@ -116,7 +117,7 @@ function filterByProvider(streams, providers) {
|
|||||||
return streams;
|
return streams;
|
||||||
}
|
}
|
||||||
return streams.filter(stream => {
|
return streams.filter(stream => {
|
||||||
const match = stream.title.match(/[🛈⚙].* ([^ \n]+)/);
|
const match = stream.title.match(/⚙.* ([^ \n]+)/);
|
||||||
const provider = match && match[1].toLowerCase();
|
const provider = match && match[1].toLowerCase();
|
||||||
return providers.includes(provider);
|
return providers.includes(provider);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const serverless = require('./serverless');
|
const serverless = require('./serverless');
|
||||||
|
const { initBestTrackers } = require('./lib/magnetHelper');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.use(express.static('static', { maxAge: '1y' }));
|
app.use(express.static('static', { maxAge: '1y' }));
|
||||||
app.use((req, res, next) => serverless(req, res, next));
|
app.use((req, res, next) => serverless(req, res, next));
|
||||||
app.listen(process.env.PORT || 7000, () => {
|
app.listen(process.env.PORT || 7000, () => {
|
||||||
console.log(`Started addon at: http://localhost:${process.env.PORT || 7000}`)
|
initBestTrackers()
|
||||||
|
.then(() => console.log(`Started addon at: http://localhost:${process.env.PORT || 7000}`));
|
||||||
});
|
});
|
||||||
|
|||||||
26
addon/lib/magnetHelper.js
Normal file
26
addon/lib/magnetHelper.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
const needle = require('needle');
|
||||||
|
|
||||||
|
const TRACKERS_URL = 'https://ngosang.github.io/trackerslist/trackers_best.txt';
|
||||||
|
const ANIME_TRACKERS = [
|
||||||
|
"http://nyaa.tracker.wf:7777/announce",
|
||||||
|
"http://anidex.moe:6969/announce",
|
||||||
|
"http://tracker.anirena.com:80/announce",
|
||||||
|
"udp://tracker.uw0.xyz:6969/announce",
|
||||||
|
"http://share.camoe.cn:8080/announce",
|
||||||
|
"http://t.nyaatracker.com:80/announce"
|
||||||
|
];
|
||||||
|
let BEST_TRACKERS = [];
|
||||||
|
let ALL_TRACKERS = [];
|
||||||
|
|
||||||
|
function getAllTrackers() {
|
||||||
|
return ALL_TRACKERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function initBestTrackers() {
|
||||||
|
BEST_TRACKERS = await needle('get', TRACKERS_URL, { open_timeout: 20000 })
|
||||||
|
.then(response => response.body && response.body.trim())
|
||||||
|
.then(body => body && body.split('\n\n') || []);
|
||||||
|
ALL_TRACKERS = BEST_TRACKERS.concat(ANIME_TRACKERS);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { initBestTrackers, getAllTrackers };
|
||||||
@@ -1,10 +1,16 @@
|
|||||||
const titleParser = require('parse-torrent-title');
|
const titleParser = require('parse-torrent-title');
|
||||||
const { Type } = require('./types');
|
const { Type } = require('./types');
|
||||||
const { mapLanguages } = require('./languages');
|
const { mapLanguages } = require('./languages');
|
||||||
|
const { getAllTrackers } = require('./magnetHelper');
|
||||||
|
|
||||||
const ADDON_NAME = 'Torrentio';
|
const ADDON_NAME = 'Torrentio';
|
||||||
const SIZE_DELTA = 0.02;
|
const SIZE_DELTA = 0.02;
|
||||||
const UNKNOWN_SIZE = 300000000;
|
const UNKNOWN_SIZE = 300000000;
|
||||||
|
const ANIME_PROVIDERS = [
|
||||||
|
'HorribleSubs',
|
||||||
|
'NyaaSi',
|
||||||
|
'NyaaPantsu'
|
||||||
|
].map(provider => provider.toLowerCase());
|
||||||
|
|
||||||
function toStreamInfo(record) {
|
function toStreamInfo(record) {
|
||||||
const torrentInfo = titleParser.parse(record.torrent.title);
|
const torrentInfo = titleParser.parse(record.torrent.title);
|
||||||
@@ -86,4 +92,19 @@ function formatSize(size) {
|
|||||||
return Number((size / Math.pow(1024, i)).toFixed(2)) + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
|
return Number((size / Math.pow(1024, i)).toFixed(2)) + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { toStreamInfo };
|
function applyStaticInfo(streams) {
|
||||||
|
return streams.map(stream => enrichStaticInfo(stream));
|
||||||
|
}
|
||||||
|
|
||||||
|
function enrichStaticInfo(stream) {
|
||||||
|
const match = stream.title.match(/⚙.* ([^ \n]+)/);
|
||||||
|
const provider = match && match[1].toLowerCase();
|
||||||
|
if (ANIME_PROVIDERS.includes(provider)) {
|
||||||
|
const infoHash = stream.infoHash;
|
||||||
|
const sources = getAllTrackers().map(tracker => `tracker:${tracker}`).concat(`dht:${infoHash}`);
|
||||||
|
return { ...stream, sources };
|
||||||
|
}
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { toStreamInfo, applyStaticInfo };
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ function populateCachedLinks(streams, mochResult) {
|
|||||||
stream.url = `${RESOLVER_HOST}/${mochResult.moch.key}/${cachedEntry.url}`;
|
stream.url = `${RESOLVER_HOST}/${mochResult.moch.key}/${cachedEntry.url}`;
|
||||||
delete stream.infoHash;
|
delete stream.infoHash;
|
||||||
delete stream.fileIndex;
|
delete stream.fileIndex;
|
||||||
|
delete stream.sources;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return streams;
|
return streams;
|
||||||
|
|||||||
Reference in New Issue
Block a user