Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/__tests__/trailingBracketEpisode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { parseTorrentTitle } from '../index';

function intRange(start: number, end: number): number[] {
const result: number[] = [];
for (let i = start; i <= end; i++) {
result.push(i);
}
return result;
}

// AniLiberty names end with the episodes in the last bracket group.
describe('parseTorrentTitle - trailing bracket episodes', () => {
test('Ледяная стена / Koori no Jouheki / 2026 / [WEB-DL 1080p][AVC][1]', () => {
const result = parseTorrentTitle(
'Ледяная стена / Koori no Jouheki / 2026 / [WEB-DL 1080p][AVC][1]'
);
expect(result.episodes).toEqual([1]);
expect(result.resolution).toBe('1080p');
});

test('Блич / Bleach / 2004 / [BDRip 1080p][HEVC][347]', () => {
const result = parseTorrentTitle(
'Блич / Bleach / 2004 / [BDRip 1080p][HEVC][347]'
);
expect(result.episodes).toEqual([347]);
});

test('Магическая битва 2 / JUJUTSU KAISEN Season 2 / 2023 / [WEBRip 1080p][AVC][1-23]', () => {
const result = parseTorrentTitle(
'Магическая битва 2 / JUJUTSU KAISEN Season 2 / 2023 / [WEBRip 1080p][AVC][1-23]'
);
expect(result.seasons).toEqual([2]);
expect(result.episodes).toEqual(intRange(1, 23));
});
test('a year in the last bracket is not an episode', () => {
const result = parseTorrentTitle('Сериал / Show [WEB-DL 1080p][2023]');
expect(result.episodes).toBeUndefined();
expect(result.year).toBe('2023');
});

test('a bit depth group at the end is not an episode', () => {
const result = parseTorrentTitle('Show Name [1080p][x265][10bit]');
expect(result.episodes).toBeUndefined();
});
});
7 changes: 7 additions & 0 deletions src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,13 @@ export const handlers: Handler[] = [
),
transform: toIntArray()
},
{
field: 'episodes',
// AniLiberty ends the name with the episodes: "/ 2026 / [WEB-DL 1080p][AVC][1]",
// "[WEBRip 1080p][HEVC][1-23]"
pattern: /\]\[(\d{1,4}(?:-\d{1,4})?)\]$/,
transform: toIntRange()
},
{
field: 'episodes',
pattern: /\bodc[. ]+(\d{1,3})\b/i,
Expand Down
Loading