[scraper] fix season parse helper

This commit is contained in:
TheBeastLT
2021-03-20 23:30:33 +01:00
parent c7f353d176
commit a52e261cf7
3 changed files with 8 additions and 8 deletions

4
package-lock.json generated
View File

@@ -1870,8 +1870,8 @@
}
},
"parse-torrent-title": {
"version": "git://github.com/TheBeastLT/parse-torrent-title.git#17b332cbf678e8e784fd2727b0dee764ee429aac",
"from": "git://github.com/TheBeastLT/parse-torrent-title.git#17b332cbf678e8e784fd2727b0dee764ee429aac",
"version": "git://github.com/TheBeastLT/parse-torrent-title.git#ee4eec8169e4ad4ab10fe4f6bf205049ce5d0ddc",
"from": "git://github.com/TheBeastLT/parse-torrent-title.git#ee4eec8169e4ad4ab10fe4f6bf205049ce5d0ddc",
"requires": {
"moment": "^2.24.0"
}

View File

@@ -32,7 +32,7 @@
"nodejs-bing": "^0.1.0",
"nyaapi": "^2.3.3",
"parse-torrent": "^6.1.2",
"parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#17b332cbf678e8e784fd2727b0dee764ee429aac",
"parse-torrent-title": "git://github.com/TheBeastLT/parse-torrent-title.git#ee4eec8169e4ad4ab10fe4f6bf205049ce5d0ddc",
"pg": "^7.8.2",
"pg-hstore": "^2.3.2",
"real-debrid-api": "git://github.com/TheBeastLT/node-real-debrid.git#935a5c23ae809edbcd2a111526a7f74d6767c50d",

View File

@@ -12,21 +12,21 @@ function parseSeriesVideos(torrent, videos) {
function parseSeriesVideo(video, parsedTorrentName) {
const videoInfo = parse(video.name);
const hasSeason = Number.isInteger(videoInfo.season);
// the episode may be in a folder containing season number
if (!hasSeason && video.path.includes('/')) {
if (!Number.isInteger(videoInfo.season) && video.path.includes('/')) {
const folders = video.path.split('/');
const pathInfo = parse(folders[folders.length - 2]);
videoInfo.season = pathInfo.season;
}
if (!hasSeason && parsedTorrentName.season) {
if (!Number.isInteger(videoInfo.season) && parsedTorrentName.season) {
videoInfo.season = parsedTorrentName.season;
}
if (!hasSeason && videoInfo.seasons && videoInfo.seasons.length > 1) {
if (!Number.isInteger(videoInfo.season) && videoInfo.seasons && videoInfo.seasons.length > 1) {
// in case single file was interpreted as having multiple seasons
videoInfo.season = videoInfo.seasons[0];
}
if (!hasSeason && video.path.includes('/') && parsedTorrentName.seasons && parsedTorrentName.seasons.length > 1) {
if (!Number.isInteger(videoInfo.season) && video.path.includes('/') && parsedTorrentName.seasons
&& parsedTorrentName.seasons.length > 1) {
// russian season are usually named with 'series name-2` i.e. Улицы разбитых фонарей-6/22. Одиночный выстрел.mkv
const folderPathSeasonMatch = video.path.match(/[\u0400-\u04ff]-(\d{1,2})(?=.*\/)/);
videoInfo.season = folderPathSeasonMatch && parseInt(folderPathSeasonMatch[1], 10) || undefined;