History

TOOLS/autocrop.lua: log a more accurate warning

This reorders some code and checks the image track-list sub-property instead of the albumart one, so that when playing audio without enough playtime-remaining and images, the "autocrop only works for videos." warning is logged instead of the "Not enough time to detect crop." one. It also avoids repeating this warning twice in the code. As of e16d0dd15d current-tracks returns a video track even when lavfi-complex is used, so the track-list loop in is_cropable can be replaced with just checking current-tracks/video while still cropping videos with lavfi-complex.

Guido Cella committed 5 years ago

Commit 0772d021 parent ae6a22d1 file · +12 −18Browse files

Unified · Split

TOOLS/lua/autocrop.lua+12−18
@@ -107,14 +107,18 @@ function is_enough_time(seconds) · 106 unmodified lines
107 return playtime_remaining and time_needed < playtime_remaining107 return playtime_remaining and time_needed < playtime_remaining
108end108end
109 109
110function is_cropable()110function is_cropable(time_needed)
111 for _, track in pairs(mp.get_property_native('track-list')) do111 if mp.get_property_native('current-tracks/video/image') ~= false then
112 if track.type == 'video' and track.selected then112 mp.msg.warn("autocrop only works for videos.")
113 return not track.albumart113 return false
114 end
115 end114 end
116 115
117 return false116 if not is_enough_time(time_needed) then
117 mp.msg.warn("Not enough time to detect crop.")
118 return false
119 end
120
121 return true
118end122end
119 123
120function remove_filter(label)124function remove_filter(label)
@@ -142,18 +146,9 @@ function cleanup() · 21 unmodified lines
142end146end
143 147
144function detect_crop()148function detect_crop()
145
146 -- If it's not cropable, exit.
147 if not is_cropable() then
148 mp.msg.warn("autocrop only works for videos.")
149 return
150 end
151
152 -- Verify if there is enough time to detect crop.
153 local time_needed = options.detect_seconds149 local time_needed = options.detect_seconds
154 150
155 if not is_enough_time(time_needed) then151 if not is_cropable(time_needed) then
156 mp.msg.warn("Not enough time to detect crop.")
157 return152 return
158 end153 end
159 154
@@ -282,8 +277,7 @@ function on_start() · 122 unmodified lines
282 -- Verify if there is enough time for autocrop.277 -- Verify if there is enough time for autocrop.
283 local time_needed = options.auto_delay + options.detect_seconds278 local time_needed = options.auto_delay + options.detect_seconds
284 279
285 if not is_enough_time(time_needed) then280 if not is_cropable(time_needed) then
286 mp.msg.warn("Not enough time for autocrop.")
287 return281 return
288 end282 end
289 283

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t