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

Support more namings and subtitles #11

Merged
merged 1 commit into from
Jul 13, 2023
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
19 changes: 12 additions & 7 deletions buganime/buganime.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,17 @@ def _get_audio_stream() -> Any:

def _get_subtitle_stream_index() -> int:
subtitle_streams = [stream for stream in streams if stream['codec_type'] == 'subtitle']
for i, stream in enumerate(subtitle_streams):
match stream:
case {'tags': {'language': str(lang), 'title': str(title)}} if (lang in ('en', 'eng') and
'S&S' not in title.upper() and 'SIGNS' not in title.upper()):
return i
relevant_streams = []
for i, stream in enumerate(subtitle_streams):
match stream:
case {'tags': {'language': str(lang)}} if lang in ('en', 'eng'):
return i
raise RuntimeError('No English subtitle stream found')
if all(x not in stream['tags'].get('title', '').upper() for x in ('S&S', 'SIGNS', 'FORCED')):
relevant_streams.append((i, stream))
if not relevant_streams:
raise RuntimeError('No English subtitle stream found')
if len(relevant_streams) == 1:
return relevant_streams[0][0]
return max(relevant_streams, key=lambda x: int(x[1]['tags'].get('NUMBER_OF_BYTES-eng', '0')))[0]

video = _get_video_stream()
return transcode.VideoInfo(audio_index=_get_audio_stream()['index'], subtitle_index=_get_subtitle_stream_index(),
Expand All @@ -95,6 +96,10 @@ def parse_filename(input_path: str) -> TVShow | Movie:
input_name):
return TVShow(name=match.group('name'), season=0, episode=int(match.group('episode') or 1))

# Formatted standalone TV Shows
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')))
Expand Down
Loading