fix lapumia scraper

This commit is contained in:
TheBeastLT
2022-05-24 09:29:44 +02:00
parent 8199b50021
commit d17c1b05c3
2 changed files with 13 additions and 9 deletions

View File

@@ -21,12 +21,11 @@ function torrent(torrentId, config = {}, retries = 2) {
if (!torrentId || retries === 0) {
return Promise.reject(new Error(`Failed ${torrentId} query`));
}
const slug = torrentId.split('?p=')[1];
return singleRequest(`${baseUrl}/?p=${slug}`, config)
return singleRequest(`${baseUrl}/${torrentId}`, config)
.then((body) => parseTorrentPage(body))
.then((torrent) => torrent.map(el => ({ torrentId: slug, ...el })))
.then((torrent) => torrent.map(el => ({ torrentId, ...el })))
.catch((err) => {
console.warn(`Failed Lapumia ${slug} request: `, err);
console.warn(`Failed Lapumia ${torrentId} request: `, err);
return torrent(torrentId, config, retries - 1)
});
}
@@ -90,10 +89,14 @@ function parseTableBody(body) {
$('div.post').each((i, element) => {
const row = $(element);
torrents.push({
name: row.find("div > a").text(),
torrentId: row.find("div > a").attr("href")
});
try {
torrents.push({
name: row.find("div > a").text(),
torrentId: row.find("div > a").attr("href").split('/')[3]
});
} catch (e) {
console.log("Failed parsing Lupumia table entry")
}
});
resolve(torrents);
});

View File

@@ -33,7 +33,8 @@ async function updateSeeders(torrent) {
async function scrapeLatestTorrents() {
const allowedCategories = [
lapumia.Categories.MOVIE
lapumia.Categories.MOVIE,
lapumia.Categories.TV
];
return Promises.sequence(allowedCategories