Skip to content

Commit

Permalink
thumbnailer_shared: use full filename path for remote URLs, hash them (
Browse files Browse the repository at this point in the history
…#45)

The actual filename part is often similar for different URLs,
so use the full path. Ensure it is always hashed to prevent
bad characters from entering file names.

Closes #44
  • Loading branch information
olifre authored Sep 21, 2023
1 parent 9191070 commit 32fdc2d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/thumbnailer_shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,14 @@ function Thumbnailer:get_thumbnail_template()
local filesize = mp.get_property_native("file-size", 0)

if self.state.is_remote then
-- Use full path for remote URLs as filename part is often similar
filename = file_path
filesize = 0
end

filename = filename:gsub('[^a-zA-Z0-9_.%-\' ]', '')
-- Hash overly long filenames (most likely URLs)
if #filename > thumbnailer_options.hash_filename_length then
-- Hash overly long filenames and any remote URL
if #filename > thumbnailer_options.hash_filename_length or self.state.is_remote then
filename = sha1.hex(filename)
end

Expand Down

0 comments on commit 32fdc2d

Please sign in to comment.