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

Hide or show thumbnails based on config (profile) #575

Closed
Niotferdi opened this issue Jun 15, 2023 · 26 comments
Closed

Hide or show thumbnails based on config (profile) #575

Niotferdi opened this issue Jun 15, 2023 · 26 comments

Comments

@Niotferdi
Copy link

In films, I don't want to spoil the future events of the plot for myself when I seek time with the mouse. So thumbfast should be disabled automatically if the video has a cinema profile applied to it, in which I pass script-opts options. Other videos on the computer do not contain a story, there thumbnails should be enabled by default.
So far, I have found only such a code that enables and disables thumbnails by key.

bind_command('hide-thumbnails', function() thumbnail.disabled = true end) bind_command('show-thumbnails', function() thumbnail.disabled = false end)

It is also needed, but for other purposes.

@tomasklaen
Copy link
Owner

Deciding for what files to generate thumbnails is definitely a thumbfast concern. uosc doesn't have any thumbfast related options. It just integrates with it by rendering thumbnails if thumbfast sends any.

@christoph-heinrich
Copy link
Contributor

With your modification in place, you could make a script that hides/shows thumbnails based on your preferences using the script-binding command.

@Niotferdi
Copy link
Author

Good idea. I tried to write a script that would take the script-opts value from the config and send the script-binding. But I couldn't accept script-opts from config. Do you know how to do it?

@Niotferdi
Copy link
Author

@tomasklaen I don't think it's difficult. Your script has a function to hide thumbnails, which can be called manually just like I wrote in the first post. To call it automatically, you need to read the script-opts from the config. This can be done. In the original osc it was possible to pass functions through script-opts=osc-...
For example

[extension.mp3]
profile=music
[music]
script-opts-add=osc-visibility=always

@christoph-heinrich
Copy link
Contributor

I couldn't accept script-opts from config. Do you know how to do it?

You need to use read_options to get the values from the config file/script-opts. Most scripts use it (including uosc), so you can use those as a reference.

@tomasklaen
Copy link
Owner

I don't think it's difficult.

I'm not saying it's difficult. I'm saying this is not uosc's concern. thumbfast controls thumbnails, we just integrate with it. In other words, if you want something like this to be built into uosc+thumbfast, you should make this issue in thumbfast's repo.

Also, I think thumbnail.disabled can get overwritten in thumbfast message handlers if I recall correctly, so your solution is prone to not be reliable.

@Niotferdi
Copy link
Author

@christoph-heinrich script-opts from config works, but script-opts from profile in config doesn't work. Options for the default osc, those with the osc- prefix, work from both the config and the profile. However, custom scripts take options only from the config, but not from the profile in the config.

@po5
Copy link
Contributor

po5 commented Jun 17, 2023

thumbfast has an enabled option which is likely what we'd end up using, but it currently does not support hot option reloading. See po5/thumbfast#95

@Niotferdi
Copy link
Author

@po5 I did not find the enabled option in the code.

@po5
Copy link
Contributor

po5 commented Jun 17, 2023

I wrote this at 4am, turns out there's no such option yet :^)

@christoph-heinrich
Copy link
Contributor

Updating script-opts at runtime doesn't work with most scripts, because support for it is rarely implemented, not because it can't work for scripts provided by users. You have to pass a function to read_options as the third parameter that notifies the script about updates.
The osc does pass a function. They could however directly pass a reference to update_options instead of a wrapper function.

Btw the documentation I've linked mentions that third parameter 😉

@Niotferdi
Copy link
Author

@christoph-heinrich I saw the line function update_options(list) earlier. It uses functions that update osc-specific interface elements. I don't understand how this has to do with the generic updating of script-opts while the script is running.

@christoph-heinrich
Copy link
Contributor

I thought you meant that updating script-opts during runtime doesn't change the options in the script, but do you mean that setting script-opts in a conditional profiles does not actually change the script-opts property itself?

@Niotferdi
Copy link
Author

What I mean is that setting the script-opts of my script in the profile does not change its value. Only osc options can be changed in the profile. Whereas in the main config you can change the script-opts of any script, but this does not make sense to me.

@christoph-heinrich
Copy link
Contributor

christoph-heinrich commented Jun 17, 2023

I've made a little test now and it works just fine.

test.lua
local options = require 'mp.options'

opts = {
   something = "hi"
}

options.read_options(opts, "test", function(list)
   print(opts.something)
end)

print(opts.something)
mpv.conf
profile=test

[test]
script-opts=test-something=test_profile

[test2]
profile-cond=vid == false
script-opts=test-something=test2_profile
profile-restore=copy-equal

When not loading the profile in mpv.conf it prints hi upon startup.
When loading the profile it prints test_profile.
When opening a video it prints test_profile, opening an audio file in the same instance then prints test2_profile, and opening a video again in the same instance prints test_profile.

Loading a profile in mpv.conf works and loading a conditional profile works as well. So... what's the problem?

@Niotferdi
Copy link
Author

What you wrote works. Because you wrote profile=test at the beginning of the config, that is, you applied all the options from [test] to the main config. This could be done without a profile. But I use the use-filedir-conf option, next to each movie there is a separate mpv.conf, in which the cinema profile is registered, and script-opts are registered in the cinema profile

@Niotferdi
Copy link
Author

I also tried to apply the profile via profile-cond and it doesn't work

@Niotferdi
Copy link
Author

Moreover, at the moment it all makes no sense! I tried to do all this for the sake of script-binding uosc/hide-thumbnails, but mp.commandv('script-binding', 'uosc/hide-thumbnails') does not work in a script, regardless of whether it reads script-opts from the profile or not

@christoph-heinrich
Copy link
Contributor

I've now created a mpv.conf at the location of the video file with the content I've posted above and ran mpv with --use-filedir-conf. The profile test_profile got loaded after dragging the video file in the idle mpv instance.

@christoph-heinrich
Copy link
Contributor

christoph-heinrich commented Jun 17, 2023

After adding

bind_command('hide-thumbnails', function() print('hide') end)
bind_command('show-thumbnails', function() print('show') end)

to uosc.lua and adding

mp.add_key_binding('Y', 'asdf', function() mp.commandv('script-binding', 'uosc/hide-thumbnails') end)

to test.lua I can say for sure that invoking the binding via script-binding from a script does work.

@Niotferdi
Copy link
Author

I was talking about automatically applying script-binding based on script-opts

@christoph-heinrich
Copy link
Contributor

christoph-heinrich commented Jun 17, 2023

Do your "cinema" files all have a common path? Something like /data/movies/<movie name>/<video file> ? because then you could apply a conditional profile by matching on '/data/movies/' in the file name (profile-cond gets evaluated as lua), and restore the script-opts if the condition doesn't match anymore with profile-restore.

Purely applying script-opts with your mpv.conf next to the video file is easy (literally just script-opts=your_script_name-script_option_name), but resetting the script-opts back to it's original value when you open a different file wouldn't be possible (at least I couldn't think of anything).

@Niotferdi
Copy link
Author

I tested on the same movie in d:\Movies folder. I don't understand how profile-restore can help me, I don't understand what you are talking about. The script-opts in mpv.conf near the video file (use-filedir-conf) doesn't work, I figured that out even before I started using uosc.

@christoph-heinrich
Copy link
Contributor

Except that it does in fact work, as I've described in #575 (comment)

@Niotferdi
Copy link
Author

Niotferdi commented Jun 18, 2023

I don't know why this option works for you and not for me. Possibly because I'm opening the video file from Windows Explorer instead of dragging it into the window of a pre-launched mpv.
I'm tired. And I used a "dirty trick" - I wrote an autohotkey script that presses the 'home' key with some delay after starting the desired video files. Sloppy, but it works.

moviepath = (('d:\\Movies') or ('e:\\Movies') or ('e:\\Anime'))
ahkexe = 'c:\\ahk\\mpv-hide-thumbs-ahk.exe'

mp.register_event("file-loaded", function()
	if string.find(mp.get_property("working-directory"), moviepath) then 
		mp.commandv('run', ahkexe)
	end
end)
#SingleInstance force
#NoTrayIcon

Sleep, 800
Send, {home}
exit

input.conf:

home script-binding uosc/hide-thumbnails

scripts\uosc_shared\elements\Timeline.lua

bind_command('hide-thumbnails', function()
	thumbnail.disabled = true
end)
bind_command('show-thumbnails', function()
	thumbnail.disabled = false
end)

@tomasklaen
Copy link
Owner

Feel free to discuss this further here, but since this doesn't seem to concern uosc I'm going to close it for now.

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

4 participants