Skip to content

Commit 40cadfc

Browse files
committed
Playlist logn EDL paths, or give up
Some ytdl Youtube EDLs can be even 150 kilobytes long, which is much too much for commandline and even playlist files (mpv can handle 8k characters on one line). If a file path (url) is over 8k characters long, use original path (url) and permit the use of ytdl. This will be slow, but it will work. If a file path is over 1k characters long (but less than 8k), save it to a temporary playlist and play that. 1k may be too long for Windows commandline; I didn't really check.
1 parent aa54d30 commit 40cadfc

File tree

1 file changed

+47
-6
lines changed

1 file changed

+47
-6
lines changed

src/thumbnailer_server.lua

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ function skip_nil(tbl)
66
return n
77
end
88

9-
function create_thumbnail_mpv(file_path, timestamp, size, output_path)
10-
local ytdl_disabled = mp.get_property_native("ytdl") == false or thumbnailer_options.remote_direct_stream
9+
function create_thumbnail_mpv(file_path, timestamp, size, output_path, options)
10+
options = options or {}
11+
12+
local ytdl_disabled = not options.enable_ytdl and (mp.get_property_native("ytdl") == false
13+
or thumbnailer_options.remote_direct_stream)
1114

1215
local profile_arg = nil
1316
if thumbnailer_options.mpv_profile ~= "" then
@@ -81,8 +84,8 @@ function check_output(ret, output_path, is_mpv)
8184
else
8285
if ret.error or ret.status ~= 0 then
8386
msg.error("Thumbnailing command failed!")
84-
msg.error(ret.error)
85-
msg.error(ret.stdout)
87+
msg.error("mpv process error:", ret.error)
88+
msg.error("Process stdout:", ret.stdout)
8689
if is_mpv then
8790
msg.error("Debug log:", log_path)
8891
end
@@ -131,6 +134,7 @@ function do_worker_job(state_json_string, frames_json_string)
131134

132135
local file_duration = mp.get_property_native("duration")
133136
local file_path = mp.get_property_native("path")
137+
local extra_worker_options = {}
134138

135139
if thumb_state.is_remote then
136140
thumbnail_func = create_thumbnail_mpv
@@ -142,7 +146,33 @@ function do_worker_job(state_json_string, frames_json_string)
142146
end
143147
end
144148

145-
msg.debug(("Generating %d thumbnails @ %dx%d"):format(#thumbnail_indexes, thumb_state.thumbnail_size.w, thumb_state.thumbnail_size.h))
149+
-- edl:// urls can get LONG. In which case, save the path (URL)
150+
-- to a temporary file and use that instead.
151+
local thumbnail_directory = split_path(thumb_state.thumbnail_template)
152+
local playlist_filename = join_paths(thumbnail_directory, "playlist" .. mp.get_script_name() .. ".txt")
153+
local edl_playlist_used = false
154+
155+
if #file_path > 8000 then
156+
-- Path is too long for a playlist - just pass the original URL to
157+
-- workers and allow ytdl
158+
extra_worker_options.enable_ytdl = true
159+
file_path = mp.get_property_native("path")
160+
msg.warn("Falling back to original URL and ytdl due to LONG source path. This will be slow.")
161+
162+
elseif #file_path > 1024 then
163+
local playlist_file = io.open(playlist_filename, "wb")
164+
if not playlist_file then
165+
msg.error(("Tried to write a playlist to %s but couldn't!"):format(playlist_file))
166+
return
167+
end
168+
169+
playlist_file:write(file_path .. "\n")
170+
playlist_file:close()
171+
172+
file_path = "--playlist=" .. playlist_filename
173+
edl_playlist_used = true
174+
msg.warn("Using playlist workaround due to long source path")
175+
end
146176

147177
local generate_thumbnail_for_index = function(thumbnail_index)
148178
local thumbnail_path = thumb_state.thumbnail_template:format(thumbnail_index)
@@ -170,7 +200,7 @@ function do_worker_job(state_json_string, frames_json_string)
170200
end
171201

172202
if need_thumbnail_generation then
173-
local ret = thumbnail_func(file_path, timestamp, thumb_state.thumbnail_size, thumbnail_path)
203+
local ret = thumbnail_func(file_path, timestamp, thumb_state.thumbnail_size, thumbnail_path, extra_worker_options)
174204
local success = check_output(ret, thumbnail_path, thumbnail_func == create_thumbnail_mpv)
175205

176206
if success == nil then
@@ -216,6 +246,17 @@ function do_worker_job(state_json_string, frames_json_string)
216246
local bail = generate_thumbnail_for_index(thumbnail_index)
217247
if bail then return end
218248
end
249+
250+
msg.debug(("Generating %d thumbnails @ %dx%d for %q"):format(
251+
#thumbnail_indexes,
252+
thumb_state.thumbnail_size.w,
253+
thumb_state.thumbnail_size.h,
254+
file_path))
255+
256+
-- Remove playlist file if it was used as a workaround
257+
if edl_playlist_used then
258+
os.remove(playlist_filename)
259+
end
219260
end
220261

221262
-- Set up listeners and keybinds

0 commit comments

Comments
 (0)