Skip to content

Commit bb76cf5

Browse files
committed
Improved detection of successful conversions: using the HandBrake CLI return code is not enough to detect all errors.
1 parent 338520c commit bb76cf5

File tree

1 file changed

+15
-5
lines changed
  • rootfs/etc/services.d/autovideoconverter

1 file changed

+15
-5
lines changed

rootfs/etc/services.d/autovideoconverter/run

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ log_hb_encode_progress_yad() {
102102
2>/dev/null
103103
}
104104

105+
log_hb_encode_detect_success() {
106+
while read -r OUTPUT; do
107+
if [ "$OUTPUT" = "Encode done!" ]; then
108+
touch "$1"
109+
fi
110+
done
111+
}
112+
105113
WATCHDIR_HASH_calculate() {
106114
local watchdir="$1"
107115
find "$watchdir" -follow -type f -not -path '*/\.*' -printf '%T@:%s:%p:%m\n' | md5sum | cut -d' ' -f1
@@ -435,8 +443,8 @@ process_video() {
435443
$title_arg \
436444
--preset "$AC_PRESET" \
437445
$HANDBRAKE_HOOK_CUSTOM_ARGS \
438-
$AC_HANDBRAKE_CUSTOM_ARGS 2>> \
439-
/config/log/hb/conversion.log | \
446+
$AC_HANDBRAKE_CUSTOM_ARGS \
447+
2> >(tee -a /config/log/hb/conversion.log | log_hb_encode_detect_success "$OUTPUT_FILE_TMP".success ) | \
440448
/usr/bin/unbuffer -p grep "^Encoding" | \
441449
stdbuf -oL cut -d' ' -f2- | \
442450
tee >(log_hb_encode_progress) >(log_hb_encode_progress_yad) > /dev/null
@@ -445,9 +453,11 @@ process_video() {
445453
# Close YAD window.
446454
killall -SIGUSR1 yad 2> /dev/null
447455

448-
# Make sure the output file has been generated.
449-
if [ $hb_rc -eq 0 ] && [ ! -f "$OUTPUT_FILE_TMP" ]; then
450-
hb_rc=1
456+
# Make sure the video has been converted successfully.
457+
if [ $hb_rc -eq 0 ]; then
458+
if [ ! -f "$OUTPUT_FILE_TMP" ] || [ ! -f "$OUTPUT_FILE_TMP".success ]; then
459+
hb_rc=1
460+
fi
451461
fi
452462

453463
# Move the file to its final location if conversion terminated

0 commit comments

Comments
 (0)