Skip to content

Commit

Permalink
improvement to season/episode handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBeastLT committed Jan 27, 2025
1 parent c4b4999 commit ea4ab26
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ exports.addDefaults = /** @type Parser */ parser => {
parser.addHandler("audio", /\b5\.1ch\b/i, value("ac3"), { remove: true, skipIfAlreadyFound: false });
parser.addHandler("audio", /\bDD5[. ]?1\b/i, value("dd5.1"), { remove: true });
parser.addHandler("audio", /\bQ?AAC(?:[. ]?2[. ]0|x2)?\b/, value("aac"), { remove: true });
parser.addHandler("audioChannels", /\[[257][.-][01]]/, lowercase, { remove: true });

// Group
parser.addHandler("group", /- ?(?!\d+$|S\d+|\d+x|ep?\d+|[^[]+]$)([^\-. []+[^\-. [)\]\d][^\-. [)\]]*)(?:\[[\w.-]+])?(?=\.\w{2,4}$|$)/i, { remove: true });
Expand Down Expand Up @@ -176,7 +177,8 @@ exports.addDefaults = /** @type Parser */ parser => {
parser.addHandler("seasons", /[Сс]езон:?[. _]??(\d{1,2})(?!\d)/i, array(integer));
parser.addHandler("seasons", /(?:\D|^)(\d{1,2})Â?[°ºªa]?[. ]*temporada/i, array(integer), { remove: true });
parser.addHandler("seasons", /t(\d{1,3})(?:[ex]+|$)/i, array(integer), { remove: true });
parser.addHandler("seasons", /(?:(?:\bthe\W)?\bcomplete)?(?:\W|^)so?(\d{1,3})(?:[\Wex]|\d{2}\b|$)/i, array(integer), { skipIfAlreadyFound: false });
parser.addHandler("seasons", /(?:(?:\bthe\W)?\bcomplete)?(?:\W|^)so?([01]?[0-5]?[1-9])(?:[\Wex]|\d{2}\b)/i, array(integer), { skipIfAlreadyFound: false });
parser.addHandler("seasons", /(?:so?|t)(\d{1,2})[. ]?[xх-]?[. ]?(?:e|x|х|ep|-|\.)[. ]?\d{1,4}(?:[abc]|v0?[1-4]|\D|$)/i, array(integer));
parser.addHandler("seasons", /(?:(?:\bthe\W)?\bcomplete\W)?(?:\W|^)(\d{1,2})[. ]?(?:st|nd|rd|th)[. ]*season/i, array(integer));
parser.addHandler("seasons", /(?:\D|^)(\d{1,2})[Xxх]\d{1,3}(?:\D|$)/, array(integer));
parser.addHandler("seasons", /\bSn([1-9])(?:\D|$)/, array(integer));
Expand All @@ -201,7 +203,7 @@ exports.addDefaults = /** @type Parser */ parser => {
parser.addHandler("episodes", /(?:[\W\d]|^)(?:episodes?|[Сс]ерии:?)[ .]?[([]?(\d{1,3}(?:[ .+]*[&+][ .]?\d{1,3})+)(?:\W|$)/i, range);
parser.addHandler("episodes", /[([]?(?:\D|^)(\d{1,3}[ .]?ao[ .]?\d{1,3})[)\]]?(?:\W|$)/i, range);
parser.addHandler("episodes", /(?:[\W\d]|^)(?:e|eps?|episodes?|[Сс]ерии:?|\d+[xх])[ .]*[([]?(\d{1,3}(?:-\d{1,3})+)(?:\W|$)/i, range);
parser.addHandler("episodes", /(?:\W|^)(?:so?|t)\d{1,2}[. ]?[xх-]?[. ]?(?:e|x|х|ep|-|\.)[. ]?(\d{1,4})(?:[abc]|v0?[1-4]|\D|$)/i, array(integer));
parser.addHandler("episodes", /(?:so?|t)\d{1,2}[. ]?[xх-]?[. ]?(?:e|x|х|ep|-|\.)[. ]?(\d{1,4})(?:[abc]|v0?[1-4]|\D|$)/i, array(integer));
parser.addHandler("episodes", /\b(?:so?|t)\d{2}(\d{2})\b/i, array(integer));
parser.addHandler("episodes", /(?:\W|^)(\d{1,3}(?:[ .]*~[ .]*\d{1,3})+)(?:\W|$)/i, range);
parser.addHandler("episodes", /-\s(\d{1,3}[ .]*-[ .]*\d{1,3})(?!-\d)(?:\W|$)/i, range);
Expand Down Expand Up @@ -266,6 +268,7 @@ exports.addDefaults = /** @type Parser */ parser => {
parser.addHandler("complete", /(?:\bthe\W)?\bultimate\b[ .]\bcollection\b/i, boolean, { skipIfAlreadyFound: false });
parser.addHandler("complete", /\bcollection\b.*\b(?:set|pack|movies)\b/i, boolean);
parser.addHandler("complete", /\b(collection|completa)\b/i, boolean, { skipFromTitle: true });
parser.addHandler("complete", /\bkolekcja\b(?:\Wfilm(?:y|ów|ow)?)?/i, boolean, { remove: true });
parser.addHandler("complete", /duology|trilogy|quadr[oi]logy|tetralogy|pentalogy|hexalogy|heptalogy|anthology|saga/i, boolean, { skipIfAlreadyFound: false });

// Language
Expand Down
2 changes: 1 addition & 1 deletion src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const RUSSIAN_CAST_REGEX = new RegExp("\\([^)]*[\u0400-\u04ff][^)]*\\)$|(?<=\\/.
const ALT_TITLES_REGEX = new RegExp(`[^/|(]*[${NON_ENGLISH_CHARS}][^/|]*[/|]|[/|][^/|(]*[${NON_ENGLISH_CHARS}][^/|]*`, "g");
const NOT_ONLY_NON_ENGLISH_REGEX = new RegExp(`(?<=[a-zA-Z][^${NON_ENGLISH_CHARS}]+)[${NON_ENGLISH_CHARS}].*[${NON_ENGLISH_CHARS}]|[${NON_ENGLISH_CHARS}].*[${NON_ENGLISH_CHARS}](?=[^${NON_ENGLISH_CHARS}]+[a-zA-Z])`, "g");
const NOT_ALLOWED_SYMBOLS_AT_START_AND_END = new RegExp(`^[^\\w${NON_ENGLISH_CHARS}#[【★]+|[ \\-:/\\\\[|{(#$&^]+$`, "g");
const REMAINING_NOT_ALLOWED_SYMBOLS_AT_START_AND_END = new RegExp(`^[^\\w${NON_ENGLISH_CHARS}#]+|]$`, "g");
const REMAINING_NOT_ALLOWED_SYMBOLS_AT_START_AND_END = new RegExp(`^[^\\w${NON_ENGLISH_CHARS}#]+|[[\\]({} ]+$`, "g");

function extendOptions(options) {
options = options || {};
Expand Down
5 changes: 5 additions & 0 deletions test/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,9 @@ describe("Parsing complete collection", () => {
const releaseName = "[Erai-raws] Ninja Collection - 05 [720p][Multiple Subtitle].mkv";
expect(parse(releaseName)).to.deep.include({ title: "Ninja Collection", complete: true });
});

it("should not remove kolekcja from title", () => {
const releaseName = "Kolekcja Halloween (1978-2022) [720p] [BRRip] [XviD] [AC3-ELiTE] [Lektor PL]";
expect(parse(releaseName)).to.deep.include({ title: "Halloween", complete: true });
});
});
38 changes: 37 additions & 1 deletion test/episode.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,43 @@ describe("Parsing episode", () => {

it("should not detect season.episode pattern when it's a date without other pattern", () => {
const releaseName = "wwf.raw.is.war.18.09.00.avi";
expect(parse(releaseName)).to.not.have.property("season");
expect(parse(releaseName)).to.not.have.property("seasons");
expect(parse(releaseName)).to.not.have.property("episode");
});

it("should not detect episodes when it's 2.0 sound", () => {
const releaseName = "The Rat Race (1960) [1080p] [WEB-DL] [x264] [DD] [2-0] [DReaM] [LEKTOR PL]";
expect(parse(releaseName)).to.not.have.property("seasons");
expect(parse(releaseName)).to.not.have.property("episodes");
});

it("should not detect episodes when it's 2.0 sound v2", () => {
const releaseName = "Avatar 2009 [1080p.BDRip.x264.AC3-azjatycki] [2.0] [Lektor PL]";
expect(parse(releaseName)).to.not.have.property("seasons");
expect(parse(releaseName)).to.not.have.property("episodes");
});

it("should not detect episodes when it's 5.1 sound", () => {
const releaseName = "A Quiet Place: Day One (2024) [1080p] [WEB-DL] [x264] [AC3] [DD] [5-1] [LEKTOR PL]";
expect(parse(releaseName)).to.not.have.property("seasons");
expect(parse(releaseName)).to.not.have.property("episodes");
});

it("should not detect episodes when it's 5.1 sound v2", () => {
const releaseName = "Avatar 2009 [1080p.BDRip.x264.AC3-azjatycki] [5.1] [Lektor PL]";
expect(parse(releaseName)).to.not.have.property("seasons");
expect(parse(releaseName)).to.not.have.property("episodes");
});

it("should not detect episodes when it's 7.1 sound", () => {
const releaseName = "Frequency (2000) [1080p] [BluRay] [REMUX] [AVC] [DTS] [HD] [MA] [7-1] [MR]";
expect(parse(releaseName)).to.not.have.property("seasons");
expect(parse(releaseName)).to.not.have.property("episodes");
});

it("should not detect episodes when it's 7.1 sound v2", () => {
const releaseName = "Avatar 2009 [1080p.BDRip.x264.AC3-azjatycki] [7.1] [Lektor PL]";
expect(parse(releaseName)).to.not.have.property("seasons");
expect(parse(releaseName)).to.not.have.property("episodes");
});
});
25 changes: 25 additions & 0 deletions test/season.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ describe("Parsing season", () => {
expect(parse(releaseName)).to.deep.include({ season: 1 });
});

it("should detect regular season with high number", () => {
const releaseName = "48 Hours S51E15 720p WEB x264-CookieMonster";
expect(parse(releaseName)).to.deep.include({ season: 51 });
});

it("should detect regular season with high number v2", () => {
const releaseName = "Bargain.Hunt.S66E02.Builth Wells4.720p.WEB.H264-BeechyBoy.mp4";
expect(parse(releaseName)).to.deep.include({ season: 66 });
});

it("should detect regular season with O instead of zero", () => {
const releaseName = "Arrested Development SO2E04.avi";
expect(parse(releaseName)).to.deep.include({ season: 2 });
Expand Down Expand Up @@ -523,8 +533,23 @@ describe("Parsing season", () => {
expect(parse(releaseName)).to.deep.include({ seasons: [1, 2, 3, 4, 5, 6, 7] });
});

it("should detect season episode when not in boundary", () => {
const releaseName = "Those.About.to.DieS01E06.MULTi.720p.AMZN.WEB-DL.H264.DDP5.1-K83.mkv";
expect(parse(releaseName)).to.deep.include({ seasons: [1], episodes: [6] });
});

it("should not detect season when it's part of the name", () => {
const releaseName = "Ranma-12-86.mp4";
expect(parse(releaseName)).to.not.have.property("season");
});

it("should not detect season when it's part of group", () => {
const releaseName = "The Killer's Game 2024 PL 1080p WEB-DL H264 DD5.1-S56";
expect(parse(releaseName)).to.not.have.property("season");
});

it("should not detect season when it's part of group v2", () => {
const releaseName = "Apollo 13 (1995) [1080p] [WEB-DL] [x264] [E-AC3-S78] [Lektor PL]";
expect(parse(releaseName)).to.not.have.property("season");
});
});

0 comments on commit ea4ab26

Please sign in to comment.