@@ -31,7 +31,7 @@ def probe_video(filename):
31
31
result = sp .run ([ffprobe_cmd , "-show_streams" , "-v" , "quiet" , "-print_format" , "json" , filename ],
32
32
capture_output = True )
33
33
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 ))
35
35
probe = json .loads (result .stdout )
36
36
streams = probe .get ("streams" )
37
37
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):
168
168
return srt_path
169
169
170
170
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 ):
173
172
file_root , _ = op .splitext (filename )
174
173
for e in sub_exts [:- 1 ]:
175
174
path = file_root + sub_suffix + e [1 :]
@@ -178,8 +177,20 @@ def find_same_name_sub(filename):
178
177
return None
179
178
180
179
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
+
181
192
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 )
183
194
184
195
if sub_path is None :
185
196
# No same-name subs
@@ -225,13 +236,13 @@ def condense(srt_path, padding, temp_dir, filename, audio_index, output_filename
225
236
226
237
def condense_multi (subtitle_option , video_paths , video_names , subtitle_stream , audio_stream , mulsrt_ask , parent_folder ,
227
238
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 )
229
240
sub_index = 0
230
- if None in all_subtitle_paths :
241
+ if invalid_videos :
231
242
# There is at least one video with no external sub
232
243
if len (subtitle_option ) == 0 :
233
244
# 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 ) )
235
246
is_all_none = all (s is None for s in all_subtitle_paths )
236
247
file_name_str = "all files" if is_all_none else "some files"
237
248
sub_index = choose_subtitle_stream (subtitle_stream , mulsrt_ask , file_name_str )
0 commit comments