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:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user