Skip to content

Commit d77f215

Browse files
committed
Show files without subtitles + show filename on error
1 parent 6a37007 commit d77f215

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

condenser.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def probe_video(filename):
3131
result = sp.run([ffprobe_cmd, "-show_streams", "-v", "quiet", "-print_format", "json", filename],
3232
capture_output=True)
3333
if result.returncode != 0:
34-
raise Exception("Could not probe video with ffprobe: " + str(result.stderr))
34+
raise Exception("Could not probe video " + filename + " with ffprobe: " + str(result.stderr))
3535
probe = json.loads(result.stdout)
3636
streams = probe.get("streams")
3737
audio_streams = [s for s in streams if s.get("codec_type") == "audio"]
@@ -168,8 +168,7 @@ def extract_srt(temp_dir, filename, sub_index):
168168
return srt_path
169169

170170

171-
def find_same_name_sub(filename):
172-
# Checking if a subtitle file exists with the same name as the video file
171+
def find_subtitle_with_same_name_as_file(filename):
173172
file_root, _ = op.splitext(filename)
174173
for e in sub_exts[:-1]:
175174
path = file_root + sub_suffix + e[1:]
@@ -178,8 +177,20 @@ def find_same_name_sub(filename):
178177
return None
179178

180179

180+
def find_matching_subtitles_for_files(filenames):
181+
all_subtitle_paths = []
182+
invalid_videos = []
183+
for filename in filenames:
184+
subtitle = find_subtitle_with_same_name_as_file(filename)
185+
if subtitle:
186+
all_subtitle_paths.append(subtitle)
187+
else:
188+
invalid_videos.append(filename)
189+
return all_subtitle_paths, invalid_videos
190+
191+
181192
def get_srt(subtitle_streams, mulsrt_ask, file_folder, filename, temp_dir):
182-
sub_path = find_same_name_sub(filename)
193+
sub_path = find_subtitle_with_same_name_as_file(filename)
183194

184195
if sub_path is None:
185196
# No same-name subs
@@ -225,13 +236,13 @@ def condense(srt_path, padding, temp_dir, filename, audio_index, output_filename
225236

226237
def condense_multi(subtitle_option, video_paths, video_names, subtitle_stream, audio_stream, mulsrt_ask, parent_folder,
227238
folder_name, temp_dir, padding):
228-
all_subtitle_paths = list(map(find_same_name_sub, video_paths))
239+
all_subtitle_paths, invalid_videos = find_matching_subtitles_for_files(video_paths)
229240
sub_index = 0
230-
if None in all_subtitle_paths:
241+
if invalid_videos:
231242
# There is at least one video with no external sub
232243
if len(subtitle_option) == 0:
233244
# There are no internal subs
234-
raise Exception("There are videos with no subtitles and no corresponding subtitle files")
245+
raise Exception("There are videos with no subtitles and no corresponding subtitle files:\n"+ '\n'.join(invalid_videos))
235246
is_all_none = all(s is None for s in all_subtitle_paths)
236247
file_name_str = "all files" if is_all_none else "some files"
237248
sub_index = choose_subtitle_stream(subtitle_stream, mulsrt_ask, file_name_str)

0 commit comments

Comments
 (0)