mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[scraper] updates stream info mapping
This commit is contained in:
@@ -81,7 +81,11 @@ function filterByProvider(streams, providers) {
|
|||||||
if (!providers || !providers.length) {
|
if (!providers || !providers.length) {
|
||||||
return streams;
|
return streams;
|
||||||
}
|
}
|
||||||
return streams.filter(stream => providers.includes(stream.name.split('\n')[1].toLowerCase()))
|
return streams.filter(stream => {
|
||||||
|
const parts = stream.title.split('\n');
|
||||||
|
const provider = parts[parts.length - 2].match(/\w+$/)[0];
|
||||||
|
return providers.includes(provider.toLowerCase());
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = builder.getInterface();
|
module.exports = builder.getInterface();
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ function sortBySeeders(streams) {
|
|||||||
function sortByVideoQuality(streams, limit) {
|
function sortByVideoQuality(streams, limit) {
|
||||||
const qualityMap = sortBySeeders(streams)
|
const qualityMap = sortBySeeders(streams)
|
||||||
.reduce((map, stream) => {
|
.reduce((map, stream) => {
|
||||||
const quality = extractQuality(stream.title);
|
const quality = extractQuality(stream.name);
|
||||||
map[quality] = (map[quality] || []).concat(stream);
|
map[quality] = (map[quality] || []).concat(stream);
|
||||||
return map;
|
return map;
|
||||||
}, {});
|
}, {});
|
||||||
@@ -56,8 +56,7 @@ function sortByVideoQuality(streams, limit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function extractQuality(title) {
|
function extractQuality(title) {
|
||||||
const qualityMatch = title.match(/📺 (.*)/);
|
const qualityDesc = title.split('\n')[1];
|
||||||
const qualityDesc = qualityMatch && qualityMatch[1];
|
|
||||||
const resolutionMatch = qualityDesc && qualityDesc.match(/\d+p/);
|
const resolutionMatch = qualityDesc && qualityDesc.match(/\d+p/);
|
||||||
if (resolutionMatch) {
|
if (resolutionMatch) {
|
||||||
return resolutionMatch[0];
|
return resolutionMatch[0];
|
||||||
|
|||||||
@@ -1,58 +1,40 @@
|
|||||||
const titleParser = require('parse-torrent-title');
|
const titleParser = require('parse-torrent-title');
|
||||||
const { Type } = require('./types');
|
|
||||||
|
|
||||||
const ADDON_NAME = 'Torrentio';
|
const ADDON_NAME = 'Torrentio';
|
||||||
|
const UNKNOWN_SIZE = 300000000;
|
||||||
|
|
||||||
function toStreamInfo(record) {
|
function toStreamInfo(record) {
|
||||||
if (record.torrent.type === Type.MOVIE) {
|
const torrentInfo = titleParser.parse(record.torrent.title);
|
||||||
return movieStream(record);
|
const fileInfo = titleParser.parse(record.title);
|
||||||
}
|
const sameInfo = !Number.isInteger(record.fileIndex)
|
||||||
return seriesStream(record);
|
|| record.size !== UNKNOWN_SIZE && record.size === record.torrent.size;
|
||||||
}
|
|
||||||
|
|
||||||
function movieStream(record) {
|
|
||||||
const titleInfo = titleParser.parse(record.title);
|
|
||||||
const sameInfo = record.title === record.torrent.title;
|
|
||||||
const title = joinDetailParts(
|
|
||||||
[
|
|
||||||
joinDetailParts([!sameInfo && record.torrent.title.replace(/[, ]+/g, ' ') || undefined]),
|
|
||||||
joinDetailParts([titleInfo.title, titleInfo.year, titleInfo.language]),
|
|
||||||
joinDetailParts([titleInfo.resolution, titleInfo.source], '📺 '),
|
|
||||||
joinDetailParts([record.torrent.seeders], '👤 ')
|
|
||||||
],
|
|
||||||
'',
|
|
||||||
'\n'
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
|
||||||
name: `${ADDON_NAME}\n${record.torrent.provider}`,
|
|
||||||
title: title,
|
|
||||||
infoHash: record.infoHash,
|
|
||||||
fileIdx: record.fileIndex
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function seriesStream(record) {
|
|
||||||
const tInfo = titleParser.parse(record.title);
|
|
||||||
const eInfo = titleParser.parse(record.torrent.title);
|
|
||||||
const sameInfo = record.title === record.torrent.title ||
|
|
||||||
tInfo.season === eInfo.season && tInfo.episode && eInfo.episode === tInfo.episode;
|
|
||||||
const title = joinDetailParts(
|
const title = joinDetailParts(
|
||||||
[
|
[
|
||||||
joinDetailParts([record.torrent.title.replace(/[, ]+/g, ' ')]),
|
joinDetailParts([record.torrent.title.replace(/[, ]+/g, ' ')]),
|
||||||
joinDetailParts([!sameInfo && record.title.replace(/[, ]+/g, ' ') || undefined]),
|
joinDetailParts([!sameInfo && record.title.replace(/[, ]+/g, ' ') || undefined]),
|
||||||
joinDetailParts([
|
joinDetailParts([formatSize(record.size), record.torrent.provider], '⚙️️ '),
|
||||||
tInfo.resolution || eInfo.resolution || record.torrent.resolution,
|
|
||||||
tInfo.source || eInfo.source
|
|
||||||
], '📺 '),
|
|
||||||
joinDetailParts([record.torrent.seeders], '👤 ')
|
joinDetailParts([record.torrent.seeders], '👤 ')
|
||||||
],
|
],
|
||||||
'',
|
'',
|
||||||
'\n'
|
'\n'
|
||||||
);
|
);
|
||||||
|
const name = joinDetailParts(
|
||||||
|
[
|
||||||
|
joinDetailParts([ADDON_NAME]),
|
||||||
|
joinDetailParts([
|
||||||
|
fileInfo.resolution ||
|
||||||
|
torrentInfo.resolution ||
|
||||||
|
record.torrent.resolution ||
|
||||||
|
fileInfo.source ||
|
||||||
|
torrentInfo.source
|
||||||
|
])
|
||||||
|
],
|
||||||
|
'',
|
||||||
|
'\n'
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: `${ADDON_NAME}\n${record.torrent.provider}`,
|
name: name,
|
||||||
title: title,
|
title: title,
|
||||||
infoHash: record.infoHash,
|
infoHash: record.infoHash,
|
||||||
fileIdx: record.fileIndex
|
fileIdx: record.fileIndex
|
||||||
@@ -65,4 +47,12 @@ function joinDetailParts(parts, prefix = '', delimiter = ' ') {
|
|||||||
return filtered.length > 0 ? `${prefix}${filtered}` : undefined;
|
return filtered.length > 0 ? `${prefix}${filtered}` : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatSize(size) {
|
||||||
|
if (size === UNKNOWN_SIZE) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const i = size === 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
|
||||||
|
return Number((size / Math.pow(1024, i)).toFixed(2)) + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = { toStreamInfo };
|
module.exports = { toStreamInfo };
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ async function applyMoch(streams, apiKey) {
|
|||||||
const cachedEntry = available[stream.infoHash];
|
const cachedEntry = available[stream.infoHash];
|
||||||
const cachedIds = getCachedFileIds(stream.fileIdx, cachedEntry).join(',');
|
const cachedIds = getCachedFileIds(stream.fileIdx, cachedEntry).join(',');
|
||||||
if (cachedIds.length) {
|
if (cachedIds.length) {
|
||||||
stream.name = `[RD Cached]\n${stream.name}`;
|
stream.name = `[RD+] ${stream.name}`;
|
||||||
stream.url = `${RESOLVER_HOST}/realdebrid/${apiKey}/${stream.infoHash}/${cachedIds}/${stream.fileIdx}`;
|
stream.url = `${RESOLVER_HOST}/realdebrid/${apiKey}/${stream.infoHash}/${cachedIds}/${stream.fileIdx}`;
|
||||||
delete stream.infoHash;
|
delete stream.infoHash;
|
||||||
delete stream.fileIndex;
|
delete stream.fileIndex;
|
||||||
|
|||||||
Reference in New Issue
Block a user