occivink / mpv-gallery-view

Gallery-view scripts for mpv
The Unlicense
189 stars 20 forks source link

Thumbnail path in portable mpv Windows #49

Closed JimPancakes closed 8 months ago

JimPancakes commented 8 months ago

I am using mpv with "portable_config" folder in it. All scripts load fine but I just don't know how to set the thumbnail path in this case. I made a "gallery-thumbs-dir" folder in "portable_config" but it doesn't work. Putting the direct path to "gallery-thumbs-dir" in playlist_view.conf does work but that is not the solution I'm looking for because if I move mpv someplace else I have to do this all over again thus making it not so portable anymore.

occivink commented 8 months ago

I don't know if it's possible currently, but we might be able to use expand-path on the configured thumbs dir, such that it can be defined relative to the mpv config location. I won't be able to check it in the near future though, so either PRs welcome or ping me again in ~2 weeks

JimPancakes commented 8 months ago

Managed to solve it on my own. Thanks for the hint!

occivink commented 8 months ago

Could you share your solution?

JimPancakes commented 8 months ago

I made changes so that the script would automatically work for both mpv in portable mode on windows and for mpv-android since this is what I wanted to use it for. I don't know if it works on linux or the normal mpv mode on windows.

The changes I made are as follows:

thumbs_dir = ON_WINDOWS and "%APPDATA%\\mpv\\gallery-thumbs-dir" or "~/.cache/thumbnails/mpv-gallery/",

to

thumbs_dir = mp.command_native({ "expand-path", "~~/thumbnails" }),

and

if ON_WINDOWS then
    thumbs_dir = string.gsub(opts.thumbs_dir, "^%%APPDATA%%", os.getenv("APPDATA") or "%APPDATA%")
else
    thumbs_dir = string.gsub(opts.thumbs_dir, "^~", os.getenv("HOME") or "~")
end
local res = utils.file_info(thumbs_dir)
if not res or not res.is_dir then
    if opts.mkdir_thumbs then
        local args = ON_WINDOWS and { "mkdir", thumbs_dir } or { "mkdir", "-p", thumbs_dir }
        utils.subprocess({ args = args, playback_only = false })
    else
        msg.error(string.format("Thumbnail directory \"%s\" does not exist", thumbs_dir))
    end
end

to

thumbs_dir = opts.thumbs_dir
local res = utils.file_info(thumbs_dir)
if not res or not res.is_dir then
    if opts.mkdir_thumbs then
        if ON_WINDOWS then
            os.execute("mkdir " .. thumbs_dir:gsub("/", "\\"))
        else
            local args = { "mkdir", "-p", thumbs_dir }
            utils.subprocess({ args = args, playback_only = false })
        end
    else
        msg.error(string.format("Thumbnail directory \"%s\" does not exist", thumbs_dir))
    end
end

The use of expand-path was the key.