Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thumbnail path in portable mpv Windows #49

Closed
JimPancakes opened this issue Dec 20, 2023 · 4 comments
Closed

Thumbnail path in portable mpv Windows #49

JimPancakes opened this issue Dec 20, 2023 · 4 comments

Comments

@JimPancakes
Copy link

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
Copy link
Owner

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
Copy link
Author

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

@occivink
Copy link
Owner

occivink commented Jan 2, 2024

Could you share your solution?

@JimPancakes
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants