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

Accept only textual subtitle codecs #17

Merged
merged 4 commits into from
Jun 27, 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
21 changes: 16 additions & 5 deletions buganime/buganime.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
OUTPUT_DIR = os.getenv('BUGANIME_OUTPUT_DIR', '')
UPSCALE_MUTEX_NAME = 'anime4kconvert'

SUPPORTED_SUBTITLE_CODECS = ('ass', 'subrip')


@contextlib.contextmanager
def lock_mutex(name: str) -> Iterator[None]:
Expand Down Expand Up @@ -69,7 +71,8 @@ def _get_subtitle_stream_index() -> int:
for i, stream in enumerate(subtitle_streams):
match stream:
case {'tags': {'language': str(lang)}} if lang in ('en', 'eng'):
if all(x not in stream['tags'].get('title', '').upper() for x in ('S&S', 'SIGNS', 'FORCED')):
if all(x not in stream['tags'].get('title', '').upper() for x in ('S&S', 'SIGNS', 'FORCED')) and \
stream['codec_name'].lower() in SUPPORTED_SUBTITLE_CODECS:
relevant_streams.append((i, stream))
if not relevant_streams:
if len(subtitle_streams) == 1:
Expand Down Expand Up @@ -141,10 +144,18 @@ def process_file(input_path: str) -> None:
logging.info('ffprobe %s wrote %s, %s', str(proc.args), proc.stderr, proc.stdout)
video_info = parse_streams(json.loads(proc.stdout)['streams'])

with lock_mutex(name=UPSCALE_MUTEX_NAME):
logging.info('Running Upscaler')
asyncio.run(transcode.Transcoder(input_path=input_path, output_path=output_path, height_out=2160, width_out=3840, video_info=video_info).run())
logging.info('Upscaler for %s finished', input_path)
try:
with lock_mutex(name=UPSCALE_MUTEX_NAME):
logging.info('Running Upscaler')
asyncio.run(transcode.Transcoder(input_path=input_path, output_path=output_path, height_out=2160, width_out=3840, video_info=video_info).run())
logging.info('Upscaler for %s finished', input_path)
except Exception:
logging.warning('Upscaler for %s failed. Deleting output %s', input_path, output_path)
try:
os.unlink(output_path)
except Exception:
pass
raise


def process_path(input_path: str) -> None:
Expand Down
1 change: 0 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ mypy
tqdm-stubs
types-retry
types-requests
torch<2.3.0 # Due to https://github.com/pytorch/pytorch/issues/124897
-r requirements.txt
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pywin32
opencv-python
requests
tqdm
numpy
numpy<2.0.0,>=1.16.0 # https://github.com/pytorch/pytorch/issues/78341
retry
torch
torchvision
Expand Down
Loading
Loading