mpv_thumbnail_script icon indicating copy to clipboard operation
mpv_thumbnail_script copied to clipboard

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

Open scarlion1 opened this issue 3 years ago • 3 comments

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 avatar Sep 18 '22 18:09 scarlion1

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 avatar Sep 19 '22 00:09 scarlion1

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)
$

scarlion1 avatar Sep 19 '22 01:09 scarlion1

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.

NicolaSmaniotto avatar Jul 15 '23 14:07 NicolaSmaniotto