mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[scraper] updates 1337x search api to extend results
This commit is contained in:
@@ -9,6 +9,7 @@ const defaultProxies = [
|
|||||||
'https://1337x.to'
|
'https://1337x.to'
|
||||||
];
|
];
|
||||||
const defaultTimeout = 10000;
|
const defaultTimeout = 10000;
|
||||||
|
const maxSearchPage = 50;
|
||||||
|
|
||||||
const Categories = {
|
const Categories = {
|
||||||
MOVIE: 'Movies',
|
MOVIE: 'Movies',
|
||||||
@@ -42,10 +43,19 @@ function search(keyword, config = {}, retries = 2) {
|
|||||||
}
|
}
|
||||||
const proxyList = config.proxyList || defaultProxies;
|
const proxyList = config.proxyList || defaultProxies;
|
||||||
const page = config.page || 1;
|
const page = config.page || 1;
|
||||||
|
const category = config.category;
|
||||||
|
const extendToPage = Math.min(maxSearchPage, (config.extendToPage || 1))
|
||||||
|
const requestUrl = proxyUrl => category
|
||||||
|
? `${proxyUrl}/category-search/${keyword}/${category}/${page}/`
|
||||||
|
: `${proxyUrl}/search/${keyword}/${page}/`;
|
||||||
|
|
||||||
return Promises.first(proxyList
|
return Promises.first(proxyList
|
||||||
.map((proxyUrl) => singleRequest(`${proxyUrl}/search/${keyword}/${page}/`, config)))
|
.map(proxyUrl => singleRequest(requestUrl(proxyUrl), config)))
|
||||||
.then((body) => parseTableBody(body))
|
.then(body => parseTableBody(body))
|
||||||
|
.then(torrents => torrents.length === 40 && page < extendToPage
|
||||||
|
? search(keyword, { ...config, page: page + 1 }).catch(() => [])
|
||||||
|
.then(nextTorrents => torrents.concat(nextTorrents))
|
||||||
|
: torrents)
|
||||||
.catch((err) => search(keyword, config, retries - 1));
|
.catch((err) => search(keyword, config, retries - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ async function processTorrentRecord(record) {
|
|||||||
infoHash: torrentFound.infoHash,
|
infoHash: torrentFound.infoHash,
|
||||||
provider: NAME,
|
provider: NAME,
|
||||||
torrentId: torrentFound.torrentId,
|
torrentId: torrentFound.torrentId,
|
||||||
title: torrentFound.name.replace(/\t|\s+/g, ' '),
|
title: torrentFound.name.replace(/\t|\s+/g, ' ').trim(),
|
||||||
type: TYPE_MAPPING[torrentFound.category],
|
type: TYPE_MAPPING[torrentFound.category],
|
||||||
size: torrentFound.size,
|
size: torrentFound.size,
|
||||||
seeders: torrentFound.seeders,
|
seeders: torrentFound.seeders,
|
||||||
|
|||||||
Reference in New Issue
Block a user