Handbrake post conversion script error


Recommended Posts

Hi All,

 

I'm trying to get Handbrake post conversion script to work. I made a script and put it into the hooks folder for Handbrake named post_conversion.sh. It's being run after an encode completes, but it gives an error and not the result I expect. When I run the script from the terminal though, I get the expected output. Any thoughts?

 

Handbrake Info:

Docker: jlesage/handbrake

Version 1.25.1

 

Script:

CONVERSION_STATUS=$1
CONVERTED_FILE="$2"
SOURCE_FILE="$3"
PRESET="$4"

echo "post-conversion: Status = $CONVERSION_STATUS"
echo "post-conversion: Output File = $CONVERTED_FILE"
echo "post-conversion: Source File = $SOURCE_FILE"
echo "post-conversion: Preset = $PRESET"

if [ "$CONVERSION_STATUS" -eq 0 ]; then
    # Successful conversion.
    FILE="${CONVERTED_FILE##*/}"
    echo " [$FILE]"
    
    # Check for show or movie
    REGEX='(.*)( - (S([0-9]+)E[0-9]+))'
    echo "REGEX = [$REGEX]"
    if [[ $FILE =~ $REGEX ]]; then
        SHOW=${BASH_REMATCH[1]}
        echo "SHOW = [$SHOW]"
        SEASON=$((10#${BASH_REMATCH[4]}))
        echo "SEASON = [$SEASON]"
        DESTINATION="/mnt/user/Media/TV Shows/$SHOW/Season $SEASON"
    else
        DESTINATION="/mnt/user/Media/Movies"
    fi
    
    # Move the file to the destination, making any directories as needed
    echo "➡️ $DESTINATION/$FILE"
else
    # Failed conversion.
    echo " $SOURCE_FILE"
fi

 

Output from Handbrake Logs:

[autovideoconverter] Executing post-conversion hook...
post-conversion: Status = 0
post-conversion: Output File = /output/Love Island - S08E33 - 1080p.mp4
post-conversion: Source File = /watch/Love Island - S08E33 - 1080p.mp4
post-conversion: Preset = General/Very Fast 1080p30
[Love Island - S08E33 - 1080p.mp4]
REGEX = [(.*)( - (S([0-9]+)E[0-9]+))]
sh: Island: unknown operand
➡️ /mnt/user/Media/Movies/Love Island - S08E33 - 1080p.mp4
[autovideoconverter] Post-conversion hook exited with 0

 

Terminal Testing:

Command: `bash /mnt/cache/appdata/HandBrake/hooks/post_conversion.sh 0 "/output/Love Island - S08E33 - 1080p.mp4" "/watch/Love Island - S08E33 - 1080p.mp4" "General/Very Fast 1080p30"`

Output:

post-conversion: Status = 0
post-conversion: Output File = /output/Love Island - S08E33 - 1080p.mp4
post-conversion: Source File = /watch/Love Island - S08E33 - 1080p.mp4
post-conversion: Preset = General/Very Fast 1080p30
[Love Island - S08E33 - 1080p.mp4]
REGEX = [(.*)( - (S([0-9]+)E[0-9]+))]
SHOW = [Love Island]
SEASON = [8]
➡️ /mnt/user/Media/TV Shows/Love Island/Season 8/Love Island - S08E33 - 1080p.mp4

 

Any thoughts on what's wrong with my script?

 

Link to comment

The issue is that the shell is different in the docker that is running your script. Try a script with sh --version to see the version of the interpreter you are dealing with.

 

The version of the docker interpreter cannot handle the space in the show, Love Island, after expansion in that if. While the one where you tested can. Because of that space after expansion your if is seeing Love and Island without an operand.

 

By no means am I a coder, did some googling and found possible solution on stackexchange.

 

You can, and from what I'm reading you should, double quote your vars, like this:

if [[ "$FILE" =~ "$REGEX" ]]; then

 

Don't just plug that in and run it blindly, make a script that prints out what you want it to do and see if it works.

 

BTW, here is what I googled "sh variable has space after expansion cannot equate to another"

 

Lastly, this isn't an unRAID issue, it's a general command interpreter programming issue. This should be in the lounge, or another advise section of the forum and not unRAID general support.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.