marzzzello / mpv_thumbnail_script

A Lua script to show preview thumbnails in mpv's OSC seekbar, sans external dependencies (fork)
GNU General Public License v3.0
270 stars 20 forks source link

Possible to put the thumbnails in the video's directory? #28

Open scarlion1 opened 1 year ago

scarlion1 commented 1 year ago

Instead of having all the thumbnails saved into one directory, is it possible to save them in a ".thumbnails" subdirectory in the same directory the video is loaded from? Either with the config file or by editing the script code? I tried cache_directory=./.thumbnails but it puts the ".thumbnails" in my home directory. Thanks

scarlion1 commented 1 year ago

I've never programmed with mpv or lua before, but I feel like using mp.get_property("path") could be used. However when I try to use it the value is always "nil" I guess because the script is running before the video is loaded?

scarlion1 commented 1 year ago

Yay I figured out something! Just made some changes to function Thumbnailer:get_thumbnail_template() in mpv_thumbnail_script_client_osc.lua

Basically added local filedir, filename = utils.split_path(file_path) after the first line and added two join_paths() in place of the original.

Now if I set cache_directory=.thumbnails then the thumbnails get created in <the directory the video is in>/.thumbnails/<file_key>/

$ diff mpv_thumbnail_script_client_osc.lua mpv_thumbnail_script_client_osc.lua.orig 
919,920d918
<     local filedir, filename = utils.split_path(file_path)
< 
938,940c936
<     -- local thumbnail_directory = join_paths(self.cache_directory, file_key)
<     local thumbnail_directory_base = join_paths(filedir, self.cache_directory)
<     local thumbnail_directory = join_paths(thumbnail_directory_base, file_key)
---
>     local thumbnail_directory = join_paths(self.cache_directory, file_key)
$
NicolaSmaniotto commented 1 year ago

It would be nice to determine it automatically: if cache_directory isn't an absolute path, then consider it relative to the file being played.

On *nix, we can simply check for a / as first character, I don't know how it can be detected on windows.