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

Showing the changes to TOOLS/lua (1 of 1 file). Show all

Unified · Split

TOOLS/lua/autocrop.lua+12−18
@@ -107,14 +107,18 @@ function is_enough_time(seconds) · 106 unmodified lines
107107 return playtime_remaining and time_needed < playtime_remaining
108108 end
109109
110−function is_cropable()
111− for _, track in pairs(mp.get_property_native('track-list')) do
112− if track.type == 'video' and track.selected then
113− return not track.albumart
114− end
110+function is_cropable(time_needed)
111+ if mp.get_property_native('current-tracks/video/image') ~= false then
112+ mp.msg.warn("autocrop only works for videos.")
113+ return false
115114 end
116115
117− return false
116+ 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
118122 end
119123
120124 function remove_filter(label)
@@ -142,18 +146,9 @@ function cleanup() · 21 unmodified lines
142146 end
143147
144148 function 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.
153149 local time_needed = options.detect_seconds
154150
155− if not is_enough_time(time_needed) then
156− mp.msg.warn("Not enough time to detect crop.")
151+ if not is_cropable(time_needed) then
157152 return
158153 end
159154
@@ -282,8 +277,7 @@ function on_start() · 122 unmodified lines
282277 -- Verify if there is enough time for autocrop.
283278 local time_needed = options.auto_delay + options.detect_seconds
284279
285− if not is_enough_time(time_needed) then
286− mp.msg.warn("Not enough time for autocrop.")
280+ if not is_cropable(time_needed) then
287281 return
288282 end
289283

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