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.
Unified · Split
| @@ -107,14 +107,18 @@ function is_enough_time(seconds) · 106 unmodified lines | ||
| 107 | 107 | return playtime_remaining and time_needed < playtime_remaining |
| 108 | 108 | end |
| 109 | 109 | |
| 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 | |
| 115 | 114 | end |
| 116 | 115 | |
| 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 | |
| 118 | 122 | end |
| 119 | 123 | |
| 120 | 124 | function remove_filter(label) |
| @@ -142,18 +146,9 @@ function cleanup() · 21 unmodified lines | ||
| 142 | 146 | end |
| 143 | 147 | |
| 144 | 148 | 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. | |
| 153 | 149 | local time_needed = options.detect_seconds |
| 154 | 150 | |
| 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 | |
| 157 | 152 | return |
| 158 | 153 | end |
| 159 | 154 | |
| @@ -282,8 +277,7 @@ function on_start() · 122 unmodified lines | ||
| 282 | 277 | -- Verify if there is enough time for autocrop. |
| 283 | 278 | local time_needed = options.auto_delay + options.detect_seconds |
| 284 | 279 | |
| 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 | |
| 287 | 281 | return |
| 288 | 282 | end |
| 289 | 283 | |