Skip to content

Commit

Permalink
fix: support more filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
bugale committed Sep 1, 2024
1 parent 0b9bfe6 commit 3ad71da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions buganime/buganime.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ def parse_filename(input_path: str) -> TVShow | Movie:
if match := re.match(r'^(?P<name>.+?)[ -]+S(?P<season>\d{1,2})E(?P<episode>\d{1,3})(?:[ -]+.*)?$', input_name):
return TVShow(name=match.group('name'), season=int(match.group('season')), episode=int(match.group('episode')))

# Other standalone TV Shows
if match := re.match(r'^(?P<name>.+?)[ -]* (?:S(?:eason ?)?(?P<season>\d{1,2})[ -]*)?E?(?P<episode>\d{1,3})(?:v\d+)?(?:[ -].*)?$', input_name):
return TVShow(name=match.group('name'), season=int(match.group('season') or '1'), episode=int(match.group('episode')))

# Structured TV Shows
dir_re = r'(?P<name>[^\\]+?)[ -]+S(?:eason ?)?\d{1,2}(?:[ -][^\\]*)?'
file_re = r'[^\\]*S(?P<season>\d{1,2})E(?P<episode>\d{1,3})(?:[ -][^\\]*)?'
if match := re.match(fr'^.*\\{dir_re}(?:\\.*)?\\{file_re}$', input_path):
return TVShow(name=match.group('name'), season=int(match.group('season')), episode=int(match.group('episode')))

# Other standalone TV Shows
if match := re.match(r'^(?P<name>.+?)[ -]* (?:S(?:eason ?)?(?P<season>\d{1,2})[ -]*)?E?(?P<episode>\d{1,3})(?:v\d+)?(?:[ -].*)?$', input_name):
return TVShow(name=match.group('name'), season=int(match.group('season') or '1'), episode=int(match.group('episode')))

return Movie(name=input_name)


Expand Down
6 changes: 5 additions & 1 deletion tests/test_buganime.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,17 @@
(r'C:\Monogatari Series\15. Zoku Owarimonogatari\Zoku Owarimonogatari 01 - Koyomi Reverse, Part 1.mkv',
buganime.TVShow(name='Zoku Owarimonogatari', season=1, episode=1)),

(r'C:\SNAFU S01-S03+OVA 1080p Dual Audio BDRip 10 bits DD x265-EMBER\SNAFU S02+OVA 1080p Dual Audio BDRip 10 bits DD x265-EMBER\Series\S02E01-Nobody Knows'
(r'C:\SNAFU S01-S03+OVA 1080p Dual Audio BDRip 10 bits DD x265-EMBER\SNAFU S02+OVA 1080p Dual Audio BDRip 10 bits DD x265-EMBER\Series\S02E01-Nobody Knows '
r'Why They Came to the Service Club [7CE95AC0].mkv',
buganime.TVShow(name='SNAFU', season=2, episode=1)),

(r'C:\Temp\Torrents\SNAFU S01-S03+OVA 1080p Dual Audio BDRip 10 bits DD x265-EMBER\SNAFU S02+OVA 1080p Dual Audio BDRip 10 bits DD x265-EMBER\OVA\S02E14 '
r'[OVA]-Undoubtedly, Girls Are Made of Sugar, Spice, and Everything Nice [7E9E8A1F].mkv',
buganime.TVShow(name='SNAFU', season=2, episode=14)),

(r'C:\Temp\Torrents\Mushoku Tensei S01+SP 1080p Dual Audio BDRip 10 bits DDP x265-EMBER\Mushoku Tensei S01P01 1080p Dual Audio BDRip 10 bits DD '
r'x265-EMBER\S01E08-Turning Point 1 V2 [87C2150F].mkv',
buganime.TVShow(name='Mushoku Tensei', season=1, episode=8)),
]


Expand Down

0 comments on commit 3ad71da

Please sign in to comment.