mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[addon] adds initial version for languages visualization
This commit is contained in:
@@ -82,9 +82,9 @@ function filterByProvider(streams, providers) {
|
||||
return streams;
|
||||
}
|
||||
return streams.filter(stream => {
|
||||
const parts = stream.title.split('\n');
|
||||
const provider = parts[parts.length - 2].match(/\w+$/)[0];
|
||||
return providers.includes(provider.toLowerCase());
|
||||
const match = stream.title.match(/[🛈⚙].* ([^ \n]+)/);
|
||||
const provider = match && match[1].toLowerCase();
|
||||
return providers.includes(provider);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
45
addon/lib/languages.js
Normal file
45
addon/lib/languages.js
Normal file
@@ -0,0 +1,45 @@
|
||||
const languageMapping = {
|
||||
'dubbed': 'Dubbed',
|
||||
'multi': 'Multi',
|
||||
'english': '🇬🇧',
|
||||
'japanese': '🇯🇵',
|
||||
'korean': '🇰🇷',
|
||||
'chinese': '🇨🇳',
|
||||
'french': '🇫🇷',
|
||||
'german': '🇩🇪',
|
||||
'dutch': '🇳🇱',
|
||||
'portuguese': '🇵🇹',
|
||||
'spanish': '🇪🇸',
|
||||
'italian': '🇮🇹',
|
||||
'russian': '🇷🇺',
|
||||
'hindi': '🇮🇳',
|
||||
'telugu': '🇮🇳',
|
||||
'tamil': '🇮🇳',
|
||||
'polish': '🇵🇱',
|
||||
'lithuanian': '🇱🇹',
|
||||
'czech': '🇨🇿',
|
||||
'hungarian': '🇭🇺',
|
||||
'romanian': '🇷🇴',
|
||||
'croatian': '🇭🇷',
|
||||
'greek': '🇬🇷',
|
||||
'danish': '🇩🇰',
|
||||
'finnish': '🇫🇮',
|
||||
'swedish': '🇸🇪',
|
||||
'norwegian': '🇳🇴',
|
||||
'turkish': '🇹🇷',
|
||||
'arabic': '🇸🇦',
|
||||
'hebrew': '🇮🇱'
|
||||
}
|
||||
|
||||
function mapLanguages(languages) {
|
||||
const mapped = languages
|
||||
.map(language => languageMapping[language])
|
||||
.filter(language => language)
|
||||
.sort((a, b) => Object.values(languageMapping).indexOf(a) - Object.values(languageMapping).indexOf(b));
|
||||
const unmapped = languages
|
||||
.filter(language => !languageMapping[language])
|
||||
.sort((a, b) => a.localeCompare(b))
|
||||
return [...new Set([].concat(mapped).concat(unmapped))];
|
||||
}
|
||||
|
||||
module.exports = { mapLanguages }
|
||||
@@ -1,4 +1,6 @@
|
||||
const titleParser = require('parse-torrent-title');
|
||||
const { Type } = require('./types');
|
||||
const { mapLanguages } = require('./languages');
|
||||
|
||||
const ADDON_NAME = 'Torrentio';
|
||||
const UNKNOWN_SIZE = 300000000;
|
||||
@@ -12,8 +14,12 @@ function toStreamInfo(record) {
|
||||
[
|
||||
joinDetailParts([record.torrent.title.replace(/[, ]+/g, ' ')]),
|
||||
joinDetailParts([!sameInfo && record.title.replace(/[, ]+/g, ' ') || undefined]),
|
||||
joinDetailParts([formatSize(record.size), record.torrent.provider], '⚙️️ '),
|
||||
joinDetailParts([record.torrent.seeders], '👤 ')
|
||||
joinDetailParts([
|
||||
joinDetailParts([record.torrent.seeders], '👤 '),
|
||||
joinDetailParts([formatSize(record.size)], '💾 '),
|
||||
joinDetailParts([record.torrent.provider], '🛈 ')
|
||||
]),
|
||||
joinDetailParts(getLanguages(record, torrentInfo, fileInfo), '', ' / '),
|
||||
],
|
||||
'',
|
||||
'\n'
|
||||
@@ -21,7 +27,7 @@ function toStreamInfo(record) {
|
||||
const name = joinDetailParts(
|
||||
[
|
||||
joinDetailParts([ADDON_NAME]),
|
||||
joinDetailParts([getQuality(record, fileInfo, torrentInfo)])
|
||||
joinDetailParts([getQuality(record, torrentInfo, fileInfo)])
|
||||
],
|
||||
'',
|
||||
'\n'
|
||||
@@ -35,7 +41,7 @@ function toStreamInfo(record) {
|
||||
};
|
||||
}
|
||||
|
||||
function getQuality(record, fileInfo, torrentInfo) {
|
||||
function getQuality(record, torrentInfo, fileInfo) {
|
||||
const resolution = fileInfo.resolution || torrentInfo.resolution || record.torrent.resolution;
|
||||
const source = fileInfo.source || torrentInfo.source;
|
||||
if (['CAM', 'TeleSync'].includes(source)) {
|
||||
@@ -44,6 +50,24 @@ function getQuality(record, fileInfo, torrentInfo) {
|
||||
return resolution || source;
|
||||
}
|
||||
|
||||
function getLanguages(record, torrentInfo, fileInfo) {
|
||||
const providerLanguages = record.torrent.languages && titleParser.parse(record.torrent.languages).languages || [];
|
||||
const torrentLanguages = torrentInfo.languages || [];
|
||||
let languages = [].concat(torrentLanguages).concat(providerLanguages);
|
||||
if (record.kitsuId || record.torrent.type === Type.ANIME) {
|
||||
const dubbed = torrentInfo.dubbed || fileInfo.dubbed || languages.includes('multi');
|
||||
// no need to display japanese for anime or english if anime is dubbed
|
||||
languages = languages.concat(dubbed ? ['dubbed'] : [])
|
||||
.filter(lang => lang !== 'japanese')
|
||||
.filter(lang => dubbed && lang !== 'english' || !dubbed);
|
||||
}
|
||||
if (languages.length === 1 && languages.includes('english')) {
|
||||
// no need to display languages if only english is present
|
||||
languages = [];
|
||||
}
|
||||
return mapLanguages(languages);
|
||||
}
|
||||
|
||||
function joinDetailParts(parts, prefix = '', delimiter = ' ') {
|
||||
const filtered = parts.filter((part) => part !== undefined && part !== null).join(delimiter);
|
||||
|
||||
|
||||
4
addon/package-lock.json
generated
4
addon/package-lock.json
generated
@@ -1599,8 +1599,8 @@
|
||||
}
|
||||
},
|
||||
"parse-torrent-title": {
|
||||
"version": "git://github.com/TheBeastLT/parse-torrent-title.git#f69da3adba502690dfdef8ab4f1d188f0d6077cb",
|
||||
"from": "git://github.com/TheBeastLT/parse-torrent-title.git#f69da3adba502690dfdef8ab4f1d188f0d6077cb",
|
||||
"version": "git://github.com/TheBeastLT/parse-torrent-title.git#86dc66fc3b05d798f400d3a457720890dced4901",
|
||||
"from": "git://github.com/TheBeastLT/parse-torrent-title.git#86dc66fc3b05d798f400d3a457720890dced4901",
|
||||
"requires": {
|
||||
"moment": "^2.24.0"
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"named-queue": "^2.2.1",
|
||||
"needle": "^2.2.4",
|
||||
"magnet-uri": "^5.1.7",
|
||||
"parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#f69da3adba502690dfdef8ab4f1d188f0d6077cb",
|
||||
"parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#86dc66fc3b05d798f400d3a457720890dced4901",
|
||||
"pg": "^7.8.2",
|
||||
"pg-hstore": "^2.3.2",
|
||||
"real-debrid-api": "git://github.com/TheBeastLT/node-real-debrid.git#935a5c23ae809edbcd2a111526a7f74d6767c50d",
|
||||
|
||||
Reference in New Issue
Block a user