<commit_before>#! /bin/bash
: ${FFMPEG=ffmpeg} ${MPLAYER=mplayer}

set -e

SCRIPT=$(basename ${BASH_SOURCE[0]})

function help() {
	cat <<- EOF
This is help
EOF
	caller 0
	exit -1
}

function usage() {
	cat <<- EOF
This is usage
EOF
	caller 0
	exit -1
}

function die() {
	echo <<< "$@"
	exit -1
}

mode=0
while getopts ":hd:f:0123456789 -:" OPT
do
	if [[ $OPT == '-' ]] # Long option
	then
		OPT=$OPTARG
		eval $OPT && continue || usage # you may or may not want the continue
	fi
	case $OPT in
		-) echo Long option: $OPT $OPTARG # the continue above prevents reaching this
		;;
		h|help) help
		;;
		d|dest) dest="$OPTARG"
		;;
		f|format) format="$OPTARG"
		;;
		[0-9]) mode=$OPT
		;;
		\?) usage # getopts replaces unknown with ?
		;;
	esac
done >&2
shift $((OPTIND-1))

## defaults
format=png # jpeg
##

ext="${format##.}"

file_in="$1"
[[ -f "$file_in" ]] || die "file $file_in not found"
shift
[[ "$@" ]] && usage
basename="${file_in##*/}"
filepart="${basename%.*}"
[[ $dest ]] || dest="${basename}_thumbs"
mkdir -p "$dest"
[[ $errors ]] || errors="$dest/errors"

case $mode in
	0|1|2)
		function thumbs() {
			file_in="$1"
			out="${dest}/${filepart}_%08d${ext}"
			$FFMPEG -an -nostdin -i "$file_in" -f image2 -vframes 1 -vsync drop "$out"
		}
	;;
	3|4)
		function thumbs() {
			file_in="$1"
			out="${dest}/${filepart}_%08d${ext}"
			$FFMPEG -an -nostdin -i "$file_in" -f image2 -vf 'fps=1/240' -vsync drop "$out"
		}
	;;
	5|6|7)
		function thumbs() {
			file_in="$1"
			out="${dest}/${filepart}_%08d${ext}"
			$FFMPEG -an -nostdin -i "$file_in" -f image2 -vf select='eq(pict_type\,PICT_TYPE_I)' -vsync drop "$out"
		}
	;;
	8|9)
		function thumbs() {
			file_in="$1"
			out="${format}:${dest}"
			$MPLAYER -nosound -ss 240 "$file_in" -frames 64 -vo "$out"
		}
	;;
esac

if thumbs "$file_in" &> "$errors"
then
	exit 0
else
	cat "$errors"
fi >&2
exit 1<commit_msg>Fixed output<commit_after>#! /bin/bash
: ${FFMPEG=ffmpeg} ${MPLAYER=mplayer}

set -e

SCRIPT=$(basename ${BASH_SOURCE[0]})

function help() {
	cat <<- EOF
This is help
EOF
	caller 0
	exit -1
}

function usage() {
	cat <<- EOF
This is usage
EOF
	caller 0
	exit -1
}

function die() {
	echo <<< "$@"
	exit -1
}

mode=0
while getopts ":hd:f:0123456789 -:" OPT
do
	if [[ $OPT == '-' ]] # Long option
	then
		OPT=$OPTARG
		eval $OPT && continue || usage # you may or may not want the continue
	fi
	case $OPT in
		-) echo Long option: $OPT $OPTARG # the continue above prevents reaching this
		;;
		h|help) help
		;;
		d|dest) dest="$OPTARG"
		;;
		f|format) format="$OPTARG"
		;;
		[0-9]) mode=$OPT
		;;
		\?) usage # getopts replaces unknown with ?
		;;
	esac
done >&2
shift $((OPTIND-1))

## defaults
format=png # jpeg
##

ext="${format##.}"

file_in="$1"
[[ -f "$file_in" ]] || die "file $file_in not found"
shift
[[ "$@" ]] && usage
basename="${file_in##*/}"
filepart="${basename%.*}"
[[ $dest ]] || dest="${basename}_thumbs"
mkdir -p "$dest"
[[ $errors ]] || errors="$dest/errors"

case $mode in
	0|1|2)
		function thumbs() {
			file_in="$1"
			out="${dest}/${filepart}_%08d${ext}"
			$FFMPEG -an -nostdin -i "$file_in" -f image2 -vframes 1 -vsync drop "$out"
		}
	;;
	3|4)
		function thumbs() {
			file_in="$1"
			out="${dest}/${filepart}_%08d${ext}"
			$FFMPEG -an -nostdin -i "$file_in" -f image2 -vf 'fps=1/240' -vsync drop "$out"
		}
	;;
	5|6|7)
		function thumbs() {
			file_in="$1"
			out="${dest}/${filepart}_%08d${ext}"
			$FFMPEG -an -nostdin -i "$file_in" -f image2 -vf select='eq(pict_type\,PICT_TYPE_I)' -vsync drop "$out"
		}
	;;
	8|9)
		function thumbs() {
			file_in="$1"
			out="${format}:${dest}"
			$MPLAYER -nosound -ss 240 "$file_in" -frames 64 -vo "$out"
		}
	;;
esac

if thumbs "$file_in" &> "$errors"
then
	echo "$dest"
	exit 0
else
	cat "$errors" >&2
fi
exit 1
{'fraction_non_alphanumeric': 0.21373436252328987, 'fraction_numerical': 0.030875698695767898, 'mean_word_length': 3.447337278106509, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 9, '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': '5353400', 'n_tokens_mistral': 1738, 'n_tokens_neox': 1573, 'n_words': 402}