mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
update comando api
This commit is contained in:
@@ -29,7 +29,7 @@ function torrent(torrentId, config = {}, retries = 2) {
|
|||||||
.then((torrent) => torrent.map(el => ({ torrentId: slug, ...el })))
|
.then((torrent) => torrent.map(el => ({ torrentId: slug, ...el })))
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.warn(`Failed Comando ${slug} request: `, err);
|
console.warn(`Failed Comando ${slug} request: `, err);
|
||||||
return torrent(slug, config, retries - 1)
|
return torrent(torrentId, config, retries - 1)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,14 +116,14 @@ function parseTorrentPage(body) {
|
|||||||
const torrents = magnets.map(magnetLink => {
|
const torrents = magnets.map(magnetLink => {
|
||||||
const decodedMagnet = decode(magnetLink);
|
const decodedMagnet = decode(magnetLink);
|
||||||
const originalNameElem = details.find('strong, b')
|
const originalNameElem = details.find('strong, b')
|
||||||
.filter((i, elem) => $(elem).text().match(/Baixar|Orig(?:\.|inal)/));
|
.filter((i, elem) => $(elem).text().match(/Baixar|Orig(?:\.|inal)|^Título:/));
|
||||||
const languagesElem = details.find('strong, b')
|
const languagesElem = details.find('strong, b')
|
||||||
.filter((i, elem) => $(elem).text().match(/^\s*([IÍ]dioma|[AÁ]udio)/));
|
.filter((i, elem) => $(elem).text().match(/^\s*([IÍ]dioma|[AÁ]udio)/));
|
||||||
const originalName = originalNameElem.next().text().trim() || originalNameElem[0].nextSibling.nodeValue;
|
const originalName = parseOriginalName(originalNameElem);
|
||||||
const title = decodedMagnet.name && escapeHTML(decodedMagnet.name.replace(/\+/g, ' '));
|
const title = decodedMagnet.name && escapeHTML(decodedMagnet.name.replace(/\+/g, ' '));
|
||||||
return {
|
return {
|
||||||
title: title ? sanitizePtName(title) : originalName.replace(/: ?/, ''),
|
title: title ? sanitizePtName(title) : originalName,
|
||||||
originalName: sanitizePtOriginalName(originalName.replace(/: ?/, '')),
|
originalName: sanitizePtOriginalName(originalName),
|
||||||
year: details.find('a[href*="comando.to/category/"]').text(),
|
year: details.find('a[href*="comando.to/category/"]').text(),
|
||||||
infoHash: decodedMagnet.infoHash,
|
infoHash: decodedMagnet.infoHash,
|
||||||
magnetLink: magnetLink,
|
magnetLink: magnetLink,
|
||||||
@@ -137,6 +137,14 @@ function parseTorrentPage(body) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseOriginalName(originalNameElem) {
|
||||||
|
if (!originalNameElem[0]) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
const originalName = originalNameElem.next().text().trim() || originalNameElem[0].nextSibling.nodeValue;
|
||||||
|
return originalName.replace(/: ?/, '');
|
||||||
|
}
|
||||||
|
|
||||||
function parseCategory(categorys) {
|
function parseCategory(categorys) {
|
||||||
const $ = cheerio.load(categorys)
|
const $ = cheerio.load(categorys)
|
||||||
if ($('a:contains(\'animes\')').text()) {
|
if ($('a:contains(\'animes\')').text()) {
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ async function processTorrentRecord(foundTorrent) {
|
|||||||
if (!Number.isInteger(foundTorrent.seeders)) {
|
if (!Number.isInteger(foundTorrent.seeders)) {
|
||||||
await updateCurrentSeeders(foundTorrent);
|
await updateCurrentSeeders(foundTorrent);
|
||||||
}
|
}
|
||||||
if (!foundTorrent.imdbId) {
|
if (!foundTorrent.imdbId && foundTorrent.originalName) {
|
||||||
const info = { title: foundTorrent.originalName, year: foundTorrent.year };
|
const info = { title: foundTorrent.originalName, year: foundTorrent.year };
|
||||||
foundTorrent.imdbId = await getImdbId(info, TYPE_MAPPING[foundTorrent.category]).catch(() => undefined);
|
foundTorrent.imdbId = await getImdbId(info, TYPE_MAPPING[foundTorrent.category]).catch(() => undefined);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,13 +21,13 @@ function torrent(torrentId, config = {}, retries = 2) {
|
|||||||
if (!torrentId || retries === 0) {
|
if (!torrentId || retries === 0) {
|
||||||
return Promise.reject(new Error(`Failed ${torrentId} query`));
|
return Promise.reject(new Error(`Failed ${torrentId} query`));
|
||||||
}
|
}
|
||||||
const slug = torrentId.split("/")[3];
|
const slug = encodeURIComponent(torrentId.split("/")[3]);
|
||||||
return singleRequest(`${baseUrl}/${slug}/`, config)
|
return singleRequest(`${baseUrl}/${slug}/`, config)
|
||||||
.then((body) => parseTorrentPage(body))
|
.then((body) => parseTorrentPage(body))
|
||||||
.then((torrent) => torrent.map(el => ({ torrentId: slug, ...el })))
|
.then((torrent) => torrent.map(el => ({ torrentId: slug, ...el })))
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.warn(`Failed ComoEuBaixo ${slug} request: `, err);
|
console.warn(`Failed ComoEuBaixo ${torrentId} request: `, err);
|
||||||
return torrent(slug, config, retries - 1)
|
return torrent(torrentId, config, retries - 1)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ function singleRequest(requestUrl, config = {}) {
|
|||||||
return needle('get', requestUrl, options)
|
return needle('get', requestUrl, options)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const body = response.body;
|
const body = response.body;
|
||||||
if (!body) {
|
if (!body || (Buffer.isBuffer(body) && !body.size)) {
|
||||||
throw new Error(`No body: ${requestUrl}`);
|
throw new Error(`No body: ${requestUrl}`);
|
||||||
} else if (body.includes('502: Bad gateway') ||
|
} else if (body.includes('502: Bad gateway') ||
|
||||||
body.includes('403 Forbidden')) {
|
body.includes('403 Forbidden')) {
|
||||||
@@ -118,7 +118,7 @@ function parseTorrentPage(body) {
|
|||||||
const year = details.find('strong:contains(\'Data de Lançamento: \')').next().text().trim();
|
const year = details.find('strong:contains(\'Data de Lançamento: \')').next().text().trim();
|
||||||
const fallBackTitle = `${originalTitle.trim()} ${year.trim()} ${sanitizedTitle.trim()}`;
|
const fallBackTitle = `${originalTitle.trim()} ${year.trim()} ${sanitizedTitle.trim()}`;
|
||||||
return {
|
return {
|
||||||
title: sanitizedTitle.length > 4 ? sanitizedTitle : fallBackTitle,
|
title: sanitizedTitle.length > 5 ? sanitizedTitle : fallBackTitle,
|
||||||
infoHash: decode(magnetLink).infoHash,
|
infoHash: decode(magnetLink).infoHash,
|
||||||
magnetLink: magnetLink,
|
magnetLink: magnetLink,
|
||||||
category: category,
|
category: category,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ function torrent(torrentId, config = {}, retries = 2) {
|
|||||||
.then((torrent) => torrent.map(el => ({ torrentId: slug, ...el })))
|
.then((torrent) => torrent.map(el => ({ torrentId: slug, ...el })))
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.warn(`Failed Lapumia ${slug} request: `, err);
|
console.warn(`Failed Lapumia ${slug} request: `, err);
|
||||||
return torrent(slug, config, retries - 1)
|
return torrent(torrentId, config, retries - 1)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ function torrent(torrentId, config = {}, retries = 2) {
|
|||||||
.then((torrent) => torrent.map(el => ({ torrentId: slug, ...el })))
|
.then((torrent) => torrent.map(el => ({ torrentId: slug, ...el })))
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.warn(`Failed OndeBaixo ${slug} request: `, err);
|
console.warn(`Failed OndeBaixo ${slug} request: `, err);
|
||||||
return torrent(slug, config, retries - 1)
|
return torrent(torrentId, config, retries - 1)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ function isPtDubbed(name) {
|
|||||||
function sanitizePtName(name) {
|
function sanitizePtName(name) {
|
||||||
return name
|
return name
|
||||||
.replace(/(.*)\b(\d{3,4}P)\b(?!.*\d{3,4}[Pp])(.*)/, '$1$3 $2') // add resolution to the end if missing
|
.replace(/(.*)\b(\d{3,4}P)\b(?!.*\d{3,4}[Pp])(.*)/, '$1$3 $2') // add resolution to the end if missing
|
||||||
.replace(/^[[{]?(?:ACESSE.*|WWW\.)?[A-Z]+\.(COM|ORG|TO|TV)\b\s?[-\]}]+[\s.]*/i, '') // replace watermarks
|
.replace(/^[[{]?(?:ACESSE.*|WWW\.)?[A-Z]+\.(COM|NET|ORG|TO|TV|ME)\b\s*[-\]}]+[\s.]*/i, '') // replace watermarks
|
||||||
.replace(/^(\d*(?:\.\d{1,2})?(?:[4A-Z-]{3,}|P)[-.]+)+/, '') // replace metadata prefixes
|
.replace(/^(\d*(?:\.\d{1,2})?(?:[4A-Z-]{3,}|P)[-.]+)+/, '') // replace metadata prefixes
|
||||||
|
.replace(/^(COM|NET|ORG|TO|TV|ME)\b\s*-+[\s.]*/, '') // replace dangling site endings
|
||||||
.trim();
|
.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user