Parse multiple season packs
roblav96 opened this issue · comments
A problem I've been tussling with lately is being able to parse the amount of seasons from a magnet's name.
Examples:
s2to 9
s2 and 9
s2 &9
s1-s2
s1 - s2
season2 season 4
season2-4
season 2
season 1, 2, 3, 4, 5 & 6
season 1 2 3 4 5 6
season 1 - 3
season 1 3
season 1-3
season 1 3
seasons 1-3
seasons 1 to 3
3rd season
fresh prince of bel air season 2 3 4 5 6
So far I've come up with this:
export const regex = {
/** `1st season` */
nthseason(item: media.Item, slug: string) {
let matches = slug.match(/\s\d{1,2}[a-z]{2}\sseason\s/gi)
matches = (matches || []).map(v => v.trim())
let seasons = matches.map(v => utils.parseInt(v))
if (seasons.includes(item.S.n)) return true
},
/** `season one` */
season(item: media.Item, slug: string) {
let nstrs = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']
let matches = slug.match(
/\ss(eason)?\s(one|two|three|four|five|six|seven|eight|nine|ten)\s/gi
)
matches = (matches || []).map(v => v.trim())
let nstr = matches.map(v => v.split(' ').pop())[0]
let index = nstrs.findIndex(v => v == nstr) + 1
if (item.S.n == index) return true
},
/** `seasons 1 - 2` */
seasons0to(item: media.Item, slug: string) {
slug = slug.replace(/(through)|(and)|(to)/gi, ' ').replace(/\s+/g, ' ')
let matches = [
slug.match(/\s?s(eason(s)?)?\s?\d{1,2}\s?s?(eason)?(\s?\d{1,2}\s)+/gi) || [],
slug.match(/\s?s(eason)?\s?\d{1,2}\s/gi) || [],
].flat()
matches = (matches || []).map(v => v.trim())
matches = matches.join(' ').split(' ')
let ints = matches.map(utils.parseInt).filter(v => _.isInteger(v) && v < 100)
let { min, max } = { min: _.min(ints), max: _.max(ints) }
if (item.S.n >= min && item.S.n <= max) {
return max - min + 1
}
},
}
It's definitely not very reliable and I was wondering what your input might be.
It looks like guessit can parse some styles
❯ guessit "Life S01-S02 WEBRip 1080p DD5 1 H265-d3g"
For: Life S01-S02 WEBRip 1080p DD5 1 H265-d3g
GuessIt found: {
"title": "Life",
"season": [
1,
2
],
"source": "Web",
"other": "Rip",
"screen_size": "1080p",
"audio_codec": "Dolby Digital",
"audio_channels": "5.1",
"video_codec": "H.265",
"release_group": "d3g",
"type": "episode"
}
❯ guessit "Life season 1, 2, 3, 4, 5 & 6 WEBRip 1080p DD5 1 H265-d3g"
For: Life season 1, 2, 3, 4, 5 & 6 WEBRip 1080p DD5 1 H265-d3g
GuessIt found: {
"title": "Life",
"season": [
1,
2,
3,
4,
5,
6
],
"source": "Web",
"other": "Rip",
"screen_size": "1080p",
"audio_codec": "Dolby Digital",
"audio_channels": "5.1",
"video_codec": "H.265",
"release_group": "d3g",
"type": "episode"
}
stuff like Life S01-S02 WEBRip 1080p DD5 1 H265-d3g
is parsed in the latest version using the tv flag, not sure how far this project would ever go into parsing packs