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) {
|
||||
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();
|
||||
|
||||
@@ -33,7 +33,7 @@ function sortBySeeders(streams) {
|
||||
function sortByVideoQuality(streams, limit) {
|
||||
const qualityMap = sortBySeeders(streams)
|
||||
.reduce((map, stream) => {
|
||||
const quality = extractQuality(stream.title);
|
||||
const quality = extractQuality(stream.name);
|
||||
map[quality] = (map[quality] || []).concat(stream);
|
||||
return map;
|
||||
}, {});
|
||||
@@ -56,8 +56,7 @@ function sortByVideoQuality(streams, limit) {
|
||||
}
|
||||
|
||||
function extractQuality(title) {
|
||||
const qualityMatch = title.match(/📺 (.*)/);
|
||||
const qualityDesc = qualityMatch && qualityMatch[1];
|
||||
const qualityDesc = title.split('\n')[1];
|
||||
const resolutionMatch = qualityDesc && qualityDesc.match(/\d+p/);
|
||||
if (resolutionMatch) {
|
||||
return resolutionMatch[0];
|
||||
|
||||
@@ -1,58 +1,40 @@
|
||||
const titleParser = require('parse-torrent-title');
|
||||
const { Type } = require('./types');
|
||||
|
||||
const ADDON_NAME = 'Torrentio';
|
||||
const UNKNOWN_SIZE = 300000000;
|
||||
|
||||
function toStreamInfo(record) {
|
||||
if (record.torrent.type === Type.MOVIE) {
|
||||
return movieStream(record);
|
||||
}
|
||||
return seriesStream(record);
|
||||
}
|
||||
|
||||
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 torrentInfo = titleParser.parse(record.torrent.title);
|
||||
const fileInfo = titleParser.parse(record.title);
|
||||
const sameInfo = !Number.isInteger(record.fileIndex)
|
||||
|| record.size !== UNKNOWN_SIZE && record.size === record.torrent.size;
|
||||
const title = joinDetailParts(
|
||||
[
|
||||
joinDetailParts([record.torrent.title.replace(/[, ]+/g, ' ')]),
|
||||
joinDetailParts([!sameInfo && record.title.replace(/[, ]+/g, ' ') || undefined]),
|
||||
joinDetailParts([
|
||||
tInfo.resolution || eInfo.resolution || record.torrent.resolution,
|
||||
tInfo.source || eInfo.source
|
||||
], '📺 '),
|
||||
joinDetailParts([formatSize(record.size), record.torrent.provider], '⚙️️ '),
|
||||
joinDetailParts([record.torrent.seeders], '👤 ')
|
||||
],
|
||||
'',
|
||||
'\n'
|
||||
);
|
||||
const name = joinDetailParts(
|
||||
[
|
||||
joinDetailParts([ADDON_NAME]),
|
||||
joinDetailParts([
|
||||
fileInfo.resolution ||
|
||||
torrentInfo.resolution ||
|
||||
record.torrent.resolution ||
|
||||
fileInfo.source ||
|
||||
torrentInfo.source
|
||||
])
|
||||
],
|
||||
'',
|
||||
'\n'
|
||||
);
|
||||
|
||||
return {
|
||||
name: `${ADDON_NAME}\n${record.torrent.provider}`,
|
||||
name: name,
|
||||
title: title,
|
||||
infoHash: record.infoHash,
|
||||
fileIdx: record.fileIndex
|
||||
@@ -65,4 +47,12 @@ function joinDetailParts(parts, prefix = '', delimiter = ' ') {
|
||||
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 };
|
||||
|
||||
@@ -16,7 +16,7 @@ async function applyMoch(streams, apiKey) {
|
||||
const cachedEntry = available[stream.infoHash];
|
||||
const cachedIds = getCachedFileIds(stream.fileIdx, cachedEntry).join(',');
|
||||
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}`;
|
||||
delete stream.infoHash;
|
||||
delete stream.fileIndex;
|
||||
|
||||
Reference in New Issue
Block a user