[scraper] updates movie title to path

This commit is contained in:
TheBeastLT
2020-03-28 23:18:51 +01:00
parent 694f234cb2
commit 34486230ea
3 changed files with 11 additions and 10 deletions

4
package-lock.json generated
View File

@@ -1620,8 +1620,8 @@
} }
}, },
"parse-torrent-title": { "parse-torrent-title": {
"version": "git://github.com/TheBeastLT/parse-torrent-title.git#7597effa105bc1f0329a88aefea2291f2f7f11c1", "version": "git://github.com/TheBeastLT/parse-torrent-title.git#826ee1a8a832e8c18fcc0703f5b56a8b9acd4283",
"from": "git://github.com/TheBeastLT/parse-torrent-title.git#7597effa105bc1f0329a88aefea2291f2f7f11c1", "from": "git://github.com/TheBeastLT/parse-torrent-title.git#826ee1a8a832e8c18fcc0703f5b56a8b9acd4283",
"requires": { "requires": {
"moment": "^2.24.0" "moment": "^2.24.0"
} }

View File

@@ -32,7 +32,7 @@
"node-schedule": "^1.3.2", "node-schedule": "^1.3.2",
"nodejs-bing": "^0.1.0", "nodejs-bing": "^0.1.0",
"parse-torrent": "^6.1.2", "parse-torrent": "^6.1.2",
"parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#7597effa105bc1f0329a88aefea2291f2f7f11c1", "parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#826ee1a8a832e8c18fcc0703f5b56a8b9acd4283",
"peer-search": "^0.6.x", "peer-search": "^0.6.x",
"pg": "^7.8.2", "pg": "^7.8.2",
"pg-hstore": "^2.3.2", "pg-hstore": "^2.3.2",

View File

@@ -30,7 +30,7 @@ async function parseTorrentFiles(torrent) {
.then((newImdbId) => ({ .then((newImdbId) => ({
infoHash: torrent.infoHash, infoHash: torrent.infoHash,
fileIndex: file.fileIndex, fileIndex: file.fileIndex,
title: file.name, title: file.path || file.name,
size: file.size, size: file.size,
imdbId: newImdbId, imdbId: newImdbId,
}))))) })))))
@@ -113,7 +113,7 @@ async function mapSeriesMovie(file, torrent) {
return findMovieImdbId(file).then((imdbId) => [{ return findMovieImdbId(file).then((imdbId) => [{
infoHash: torrent.infoHash, infoHash: torrent.infoHash,
fileIndex: file.fileIndex, fileIndex: file.fileIndex,
title: file.name, title: file.path || file.name,
size: file.size, size: file.size,
imdbId: imdbId imdbId: imdbId
}]) }])
@@ -122,13 +122,14 @@ async function mapSeriesMovie(file, torrent) {
function parseSeriesFile(file, parsedTorrentName) { function parseSeriesFile(file, parsedTorrentName) {
const fileInfo = parse(file.name); const fileInfo = parse(file.name);
// the episode may be in a folder containing season number // the episode may be in a folder containing season number
if (!fileInfo.season && parsedTorrentName.season) { if (!fileInfo.season && file.path.includes('/')) {
fileInfo.season = parsedTorrentName.season;
} else if (!fileInfo.season && file.path.includes('/')) {
const folders = file.path.split('/'); const folders = file.path.split('/');
const pathInfo = parse(folders[folders.length - 2]); const pathInfo = parse(folders[folders.length - 2]);
fileInfo.season = pathInfo.season; fileInfo.season = pathInfo.season;
} }
if (!fileInfo.season && parsedTorrentName.season) {
fileInfo.season = parsedTorrentName.season;
}
// force episode to any found number if it was not parsed // force episode to any found number if it was not parsed
if (!fileInfo.episodes && !fileInfo.date) { if (!fileInfo.episodes && !fileInfo.date) {
const epMatcher = fileInfo.title.match(/(?<!movie\W*|film\W*)(?:^|\W)(\d{1,4})(?:a|b|v\d)?(?:\W|$)(?!movie|film)/i); const epMatcher = fileInfo.title.match(/(?<!movie\W*|film\W*)(?:^|\W)(\d{1,4})(?:a|b|v\d)?(?:\W|$)(?!movie|film)/i);
@@ -263,9 +264,9 @@ function decomposeDateEpisodeFiles(torrent, files, metadata) {
function decomposeEpisodeTitleFiles(torrent, files, metadata) { function decomposeEpisodeTitleFiles(torrent, files, metadata) {
files files
.filter(file => !file.season) // .filter(file => !file.season)
.map(file => { .map(file => {
const episodeTitle = file.name.replace(/^.*-\s?(.+)\.\w{1,4}$/, '$1').trim(); const episodeTitle = file.name.replace('_', ' ').replace(/^.*(?:E\d+[abc]?|-)\s?(.+)\.\w{1,4}$/, '$1').trim();
const foundEpisode = metadata.videos const foundEpisode = metadata.videos
.map(video => ({ ...video, distance: distance(episodeTitle, video.name) })) .map(video => ({ ...video, distance: distance(episodeTitle, video.name) }))
.sort((a, b) => b.distance - a.distance)[0]; .sort((a, b) => b.distance - a.distance)[0];