@@ -19,7 +19,11 @@ local Thumbnailer = {
1919 -- ready: 1
2020 -- in progress: 0
2121 -- not ready: -1
22- thumbnails = {}
22+ thumbnails = {},
23+
24+ worker_input_path = nil ,
25+ -- Extra options for the workers
26+ worker_extra = {},
2327 },
2428 workers = {}
2529}
@@ -30,6 +34,7 @@ function Thumbnailer:clear_state()
3034 self .state .available = false
3135 self .state .finished_thumbnails = 0
3236 self .state .thumbnails = {}
37+ self .state .worker_extra = {}
3338end
3439
3540
@@ -72,7 +77,7 @@ function Thumbnailer:update_state()
7277 self .state .thumbnails [i ] = - 1
7378 end
7479
75- self .state .thumbnail_template = self :get_thumbnail_template ()
80+ self .state .thumbnail_template , self . state . thumbnail_directory = self :get_thumbnail_template ()
7681 self .state .thumbnail_size = self :get_thumbnail_size ()
7782
7883 self .state .ready = true
@@ -117,8 +122,10 @@ function Thumbnailer:get_thumbnail_template()
117122 end
118123
119124 local file_key = (" %s-%d" ):format (filename , filesize )
120- local file_template = join_paths (self .cache_directory , file_key , " %06d.bgra" )
121- return file_template
125+
126+ local thumbnail_directory = join_paths (self .cache_directory , file_key )
127+ local file_template = join_paths (thumbnail_directory , " %06d.bgra" )
128+ return file_template , thumbnail_directory
122129end
123130
124131
@@ -297,15 +304,58 @@ function Thumbnailer:_create_thumbnail_job_order()
297304 return work_frames
298305end
299306
307+ function Thumbnailer :prepare_source_path ()
308+ local file_path = mp .get_property_native (" path" )
309+
310+ if self .state .is_remote and thumbnailer_options .remote_direct_stream then
311+ -- Use the direct stream (possibly) provided by ytdl
312+ -- This skips ytdl on the sub-calls, making the thumbnailing faster
313+ -- Works well on YouTube, rest not really tested
314+ file_path = mp .get_property_native (" stream-path" )
315+
316+ -- edl:// urls can get LONG. In which case, save the path (URL)
317+ -- to a temporary file and use that instead.
318+ local playlist_filename = join_paths (self .state .thumbnail_directory , " playlist.txt" )
319+
320+ if # file_path > 8000 then
321+ -- Path is too long for a playlist - just pass the original URL to
322+ -- workers and allow ytdl
323+ self .state .worker_extra .enable_ytdl = true
324+ file_path = mp .get_property_native (" path" )
325+ msg .warn (" Falling back to original URL and ytdl due to LONG source path. This will be slow." )
326+
327+ elseif # file_path > 1024 then
328+ local playlist_file = io.open (playlist_filename , " wb" )
329+ if not playlist_file then
330+ msg .error ((" Tried to write a playlist to %s but couldn't!" ):format (playlist_file ))
331+ return false
332+ end
333+
334+ playlist_file :write (file_path .. " \n " )
335+ playlist_file :close ()
336+
337+ file_path = " --playlist=" .. playlist_filename
338+ msg .warn (" Using playlist workaround due to long source path" )
339+ end
340+ end
341+
342+ self .state .worker_input_path = file_path
343+ return true
344+ end
345+
300346function Thumbnailer :start_worker_jobs ()
301347 self .state .enabled = true
302348
303349 -- Create directory for the thumbnails, if needed
304- local thumbnail_directory = split_path (self .state .thumbnail_template )
305- local l , err = utils .readdir (thumbnail_directory )
350+ local l , err = utils .readdir (self .state .thumbnail_directory )
306351 if err then
307- msg .info (" Creating" , thumbnail_directory )
308- create_directories (thumbnail_directory )
352+ msg .debug (" Creating thumbnail directory" , self .state .thumbnail_directory )
353+ create_directories (self .state .thumbnail_directory )
354+ end
355+
356+ -- Try to prepare the source path for workers, and bail if unable to do so
357+ if not self :prepare_source_path () then
358+ return
309359 end
310360
311361 local worker_list = {}
0 commit comments