@@ -261,38 +261,7 @@ mp.add_key_binding(nil, "select-edition", function ()
261261 })
262262end )
263263
264- mp .add_key_binding (nil , " select-subtitle-line" , function ()
265- local sub = mp .get_property_native (" current-tracks/sub" )
266-
267- if sub == nil then
268- show_warning (" No subtitle is loaded." )
269- return
270- end
271-
272- if sub .external and sub [" external-filename" ]:find (" ^edl://" ) then
273- sub [" external-filename" ] = sub [" external-filename" ]:match (' https?://.*' )
274- or sub [" external-filename" ]
275- end
276-
277- local r = mp .command_native ({
278- name = " subprocess" ,
279- capture_stdout = true ,
280- args = sub .external
281- and {" ffmpeg" , " -loglevel" , " error" , " -i" , sub [" external-filename" ],
282- " -f" , " lrc" , " -map_metadata" , " -1" , " -fflags" , " +bitexact" , " -" }
283- or {" ffmpeg" , " -loglevel" , " error" , " -i" , mp .get_property (" path" ),
284- " -map" , " s:" .. sub [" id" ] - 1 , " -f" , " lrc" , " -map_metadata" ,
285- " -1" , " -fflags" , " +bitexact" , " -" }
286- })
287-
288- if r .error_string == " init" then
289- show_error (" Failed to extract subtitles: ffmpeg not found." )
290- return
291- elseif r .status ~= 0 then
292- show_error (" Failed to extract subtitles." )
293- return
294- end
295-
264+ local function select_subtitle_line (data )
296265 local sub_lines = {}
297266 local sub_times = {}
298267 local default_item
@@ -301,7 +270,7 @@ mp.add_key_binding(nil, "select-subtitle-line", function ()
301270 local duration = mp .get_property_native (" duration" , math.huge )
302271
303272 -- Strip HTML and ASS tags.
304- for line in r . stdout :gsub (" <.->" , " " ):gsub (" {\\ .-}" , " " ):gmatch (" [^\n ]+" ) do
273+ for line in data :gsub (" <.->" , " " ):gsub (" {\\ .-}" , " " ):gmatch (" [^\n ]+" ) do
305274 -- ffmpeg outputs LRCs with minutes > 60 instead of adding hours.
306275 sub_times [# sub_times + 1 ] = line :match (" %d+" ) * 60 + line :match (" :([%d%.]*)" )
307276 sub_lines [# sub_lines + 1 ] = format_time (sub_times [# sub_times ], duration ) ..
@@ -326,6 +295,54 @@ mp.add_key_binding(nil, "select-subtitle-line", function ()
326295 mp .commandv (" seek" , sub_times [index ] + delay , " absolute" )
327296 end ,
328297 })
298+ end
299+
300+ mp .add_key_binding (nil , " select-subtitle-line" , function ()
301+ local sub = mp .get_property_native (" current-tracks/sub" )
302+
303+ if sub == nil then
304+ show_warning (" No subtitle is loaded." )
305+ return
306+ end
307+
308+ if sub .external and sub [" external-filename" ]:find (" ^edl://" ) then
309+ sub [" external-filename" ] = sub [" external-filename" ]:match (' https?://.*' )
310+ or sub [" external-filename" ]
311+ end
312+
313+ if not sub .external or sub [" external-filename" ]:find (" ://" ) then
314+ local screenx , screeny = mp .get_osd_size ()
315+ local osd_align_x = mp .get_property (" osd-align-x" )
316+ mp .osd_message (" Subtitle export in progress." , 3 )
317+ mp .set_osd_ass (screenx , screeny , string.format (" {\\ an%d}● " ,
318+ osd_align_x == " right" and 7 or 9 ))
319+ end
320+
321+ mp .command_native_async ({
322+ name = " subprocess" ,
323+ capture_stdout = true ,
324+ args = sub .external
325+ and {" ffmpeg" , " -loglevel" , " error" , " -i" , sub [" external-filename" ],
326+ " -f" , " lrc" , " -map_metadata" , " -1" , " -fflags" , " +bitexact" , " -" }
327+ or {" ffmpeg" , " -loglevel" , " error" , " -i" , mp .get_property (" path" ),
328+ " -map" , " s:" .. sub [" id" ] - 1 , " -f" , " lrc" , " -map_metadata" ,
329+ " -1" , " -fflags" , " +bitexact" , " -" }
330+ }, function (success , result )
331+ if not sub .external or sub [" external-filename" ]:find (" ://" ) then
332+ mp .osd_message (" " )
333+ mp .set_osd_ass (0 , 0 , " " )
334+ end
335+
336+ if result and result .error_string == " init" then
337+ show_error (" Failed to extract subtitles: ffmpeg not found." )
338+ return
339+ elseif not success or not result or result .status ~= 0 then
340+ show_error (" Failed to extract subtitles." )
341+ return
342+ end
343+
344+ select_subtitle_line (result .stdout )
345+ end )
329346end )
330347
331348mp .add_key_binding (nil , " select-audio-device" , function ()
0 commit comments