mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
format darkmahou provider
This commit is contained in:
@@ -8,13 +8,11 @@ const { getRandomUserAgent } = require("../../lib/requestHelper");
|
||||
const defaultTimeout = 10000;
|
||||
const maxSearchPage = 50;
|
||||
|
||||
const limiter = new Bottleneck({ maxConcurrent: 10 });
|
||||
|
||||
const defaultProxies = ["https://darkmahou.com"];
|
||||
const defaultProxies = ['https://darkmahou.com'];
|
||||
|
||||
const Categories = {
|
||||
MOVIE: "movie",
|
||||
ANIME: "tv",
|
||||
MOVIE: 'movie',
|
||||
ANIME: 'tv',
|
||||
OVA: 'ova'
|
||||
};
|
||||
|
||||
@@ -25,11 +23,11 @@ function torrent(torrentId, config = {}, retries = 2) {
|
||||
const proxyList = config.proxyList || defaultProxies;
|
||||
const slug = torrentId.split("/")[3];
|
||||
return Promises.first(
|
||||
proxyList.map((proxyUrl) => singleRequest(`${proxyUrl}/${slug}`, config))
|
||||
)
|
||||
.then((body) => parseTorrentPage(body))
|
||||
.then((torrent) => torrent.map((el) => ({ torrentId: slug, ...el })))
|
||||
.catch((err) => torrent(slug, config, retries - 1));
|
||||
proxyList.map((proxyUrl) => singleRequest(`${proxyUrl}/${slug}`, config))
|
||||
)
|
||||
.then((body) => parseTorrentPage(body))
|
||||
.then((torrent) => torrent.map((el) => ({ torrentId: slug, ...el })))
|
||||
.catch((err) => torrent(slug, config, retries - 1));
|
||||
}
|
||||
|
||||
function search(keyword, config = {}, retries = 2) {
|
||||
@@ -42,17 +40,17 @@ function search(keyword, config = {}, retries = 2) {
|
||||
const requestUrl = (proxyUrl) => `${proxyUrl}/page/${page}/?s=${keyword}`;
|
||||
|
||||
return Promises.first(
|
||||
proxyList.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));
|
||||
proxyList.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));
|
||||
}
|
||||
|
||||
function browse(config = {}, retries = 2) {
|
||||
@@ -63,15 +61,15 @@ function browse(config = {}, retries = 2) {
|
||||
const page = config.page || 1;
|
||||
const category = config.category;
|
||||
const requestUrl = (proxyUrl) =>
|
||||
category
|
||||
? `${proxyUrl}/category/${category}/page/${page}/`
|
||||
: `${proxyUrl}/page/${page}/`;
|
||||
category
|
||||
? `${proxyUrl}/category/${category}/page/${page}/`
|
||||
: `${proxyUrl}/page/${page}/`;
|
||||
|
||||
return Promises.first(
|
||||
proxyList.map((proxyUrl) => singleRequest(requestUrl(proxyUrl), config))
|
||||
)
|
||||
.then((body) => parseTableBody(body))
|
||||
.catch((err) => browse(config, retries - 1));
|
||||
proxyList.map((proxyUrl) => singleRequest(requestUrl(proxyUrl), config))
|
||||
)
|
||||
.then((body) => parseTableBody(body))
|
||||
.catch((err) => browse(config, retries - 1));
|
||||
}
|
||||
|
||||
function singleRequest(requestUrl, config = {}) {
|
||||
@@ -87,8 +85,8 @@ function singleRequest(requestUrl, config = {}) {
|
||||
if (!body) {
|
||||
throw new Error(`No body: ${requestUrl}`);
|
||||
} else if (
|
||||
body.includes("502: Bad gateway") ||
|
||||
body.includes("403 Forbidden")
|
||||
body.includes("502: Bad gateway") ||
|
||||
body.includes("403 Forbidden")
|
||||
) {
|
||||
throw new Error(`Invalid body contents: ${requestUrl}`);
|
||||
}
|
||||
@@ -118,7 +116,7 @@ function parseTableBody(body) {
|
||||
}
|
||||
|
||||
function parseTorrentPage(body) {
|
||||
return new Promise(async(resolve, reject) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const $ = cheerio.load(body);
|
||||
|
||||
if (!$) {
|
||||
@@ -133,8 +131,8 @@ function parseTorrentPage(body) {
|
||||
const torrent = magnets.map((magnetLink) => {
|
||||
return {
|
||||
title: decode(magnetLink).name,
|
||||
original_name: details.find('h1.entry-title').text(),
|
||||
year: details.find('b:contains(\'Lançado:\')')[0].nextSibling.nodeValue || '',
|
||||
originalName: details.find('h1.entry-title').text(),
|
||||
year: details.find('b:contains(\'Lançado:\')')[0].nextSibling.nodeValue || '',
|
||||
infoHash: decode(magnetLink).infoHash,
|
||||
magnetLink: magnetLink,
|
||||
category: details.find('b:contains(\'Tipo:\')').next().attr('href').split('/')[4],
|
||||
|
||||
Reference in New Issue
Block a user