mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
[scraper] improves title based decomposer
This commit is contained in:
@@ -3,8 +3,7 @@
|
||||
"version": "1.0.0",
|
||||
"main": "addon.js",
|
||||
"scripts": {
|
||||
"start": "node index.js",
|
||||
"deploy": "now && now alias"
|
||||
"start": "node index.js"
|
||||
},
|
||||
"author": "TheBeastLT <pauliox@beyond.lt>",
|
||||
"license": "MIT",
|
||||
@@ -13,10 +12,10 @@
|
||||
"cache-manager-mongodb": "^0.2.1",
|
||||
"express-rate-limit": "^5.1.1",
|
||||
"parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#master",
|
||||
"stremio-addon-sdk": "^1.6.1",
|
||||
"pg": "^7.8.2",
|
||||
"pg-hstore": "^2.3.2",
|
||||
"sequelize": "^4.43.0"
|
||||
"sequelize": "^4.43.0",
|
||||
"stremio-addon-sdk": "^1.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^6.4.0",
|
||||
|
||||
5
package-lock.json
generated
5
package-lock.json
generated
@@ -924,6 +924,11 @@
|
||||
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
|
||||
"integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
|
||||
},
|
||||
"jaro-winkler": {
|
||||
"version": "0.2.8",
|
||||
"resolved": "https://registry.npmjs.org/jaro-winkler/-/jaro-winkler-0.2.8.tgz",
|
||||
"integrity": "sha1-Zyfg0LcJHiQ2+TVt6b+I+tI+U0o="
|
||||
},
|
||||
"jsbn": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
"cheerio": "^0.22.0",
|
||||
"dotenv": "^8.2.0",
|
||||
"express": "^4.16.4",
|
||||
"jaro-winkler": "^0.2.8",
|
||||
"line-by-line": "^0.1.6",
|
||||
"magnet-uri": "^5.1.7",
|
||||
"moment": "^2.24.0",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const moment = require('moment');
|
||||
const distance = require('jaro-winkler');
|
||||
const { parse } = require('parse-torrent-title');
|
||||
const { torrentFiles } = require('../lib/torrent');
|
||||
const { getMetadata, getImdbId } = require('../lib/metadata');
|
||||
@@ -61,7 +62,8 @@ async function parseTorrentFiles(torrent) {
|
||||
}
|
||||
|
||||
async function getSeriesFiles(torrent, parsedTorrentName) {
|
||||
if (parsedTorrentName.episode || (!parsedTorrentName.episodes && parsedTorrentName.date)) {
|
||||
if ((parsedTorrentName.episode && (!parsedTorrentName.seasons || parsedTorrentName.seasons.length <= 1)) ||
|
||||
(!parsedTorrentName.episodes && parsedTorrentName.date)) {
|
||||
return [{
|
||||
name: torrent.title,
|
||||
path: torrent.title,
|
||||
@@ -160,6 +162,7 @@ async function decomposeEpisodes(torrent, files, metadata = { episodeCount: [] }
|
||||
.every(ep => metadata.episodeCount[file.season - 1] < ep)).length > Math.ceil(files.length / 5)) {
|
||||
decomposeAbsoluteEpisodeFiles(torrent, files, metadata);
|
||||
}
|
||||
// decomposeEpisodeTitleFiles(torrent, files, metadata);
|
||||
|
||||
return files;
|
||||
}
|
||||
@@ -228,19 +231,17 @@ function decomposeDateEpisodeFiles(torrent, files, metadata) {
|
||||
}
|
||||
|
||||
function decomposeEpisodeTitleFiles(torrent, files, metadata) {
|
||||
const titleMapping = metadata.videos
|
||||
.reduce((map, video) => {
|
||||
map[video.name.toLowerCase()] = video;
|
||||
return map;
|
||||
}, {});
|
||||
files
|
||||
.filter(file => !file.season)
|
||||
.map(file => {
|
||||
const episodeTitle = file.name.replace(/^.*-\s?(.+)\.\w{1,4}$/, '$1').toLowerCase();
|
||||
const mapping = titleMapping[episodeTitle];
|
||||
if (mapping) {
|
||||
file.season = mapping.season;
|
||||
file.episodes = [mapping.episode];
|
||||
const episodeTitle = file.name.replace(/^.*-\s?(.+)\.\w{1,4}$/, '$1').trim();
|
||||
const foundEpisode = metadata.videos
|
||||
.map(video => ({ ...video, distance: distance(episodeTitle, video.name) }))
|
||||
.sort((a, b) => b.distance - a.distance)[0];
|
||||
if (foundEpisode) {
|
||||
file.isMovie = false;
|
||||
file.season = foundEpisode.season;
|
||||
file.episodes = [foundEpisode.episode];
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user