Skip to content

Commit

Permalink
Playlist logn EDL paths, or give up
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheAMM committed Dec 19, 2017
1 parent aa54d30 commit 40cadfc
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions src/thumbnailer_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ function skip_nil(tbl)
return n
end

function create_thumbnail_mpv(file_path, timestamp, size, output_path)
local ytdl_disabled = mp.get_property_native("ytdl") == false or thumbnailer_options.remote_direct_stream
function create_thumbnail_mpv(file_path, timestamp, size, output_path, options)
options = options or {}

local ytdl_disabled = not options.enable_ytdl and (mp.get_property_native("ytdl") == false
or thumbnailer_options.remote_direct_stream)

local profile_arg = nil
if thumbnailer_options.mpv_profile ~= "" then
Expand Down Expand Up @@ -81,8 +84,8 @@ function check_output(ret, output_path, is_mpv)
else
if ret.error or ret.status ~= 0 then
msg.error("Thumbnailing command failed!")
msg.error(ret.error)
msg.error(ret.stdout)
msg.error("mpv process error:", ret.error)
msg.error("Process stdout:", ret.stdout)
if is_mpv then
msg.error("Debug log:", log_path)
end
Expand Down Expand Up @@ -131,6 +134,7 @@ function do_worker_job(state_json_string, frames_json_string)

local file_duration = mp.get_property_native("duration")
local file_path = mp.get_property_native("path")
local extra_worker_options = {}

if thumb_state.is_remote then
thumbnail_func = create_thumbnail_mpv
Expand All @@ -142,7 +146,33 @@ function do_worker_job(state_json_string, frames_json_string)
end
end

msg.debug(("Generating %d thumbnails @ %dx%d"):format(#thumbnail_indexes, thumb_state.thumbnail_size.w, thumb_state.thumbnail_size.h))
-- edl:// urls can get LONG. In which case, save the path (URL)
-- to a temporary file and use that instead.
local thumbnail_directory = split_path(thumb_state.thumbnail_template)
local playlist_filename = join_paths(thumbnail_directory, "playlist" .. mp.get_script_name() .. ".txt")
local edl_playlist_used = false

if #file_path > 8000 then
-- Path is too long for a playlist - just pass the original URL to
-- workers and allow ytdl
extra_worker_options.enable_ytdl = true
file_path = mp.get_property_native("path")
msg.warn("Falling back to original URL and ytdl due to LONG source path. This will be slow.")

elseif #file_path > 1024 then
local playlist_file = io.open(playlist_filename, "wb")
if not playlist_file then
msg.error(("Tried to write a playlist to %s but couldn't!"):format(playlist_file))
return
end

playlist_file:write(file_path .. "\n")
playlist_file:close()

file_path = "--playlist=" .. playlist_filename
edl_playlist_used = true
msg.warn("Using playlist workaround due to long source path")
end

local generate_thumbnail_for_index = function(thumbnail_index)
local thumbnail_path = thumb_state.thumbnail_template:format(thumbnail_index)
Expand Down Expand Up @@ -170,7 +200,7 @@ function do_worker_job(state_json_string, frames_json_string)
end

if need_thumbnail_generation then
local ret = thumbnail_func(file_path, timestamp, thumb_state.thumbnail_size, thumbnail_path)
local ret = thumbnail_func(file_path, timestamp, thumb_state.thumbnail_size, thumbnail_path, extra_worker_options)
local success = check_output(ret, thumbnail_path, thumbnail_func == create_thumbnail_mpv)

if success == nil then
Expand Down Expand Up @@ -216,6 +246,17 @@ function do_worker_job(state_json_string, frames_json_string)
local bail = generate_thumbnail_for_index(thumbnail_index)
if bail then return end
end

msg.debug(("Generating %d thumbnails @ %dx%d for %q"):format(
#thumbnail_indexes,
thumb_state.thumbnail_size.w,
thumb_state.thumbnail_size.h,
file_path))

-- Remove playlist file if it was used as a workaround
if edl_playlist_used then
os.remove(playlist_filename)
end
end

-- Set up listeners and keybinds
Expand Down

0 comments on commit 40cadfc

Please sign in to comment.