Skip to content

Commit

Permalink
Fixes for python 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
Kicer86 committed Dec 29, 2024
1 parent e8b9e7b commit 83f4145
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
15 changes: 5 additions & 10 deletions tests/test_subtitles_fixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ def create_broken_video_with_too_long_last_subtitle(output_video_path: str, inpu
file.write(f"1\n\n")

file.write(f"2\n")
file.write(f"{utils.ms_to_time(1000)
} --> {utils.ms_to_time((length + 10) * 1000)}\n")
file.write(f"{utils.ms_to_time(1000)} --> {utils.ms_to_time((length + 10) * 1000)}\n")
file.write(f"2\n")

utils.generate_mkv(input_video, output_video_path, [
Expand Down Expand Up @@ -82,8 +81,7 @@ def setUp(self):
def test_dry_run_is_respected(self):
with TestDataWorkingDirectory() as td:
output_video_path = f"{td.path}/test_video.mkv"
create_broken_video_with_scaled_subtitle_timings(output_video_path, f"{
current_path}/videos/sea-waves-crashing-on-beach-shore-4793288.mp4")
create_broken_video_with_scaled_subtitle_timings(output_video_path, f"{current_path}/videos/sea-waves-crashing-on-beach-shore-4793288.mp4")

hashes_before = hashes(td.path)
twotone.execute(["subtitles_fix", td.path])
Expand All @@ -94,8 +92,7 @@ def test_dry_run_is_respected(self):
def test_video_with_scaled_subtitle_timings_fixing(self):
with TestDataWorkingDirectory() as td:
output_video_path = f"{td.path}/test_video.mkv"
create_broken_video_with_scaled_subtitle_timings(output_video_path, f"{
current_path}/videos/sea-waves-crashing-on-beach-shore-4793288.mp4")
create_broken_video_with_scaled_subtitle_timings(output_video_path, f"{current_path}/videos/sea-waves-crashing-on-beach-shore-4793288.mp4")

hashes_before = hashes(td.path)
twotone.execute(["-r", "subtitles_fix", td.path])
Expand All @@ -111,8 +108,7 @@ def test_video_with_scaled_subtitle_timings_fixing(self):
def test_video_with_too_long_last_subtitle_fixing(self):
with TestDataWorkingDirectory() as td:
output_video_path = f"{td.path}/test_video.mkv"
create_broken_video_with_too_long_last_subtitle(output_video_path, f"{
current_path}/videos/sea-waves-crashing-on-beach-shore-4793288.mp4")
create_broken_video_with_too_long_last_subtitle(output_video_path, f"{current_path}/videos/sea-waves-crashing-on-beach-shore-4793288.mp4")

hashes_before = hashes(td.path)
twotone.execute(["-r", "subtitles_fix", td.path])
Expand All @@ -128,8 +124,7 @@ def test_video_with_too_long_last_subtitle_fixing(self):
def test_deal_with_incompatible_videos(self):
with TestDataWorkingDirectory() as td:
output_video_path = f"{td.path}/test_video.mkv"
create_broken_video_with_incompatible_subtitles(output_video_path, f"{
current_path}/videos/sea-waves-crashing-on-beach-shore-4793288.mp4")
create_broken_video_with_incompatible_subtitles(output_video_path, f"{current_path}/videos/sea-waves-crashing-on-beach-shore-4793288.mp4")

hashes_before = hashes(td.path)
twotone.execute(["-r", "subtitles_fix", td.path])
Expand Down
9 changes: 3 additions & 6 deletions twotone/tools/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ def _convert_subtitle(self, video_fps: str, subtitle: utils.SubtitleFile) -> [ut
utils.fix_subtitles_fps(input_file, output_file, fps)

else:
raise RuntimeError(f"ffmpeg exited with unexpected error:\n{
status.stderr.decode('utf-8')}")
raise RuntimeError(f"ffmpeg exited with unexpected error:\n{status.stderr.decode('utf-8')}")

converted_subtitle = utils.SubtitleFile(
output_file, subtitle.language, "utf-8")
Expand Down Expand Up @@ -197,8 +196,7 @@ def _merge(self, input_video: str, subtitles: [utils.SubtitleFile]):

prepared_subtitles = []
for subtitle in sorted_subtitles:
logging.debug(f"\tregister subtitle [{subtitle.language}]: {
subtitle.path}")
logging.debug(f"\tregister subtitle [{subtitle.language}]: {subtitle.path}")
self._register_input(subtitle.path)

# Subtitles are buggy sometimes, use ffmpeg to fix them.
Expand Down Expand Up @@ -246,8 +244,7 @@ def _process_dir(self, path: str):
# this is a cumbersome situation so just don't allow it
unique_names = set(Path(video).stem for video in video_files)
if len(unique_names) != len(video_files):
logging.warning(f"Two video files with the same name found in {
cd}. This is not supported, skipping whole directory.")
logging.warning(f"Two video files with the same name found in {cd}. This is not supported, skipping whole directory.")
continue

subtitles_finder = self._aggressive_subtitle_search if len(
Expand Down
6 changes: 2 additions & 4 deletions twotone/tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ def get_video_full_info(path: str) -> str:
process = start_process("ffprobe", args)

if process.returncode != 0:
raise RuntimeError(f"ffprobe exited with unexpected error:\n{
process.stderr.decode('utf-8')}")
raise RuntimeError(f"ffprobe exited with unexpected error:\n{process.stderr.decode('utf-8')}")

output_lines = process.stdout
output_json = json.loads(output_lines)
Expand Down Expand Up @@ -310,8 +309,7 @@ def generate_mkv(input_video: str, output_path: str, subtitles: [SubtitleFile]):
if result.returncode != 0:
if os.path.exists(output_path):
os.remove(output_path)
raise RuntimeError(f"{cmd} exited with unexpected error:\n{
result.stderr.decode('utf-8')}")
raise RuntimeError(f"{cmd} exited with unexpected error:\n{result.stderr.decode('utf-8')}")

if not os.path.exists(output_path):
logging.error("Output file was not created")
Expand Down

0 comments on commit 83f4145

Please sign in to comment.