Skip to content

Commit

Permalink
condition: run evaluation when alang or slang is no
Browse files Browse the repository at this point in the history
  • Loading branch information
CogentRedTester committed Jan 3, 2023
1 parent 2040b6a commit 2c68de9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ All titles are converted to lowercase automatically to allow more matches.
This expression will be run for every subtitle that passes the other filters. The `sub` variable contains the subtitle
track entry and `audio` contains the audio track entry. See the [track-list property](https://mpv.io/manual/master/#command-interface-track-list)
for what fields are available. The `mp`, `mp.msg`, and `mp.utils` modules are avaialble as `mp`, `msg`, and `utils`, respectively.
If no audio or sub track is being compared (which only happens if you set alang or slang to `no`) then `audio` or `sub` will evaluate to `nil`.

### String Matching

Expand Down
6 changes: 4 additions & 2 deletions sub-select.lua
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,13 @@ local function find_valid_tracks(manual_audio)
msg.debug("checking for valid sub:", slang)

--special handling when we want to disable subtitles
if slang == "no" then return aid, 0 end
if slang == "no" and (not pref.condition or (evaluate_string('return '..pref.condition, { audio = audio_track or nil }) == true))then
return aid, 0
end

for _,sub_track in ipairs(sub_tracks) do
if is_valid_sub(sub_track, slang, pref)
and (not pref.condition or (evaluate_string('return '..pref.condition, { audio = audio_track, sub = sub_track }) == true))
and (not pref.condition or (evaluate_string('return '..pref.condition, { audio = audio_track or nil, sub = sub_track }) == true))
then
return aid, sub_track.id
end
Expand Down

0 comments on commit 2c68de9

Please sign in to comment.