mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[scraper] implements custom rargb api class
This commit is contained in:
@@ -1,31 +1,29 @@
|
||||
const moment = require('moment');
|
||||
const Bottleneck = require('bottleneck');
|
||||
const rarbg = require('rarbg-api');
|
||||
const decode = require('magnet-uri');
|
||||
const rarbg = require('./rarbg_api');
|
||||
const { Type } = require('../../lib/types');
|
||||
const { createTorrentEntry, checkAndUpdateTorrent } = require('../../lib/torrentEntries');
|
||||
|
||||
const NAME = 'RARBG';
|
||||
|
||||
const limiter = new Bottleneck({ maxConcurrent: 1, minTime: 2500 });
|
||||
const entryLimiter = new Bottleneck({ maxConcurrent: 40 });
|
||||
const entryLimiter = new Bottleneck({ maxConcurrent: 20 });
|
||||
const allowedCategories = [
|
||||
rarbg.CATEGORY.MOVIES_XVID,
|
||||
rarbg.CATEGORY.MOVIES_XVID_720P,
|
||||
rarbg.CATEGORY.MOVIES_X265_1080P,
|
||||
rarbg.CATEGORY.MOVIES_X265_4K,
|
||||
rarbg.CATEGORY.MOVIES_X265_4K_HDR,
|
||||
rarbg.CATEGORY.MOVIES_X264,
|
||||
rarbg.CATEGORY.MOVIES_X264_720P,
|
||||
rarbg.CATEGORY.MOVIES_X264_1080P,
|
||||
rarbg.CATEGORY.MOVIES_X264_3D,
|
||||
rarbg.CATEGORY.MOVIES_X264_4K,
|
||||
rarbg.CATEGORY.MOVIES_BD_REMUX,
|
||||
rarbg.CATEGORY.TV_EPISODES,
|
||||
rarbg.CATEGORY.TV_UHD_EPISODES,
|
||||
rarbg.CATEGORY.TV_HD_EPISODES
|
||||
rarbg.Options.category.MOVIES_XVID,
|
||||
rarbg.Options.category.MOVIES_XVID_720P,
|
||||
rarbg.Options.category.MOVIES_X265_1080P,
|
||||
rarbg.Options.category.MOVIES_X265_4K,
|
||||
rarbg.Options.category.MOVIES_X265_4K_HDR,
|
||||
rarbg.Options.category.MOVIES_X264,
|
||||
rarbg.Options.category.MOVIES_X264_720P,
|
||||
rarbg.Options.category.MOVIES_X264_1080P,
|
||||
rarbg.Options.category.MOVIES_X264_3D,
|
||||
rarbg.Options.category.MOVIES_X264_4K,
|
||||
rarbg.Options.category.MOVIES_BD_REMUX,
|
||||
rarbg.Options.category.TV_EPISODES,
|
||||
rarbg.Options.category.TV_UHD_EPISODES,
|
||||
rarbg.Options.category.TV_HD_EPISODES
|
||||
].reduce((a, b) => a.concat(b), [])
|
||||
const searchOptions = { limit: 100, category: allowedCategories, sort: 'seeders', format: 'json_extended', ranked: 0 }
|
||||
|
||||
async function scrape() {
|
||||
console.log(`[${moment()}] starting ${NAME} dump scrape...`);
|
||||
@@ -39,28 +37,13 @@ async function scrape() {
|
||||
.then(() => console.log(`[${moment()}] finished ${NAME} dump scrape`));
|
||||
}
|
||||
|
||||
async function getTorrentsForImdbId(imdbId, retries = 5) {
|
||||
return rarbg.search(imdbId, searchOptions, 'imdb')
|
||||
.then(torrents => torrents.map(torrent => ({
|
||||
name: torrent.title,
|
||||
infoHash: decode(torrent.download).infoHash,
|
||||
magnetLink: torrent.download,
|
||||
seeders: torrent.seeders,
|
||||
leechers: torrent.leechers,
|
||||
category: torrent.category,
|
||||
size: torrent.size,
|
||||
uploadDate: new Date(torrent.pubdate),
|
||||
imdbId: torrent.episode_info && torrent.episode_info.imdb
|
||||
})))
|
||||
async function getTorrentsForImdbId(imdbId) {
|
||||
return rarbg.search(imdbId, { category: allowedCategories })
|
||||
.then(torrents => {
|
||||
console.log(`Completed ${imdbId} request`);
|
||||
return torrents;
|
||||
})
|
||||
.catch(error => {
|
||||
if (retries > 0) {
|
||||
console.log(`Retrying ${NAME} request for ${imdbId}...`);
|
||||
return getTorrentsForImdbId(imdbId, retries - 1);
|
||||
}
|
||||
console.warn(`Failed ${NAME} request for ${imdbId}: `, error);
|
||||
return [];
|
||||
});
|
||||
@@ -74,7 +57,7 @@ async function processTorrentRecord(record) {
|
||||
const torrent = {
|
||||
provider: NAME,
|
||||
infoHash: record.infoHash,
|
||||
title: record.name,
|
||||
title: record.title,
|
||||
type: getType(record.category),
|
||||
seeders: record.seeders,
|
||||
size: record.size,
|
||||
|
||||
Reference in New Issue
Block a user