Skip to content

Commit

Permalink
improve anime episode parsing when anim title potentially contains nu…
Browse files Browse the repository at this point in the history
…mber range
  • Loading branch information
TheBeastLT committed Sep 17, 2024
1 parent dff7654 commit 7ef5191
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,14 @@ 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|^)[st]\d{1,2}[. ]?[xх-]?[. ]?(?:e|x|х|ep|-|\.)[. ]?(\d{1,3})(?:[abc]|v0?[1-4]|\D|$)/i, array(integer));
parser.addHandler("episodes", /(?:\W|^)[st]\d{1,2}[. ]?[xх-]?[. ]?(?:e|x|х|ep|-|\.)[. ]?(\d{1,4})(?:[abc]|v0?[1-4]|\D|$)/i, array(integer));
parser.addHandler("episodes", /\b[st]\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);
parser.addHandler("episodes", /s\d{1,2}\s?\((\d{1,3}[ .]*-[ .]*\d{1,3})\)/i, range);
parser.addHandler("episodes", /(?:^|\/)\d{1,2}-(\d{2})\b(?!-\d)/, array(integer));
parser.addHandler("episodes", /(?<!\d-)\b\d{1,2}-(\d{2})(?=\.\w{2,4}$)/, array(integer));
parser.addHandler("episodes", /(?<=^\[.+].+)[. ]+-[. ]+(\d{1,4})[. ]+(?=\W)/i, array(integer));
parser.addHandler("episodes", /(?<!(?:seasons?|[Сс]езони?)\W*)(?:[ .([-]|^)(\d{1,3}(?:[ .]?[,&+~][ .]?\d{1,3})+)(?:[ .)\]-]|$)/i, range);
parser.addHandler("episodes", /(?<!(?:seasons?|[Сс]езони?)\W*)(?:[ .([-]|^)(\d{1,3}(?:-\d{1,3})+)(?:[ .)(\]]|-\D|$)/i, range);
parser.addHandler("episodes", /\bEp(?:isode)?\W+\d{1,2}\.(\d{1,3})\b/i, array(integer));
Expand Down
10 changes: 10 additions & 0 deletions test/episode.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ describe("Parsing episode", () => {
expect(parse(releaseName)).to.deep.include({ episode: 23 });
});

it("should detect regular episode above 1000", () => {
const releaseName = "One.Piece.S01E1116.Lets.Go.Get.It!.Buggys.Big.Declaration.2160p.B-Global.WEB-DL.JPN.AAC2.0.H.264.MSubs-ToonsHub.mkv";
expect(parse(releaseName)).to.deep.include({ episode: 1116 });
});

it("should detect regular episode without e symbol after season", () => {
const releaseName = "The.Witcher.S01.07.2019.Dub.AVC.ExKinoRay.mkv";
expect(parse(releaseName)).to.deep.include({ episode: 7 });
Expand Down Expand Up @@ -282,6 +287,11 @@ describe("Parsing episode", () => {
expect(parse(releaseName)).to.deep.include({ episode: 4 });
});

it("should detect detect anime episode when title contains number range", () => {
const releaseName = "[Erai-raws] 2-5 Jigen no Ririsa - 08 [480p][Multiple Subtitle][972D0669].mkv";
expect(parse(releaseName)).to.deep.include({ episode: 8 });
});

it("should detect detect absolute episode with a version and ep suffix", () => {
const releaseName = "[Exiled-Destiny]_Tokyo_Underground_Ep02v2_(41858470).mkv";
expect(parse(releaseName)).to.deep.include({ episode: 2 });
Expand Down

0 comments on commit 7ef5191

Please sign in to comment.