Skip to content

Commit

Permalink
improve anime episode parsing when title contains numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBeastLT committed Jul 8, 2024
1 parent d29c6c7 commit dff7654
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ exports.addDefaults = /** @type Parser */ parser => {
const middleTitle = title.slice(startIndex, endIndex);

// try to match the episode inside the title with a separator, if not found include the start of the title as well
const matches = beginningTitle.match(/(?<!movie\W*|film\W*|^)(?:[ .]+-[ .]+|[([][ .]*)(\d{1,4})(?:a|b|v\d)?(?:\W|$)(?!movie|film)/i) ||
const matches = Array.from(beginningTitle.matchAll(/(?<!movie\W*|film\W*|^)(?:[ .]+-[ .]+|[([][ .]*)(\d{1,4})(?:a|b|v\d|\.\d)?(?:\W|$)(?!movie|film|\d+)/gi)).pop() ||
middleTitle.match(/^(?:[([-][ .]?)?(\d{1,4})(?:a|b|v\d)?(?:\W|$)(?!movie|film)/i);

if (matches) {
Expand Down
5 changes: 5 additions & 0 deletions test/episode.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,11 @@ describe("Parsing episode", () => {
expect(parse(releaseName)).to.deep.include({ episode: 35 });
});

it("should detect anime episode with hyphen number in title", () => {
const releaseName = "[SubsPlease] Fairy Tail - 100 Years Quest - 05 (1080p) [1107F3A9].mkv";
expect(parse(releaseName)).to.deep.include({ episode: 5 });
});

it("should detect anime episode recap episode", () => {
const releaseName = "[KH] Sword Art Online II - 14.5 - Debriefing.mkv";
expect(parse(releaseName)).to.deep.include({ episode: 14 });
Expand Down

0 comments on commit dff7654

Please sign in to comment.