summaryrefslogtreecommitdiffstats
path: root/player/lua/auto_profiles.lua
Commit message (Collapse)AuthorAgeFilesLines
* auto_profiles: try to distinguish invalid properties betterDudemanguy2023-04-071-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 6e4a76db0862303ae7f0f9fd7bdddff128fbd2f0 attemped to reject invalid properties and print an error for users so they actually know that something is going wrong. This worked by simply checking if the property not found error is returned, but it is actually perfectly possible for a property to not be found (different than being unavailable just to be clear here) at first and then show up later. An example would be user-data which can be created at any time. It's also possible with subproperties of things like track-list where a new track could be added later. In light of this, let's soften the error checking logic here with a simple trick. mpv already keeps track of all toplevel properties and it can be easily retrieved with the "property-list" property, so just cache that. When we get a property not found error, instead of rejecting it, try to match it something in the property-list first. If we have a match, then consider the property valid and allow the script to behavior normally. If not, we reject it. This approach means property names that are obviously wrong like "fake-property-here" will reliably get rejected and something like "user-data/test" works as usual. The downside is that errors in the subproperty level are not caught, so something like "track-list/0/fake-property" would still be considered valid and the user gets no warning that this won't work. We'll just accept the compromise and hope this isn't too common. Fixes #11550.
* auto_profiles.lua: apply profiles when conditions are truthyGuido Cella2023-04-051-4/+1
| | | | | | | | | | | | Instead of erroring when values returned by profile-cond expressions aren't booleans, apply the relative profiles as long as the return values are truthy. This allows shortening conditions like profile-cond=path:match('foo') ~= nil to profile-cond=path:match('foo')
* auto_profiles: check for non-existent propertiesDudemanguy2023-03-291-1/+6
| | | | | | | | | | | Previously, it just silently didn't do anything which is not very intuitive. Since the lua api returns an error string, check to see if it matches the "property not found" case and print an error message. Additionally, don't add the fake property to the internal cached_properties list or try to observe it. This avoids redundant evaluate calls which will never actually succeed. We do still mark it under watched_properties however. This avoids having to call mp.get_property_native multiple times.
* auto_profiles.lua: don't warn if profile-restore=defaultCogentRedTester2022-01-301-1/+1
| | | | | | | | | | | | | | | The code assumed that the value of the profile-restore field is "default" for such profiles, but the C implementation is such that the field is intentionally omitted in such case. This resulted in incorrectly trying to restore such profiles. However, there are no stored values with profile-restore=default, so it only resulted in a harmless warning, but otherwise behaved correctly (i.e. nothing is restored). Fix the condition by taking into account that missing field means "default", so that it doesn't try to restore in such case, and avoid the warning.
* auto_profiles: fix compile_cond on lua 5.1Philip Sequeira2020-12-081-6/+10
| | | | | | 5.1's load() doesn't accept strings; loadstring must be used instead. In 5.2, loadstring is deprecated and setfenv is gone.
* auto_profiles: unapply conditional profiles if declaredwm42020-08-071-4/+10
| | | | | | Uses the mechanism introduced in the previous commit. The hope was to make auto-profiles easier to use, and to get rid of the need for manually created inverse profiles. Not sure if the end result is useful.
* auto_profiles: register hooks for more synchronous profile applicationwm42020-08-051-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | The property observation mechanism is fairly asynchronous to the player core, and Lua scripts also are (they run in a separate thread). This may sometimes lead to profiles being applied when it's too load. For example, you may want to change network options depending on the input URL - but most of these options would have to be set before the HTTP access is made. But it could happen that the profile, and thus the option, was applied at an slightly but arbitrary later time. This is generally not fixable. But for the most important use-cases, such as applying changes before media opening or playback initialization, we can use some of the defined hooks. Hooks make it synchronous again, by allowing API users (such as scripts) to block the core because it continues with loading. For this we simply don't continue a given hook, until we receive an idle event, and have applied all changes. The idle event is in general used to wait for property change notifications to settle down. Some of this relies on the subtle ways guarantees are (maybe) given. See commit ba70b150fbe for the messy details. I'm not quite sure whether it actually works, because I can't be bothered to read and understand my bullshit from half a year ago. Should provide at least some improvement, though.
* auto_profiles: add this scriptwm42020-08-051-0/+158
This is taken from a somewhat older proof-of-concept script. The basic idea, and most of the implementation, is still the same. The way the profiles are actually defined changed. I still feel bad about this being a Lua script, and running user expressions as Lua code in a vaguely defined environment, but I guess as far as balance of effort/maintenance/results goes, this is fine. It's a bit bloated (the Lua scripting state is at least 150KB or so in total), so in order to enable this by default, I decided it should unload itself by default if no auto-profiles are used. (And currently, it does not actually rescan the profile list if a new config file is loaded some time later, so the script would do nothing anyway if no auto profiles were defined.) This still requires defining inverse profiles for "unapplying" a profile. Also this is still somewhat racy. Both will probably be alleviated to some degree in the future.