[scraper] updates 1337x search api to extend results

This commit is contained in:
TheBeastLT
2020-04-25 10:29:10 +02:00
parent 43c2e737f8
commit 10615e4aed
2 changed files with 13 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ const defaultProxies = [
'https://1337x.to'
];
const defaultTimeout = 10000;
const maxSearchPage = 50;
const Categories = {
MOVIE: 'Movies',
@@ -42,10 +43,19 @@ function search(keyword, config = {}, retries = 2) {
}
const proxyList = config.proxyList || defaultProxies;
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
.map((proxyUrl) => singleRequest(`${proxyUrl}/search/${keyword}/${page}/`, config)))
.then((body) => parseTableBody(body))
.map(proxyUrl => singleRequest(requestUrl(proxyUrl), config)))
.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));
}

View File

@@ -73,7 +73,7 @@ async function processTorrentRecord(record) {
infoHash: torrentFound.infoHash,
provider: NAME,
torrentId: torrentFound.torrentId,
title: torrentFound.name.replace(/\t|\s+/g, ' '),
title: torrentFound.name.replace(/\t|\s+/g, ' ').trim(),
type: TYPE_MAPPING[torrentFound.category],
size: torrentFound.size,
seeders: torrentFound.seeders,