Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support more filenames #18

Merged
merged 3 commits into from
Sep 1, 2024
Merged
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
4 changes: 1 addition & 3 deletions .github/workflows/check-general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ jobs:
uses: actions/checkout@v4
- uses: bugale/bugroup-checks@v2
with:
checks: |-
Check .*
.*[lL]int.*
checks: .*
self: Required Checks
check-commits:
name: Check Commits
Expand Down
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
9 changes: 7 additions & 2 deletions 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 Expand Up @@ -127,7 +131,8 @@ def test_transcode(filename: str, fps: str, check_func: typing.Callable[[typing.
with tempfile.TemporaryDirectory() as tempdir:
buganime.OUTPUT_DIR = tempdir
output_path = os.path.join(tempdir, 'Movies', filename)
buganime.process_file(os.path.join(os.path.dirname(__file__), 'data', filename))
with pytest.warns(FutureWarning, match='You are using `torch.load`'):
buganime.process_file(os.path.join(os.path.dirname(__file__), 'data', filename))
assert os.path.isfile(output_path)
stream = json.loads(subprocess.run(['ffprobe', '-show_format', '-show_streams', '-of', 'json', output_path], text=True, capture_output=True,
check=True, encoding='utf-8').stdout)['streams'][0]
Expand Down
Loading