<commit_before>#!/bin/bash
#
# detect-crop.sh
#
# Copyright (c) 2013-2014 <NAME>
#

about() {
    cat <<EOF
$program 3.0 of October 23, 2014
Copyright (c) 2013-2014 <NAME>
EOF
    exit 0
}

usage() {
    cat <<EOF
Detect crop values for video file or disc image directory to use with
\`mplayer\` and \`transcode-video.sh\` (a wrapper script for \`HandBrakeCLI\`).

Usage: $program [OPTION]... [FILE|DIRECTORY]

    --title NUMBER      select numbered title in video media (default: 1)
                            (\`0\` to scan media, list title numbers and exit)
    --max-step MINUTES  maximum interval between samples (default: 5)
                            (Must be integer between 1 and 10)
    --no-constrain      don't constrain crop to optimal shape

    --help              display this help and exit
    --version           output version information and exit

Requires \`HandBrakeCLI\` and \`mplayer\` executables in \$PATH.
EOF
    exit 0
}

syntax_error() {
    echo "$program: $1" >&2
    echo "Try \`$program --help\` for more information." >&2
    exit 1
}

die() {
    echo "$program: $1" >&2
    exit ${2:-1}
}

deprecated() {
    echo "$program: deprecated option: $1" >&2
}

calculate_crop() {

    if [ "$constrain" ]; then
        local delta_x="$(($width - $crop_width))"
        local delta_y="$(($height - $crop_height))"

        if (($delta_x && $delta_y)); then

            if (($delta_x > $delta_y)); then
                crop_height="$height"
                crop_y='0'
            else
                crop_width="$width"
                crop_x='0'
            fi
        fi

        local min_crop="$(($width / 64))"
        min_crop="$(($min_crop + ($min_crop % 2)))"
        delta_x="$(($width - $crop_width))"

        if (($delta_x && ($delta_x < $min_crop))); then
            crop_width="$width"
        fi

        delta_y="$(($height - $crop_height))"

        if (($delta_y && ($delta_y < $min_crop))); then
            crop_height="$height"
        fi
    fi

    if (($crop_width == 0)); then
        crop_width="$width"
    fi

    if (($crop_height == 0)); then
        crop_height="$height"
    fi

    if (($crop_x == $width)); then
        crop_x='0'<commit_msg>Fix minimum crop origin and update `detect-crop.sh` to 3.1.<commit_after>#!/bin/bash
#
# detect-crop.sh
#
# Copyright (c) 2013-2014 <NAME>
#

about() {
    cat <<EOF
$program 3.1 of October 29, 2014
Copyright (c) 2013-2014 <NAME>
EOF
    exit 0
}

usage() {
    cat <<EOF
Detect crop values for video file or disc image directory to use with
\`mplayer\` and \`transcode-video.sh\` (a wrapper script for \`HandBrakeCLI\`).

Usage: $program [OPTION]... [FILE|DIRECTORY]

    --title NUMBER      select numbered title in video media (default: 1)
                            (\`0\` to scan media, list title numbers and exit)
    --max-step MINUTES  maximum interval between samples (default: 5)
                            (Must be integer between 1 and 10)
    --no-constrain      don't constrain crop to optimal shape

    --help              display this help and exit
    --version           output version information and exit

Requires \`HandBrakeCLI\` and \`mplayer\` executables in \$PATH.
EOF
    exit 0
}

syntax_error() {
    echo "$program: $1" >&2
    echo "Try \`$program --help\` for more information." >&2
    exit 1
}

die() {
    echo "$program: $1" >&2
    exit ${2:-1}
}

deprecated() {
    echo "$program: deprecated option: $1" >&2
}

calculate_crop() {

    if [ "$constrain" ]; then
        local delta_x="$(($width - $crop_width))"
        local delta_y="$(($height - $crop_height))"

        if (($delta_x && $delta_y)); then

            if (($delta_x > $delta_y)); then
                crop_height="$height"
                crop_y='0'
            else
                crop_width="$width"
                crop_x='0'
            fi
        fi

        local min_crop="$(($width / 64))"
        min_crop="$(($min_crop + ($min_crop % 2)))"
        delta_x="$(($width - $crop_width))"

        if (($delta_x && ($delta_x < $min_crop))); then
            crop_width="$width"
            crop_x='0'
        fi

        delta_y="$(($height - $crop_height))"

        if (($delta_y && ($delta_y < $min_crop))); then
            crop_height="$height"
            crop_y='0'
        fi
    fi

    if (($crop_width == 0)); then
        crop_width="$width"
    fi

    if (($crop_height == 0)); then
        crop_height="$height"
    fi

    if (($crop_x == $width)); then
        crop_x='0'
{'fraction_non_alphanumeric': 0.15057573073516387, 'fraction_numerical': 0.023029229406554472, 'mean_word_length': 1.9973457199734572, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '54904', 'n_tokens_mistral': 1593, 'n_tokens_neox': 1479, 'n_words': 427}