mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[scraper] fixes update seeders method
This commit is contained in:
@@ -83,7 +83,7 @@ function escapeTitle(title) {
|
|||||||
.normalize('NFKD') // normalize non-ASCII characters
|
.normalize('NFKD') // normalize non-ASCII characters
|
||||||
.replace(/[\u0300-\u036F]/g, '')
|
.replace(/[\u0300-\u036F]/g, '')
|
||||||
.replace(/&/g, 'and')
|
.replace(/&/g, 'and')
|
||||||
.replace(/[;, ~]+/g, ' ') // replace dots, commas or underscores with spaces
|
.replace(/[;, ~.]+/g, ' ') // replace dots, commas or underscores with spaces
|
||||||
.replace(/[^\w \-()+#@!']+/g, '') // remove all non-alphanumeric chars
|
.replace(/[^\w \-()+#@!']+/g, '') // remove all non-alphanumeric chars
|
||||||
.trim();
|
.trim();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ function getTorrent(torrent) {
|
|||||||
if (!result) {
|
if (!result) {
|
||||||
throw new Error(`torrent not found: ${torrent.infoHash}`);
|
throw new Error(`torrent not found: ${torrent.infoHash}`);
|
||||||
}
|
}
|
||||||
return result.dataValues;
|
return result;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,6 +115,14 @@ function getTorrentsBasedOnTitle(titleQuery, type) {
|
|||||||
return Torrent.findAll({ where: { title: { [Op.regexp]: `${titleQuery}` }, type: type } });
|
return Torrent.findAll({ where: { title: { [Op.regexp]: `${titleQuery}` }, type: type } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTorrentsWithoutId(provider) {
|
||||||
|
return Torrent.findAll({ where: { provider: provider, torrentId: { [Op.is]: null } }, limit: 100 });
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTorrentsUpdatedBetween(provider, startDate, endDate) {
|
||||||
|
return Torrent.findAll({ where: { provider: provider, updatedAt: { [Op.gte]: startDate, [Op.lte]: endDate } } });
|
||||||
|
}
|
||||||
|
|
||||||
function createTorrent(torrent) {
|
function createTorrent(torrent) {
|
||||||
return Torrent.upsert(torrent);
|
return Torrent.upsert(torrent);
|
||||||
}
|
}
|
||||||
@@ -176,5 +184,7 @@ module.exports = {
|
|||||||
deleteFile,
|
deleteFile,
|
||||||
getSkipTorrent,
|
getSkipTorrent,
|
||||||
createSkipTorrent,
|
createSkipTorrent,
|
||||||
createFailedImdbTorrent
|
createFailedImdbTorrent,
|
||||||
|
getTorrentsWithoutId,
|
||||||
|
getTorrentsUpdatedBetween
|
||||||
};
|
};
|
||||||
@@ -60,10 +60,21 @@ async function updateTorrentSeeders(torrent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return repository.getTorrent(torrent)
|
return repository.getTorrent(torrent)
|
||||||
|
.catch(() => undefined)
|
||||||
.then(stored => {
|
.then(stored => {
|
||||||
stored.seeders = torrent.seeders;
|
if (stored && stored.seeders !== torrent.seeders) {
|
||||||
return stored.save();
|
stored.seeders = torrent.seeders;
|
||||||
}).catch(() => undefined);
|
return stored.save()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(updated => {
|
||||||
|
console.log(`Updated [${torrent.infoHash}] ${torrent.name || torrent.title} to ${torrent.seeders} seeders`);
|
||||||
|
return updated;
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.warn('Failed updating seeders:', error);
|
||||||
|
return undefined;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { createTorrentEntry, createSkipTorrentEntry, getStoredTorrentEntry, updateTorrentSeeders };
|
module.exports = { createTorrentEntry, createSkipTorrentEntry, getStoredTorrentEntry, updateTorrentSeeders };
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ async function updateMovieCollections() {
|
|||||||
.then(files => files.filter(file => parse(file.title).complete));
|
.then(files => files.filter(file => parse(file.title).complete));
|
||||||
|
|
||||||
collectionFiles.map(original => repository.getTorrent({ infoHash: original.infoHash })
|
collectionFiles.map(original => repository.getTorrent({ infoHash: original.infoHash })
|
||||||
.then(torrent => parseTorrentFiles({ ...torrent, imdbId: original.imdbId }))
|
.then(torrent => parseTorrentFiles({ ...torrent.get(), imdbId: original.imdbId }))
|
||||||
.then(files => Promise.all(files.map(file => {
|
.then(files => Promise.all(files.map(file => {
|
||||||
console.log(file);
|
console.log(file);
|
||||||
return repository.createFile(file)
|
return repository.createFile(file)
|
||||||
@@ -90,7 +90,7 @@ async function reapplyEpisodeDecomposing(infoHash, includeSourceFiles = true) {
|
|||||||
}));
|
}));
|
||||||
const imdbId = storedFiles.length && storedFiles[0].imdbId || await getImdbId(parse(torrent.title));
|
const imdbId = storedFiles.length && storedFiles[0].imdbId || await getImdbId(parse(torrent.title));
|
||||||
|
|
||||||
return parseTorrentFiles({ ...torrent, imdbId, files })
|
return parseTorrentFiles({ ...torrent.get(), imdbId, files })
|
||||||
.then(newFiles => newFiles.map(file => {
|
.then(newFiles => newFiles.map(file => {
|
||||||
const fileIndex = file.fileIndex !== undefined ? file.fileIndex : null;
|
const fileIndex = file.fileIndex !== undefined ? file.fileIndex : null;
|
||||||
const mapping = fileIndexMap[fileIndex];
|
const mapping = fileIndexMap[fileIndex];
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ function parseTorrentPage(body) {
|
|||||||
category: details.find('strong:contains(\'Category\')').next().text(),
|
category: details.find('strong:contains(\'Category\')').next().text(),
|
||||||
language: details.find('strong:contains(\'Language\')').next().text(),
|
language: details.find('strong:contains(\'Language\')').next().text(),
|
||||||
size: parseSize(details.find('strong:contains(\'Total size\')').next().text()),
|
size: parseSize(details.find('strong:contains(\'Total size\')').next().text()),
|
||||||
uploadDate: Sugar.Date.create(details.find('strong:contains(\'Date uploaded\')').next().text()),
|
uploadDate: parseDate(details.find('strong:contains(\'Date uploaded\')').next().text()),
|
||||||
imdbId: imdbIdMatch && imdbIdMatch[1],
|
imdbId: imdbIdMatch && imdbIdMatch[1],
|
||||||
files: details.find('div[id=\'files\']').first().find('li')
|
files: details.find('div[id=\'files\']').first().find('li')
|
||||||
.map((i, elem) => $(elem).text())
|
.map((i, elem) => $(elem).text())
|
||||||
@@ -145,6 +145,13 @@ function parseTorrentPage(body) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseDate(dateString) {
|
||||||
|
if (/decade.*ago/i.test(dateString)) {
|
||||||
|
return Sugar.Date.create('10 years ago');
|
||||||
|
}
|
||||||
|
return Sugar.Date.create(dateString);
|
||||||
|
}
|
||||||
|
|
||||||
function parseSize(sizeText) {
|
function parseSize(sizeText) {
|
||||||
if (!sizeText) {
|
if (!sizeText) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
@@ -80,6 +80,15 @@ async function processTorrentRecord(record) {
|
|||||||
return createTorrentEntry(torrent);
|
return createTorrentEntry(torrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function updateSeeders() {
|
||||||
|
const startDate = moment().subtract(7, 'day').toDate();
|
||||||
|
const endDate = moment().subtract(1, 'day').toDate();
|
||||||
|
return repository.getTorrentsUpdatedBetween(NAME, startDate, endDate)
|
||||||
|
.then(torrents => Promise.all(torrents.map(torrent => limiter.schedule(() => leetx.torrent(torrent.torrentId)
|
||||||
|
.then(foundTorrent => updateTorrentSeeders(foundTorrent))
|
||||||
|
.catch(error => console.warn(error))))))
|
||||||
|
}
|
||||||
|
|
||||||
function typeMapping() {
|
function typeMapping() {
|
||||||
const mapping = {};
|
const mapping = {};
|
||||||
mapping[leetx.Categories.MOVIE] = Type.MOVIE;
|
mapping[leetx.Categories.MOVIE] = Type.MOVIE;
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ async function checkIfExists(torrent) {
|
|||||||
} else if (existingTorrent.provider === NAME) {
|
} else if (existingTorrent.provider === NAME) {
|
||||||
return undefined; // torrent by this provider already exists
|
return undefined; // torrent by this provider already exists
|
||||||
}
|
}
|
||||||
return { ...torrent, size: existingTorrent.size, seeders: existingTorrent.seeders };
|
return { ...torrent.get(), size: existingTorrent.size, seeders: existingTorrent.seeders };
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { scrape, NAME };
|
module.exports = { scrape, NAME };
|
||||||
@@ -7,10 +7,13 @@ const Promises = require('../../lib/promises');
|
|||||||
const defaultProxies = [
|
const defaultProxies = [
|
||||||
// 'https://thepiratebay.org',
|
// 'https://thepiratebay.org',
|
||||||
// 'https://proxybay.pro',
|
// 'https://proxybay.pro',
|
||||||
'https://ukpiratebayproxy.com',
|
// 'https://ukpiratebayproxy.com',
|
||||||
'https://thepiratebayproxy.info',
|
// 'https://thepiratebayproxy.info',
|
||||||
'https://mypiratebay.co',
|
// 'https://mypiratebay.co',
|
||||||
'https://thepiratebay.asia',
|
'https://thepiratebay.asia',
|
||||||
|
'https://thepiratebay10.org',
|
||||||
|
'https://thepiratebay0.org',
|
||||||
|
'https://proxtpb.art',
|
||||||
];
|
];
|
||||||
const dumpUrl = '/static/dump/csv/';
|
const dumpUrl = '/static/dump/csv/';
|
||||||
const defaultTimeout = 10000;
|
const defaultTimeout = 10000;
|
||||||
|
|||||||
Reference in New Issue
Block a user