diff options
author | lonkaars <loek@pipeframe.xyz> | 2024-05-05 21:27:28 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2024-05-05 21:27:28 +0200 |
commit | de6449098e34fdda8d20837e902627ee4311f7f5 (patch) | |
tree | 3685319fd5fda8c0055c95296f6670a994dd983b /.local/share/bin/subrename | |
parent | 4927db50f51d483b611f0ed42f97e9ac3f6e5de3 (diff) |
update utilities
Diffstat (limited to '.local/share/bin/subrename')
-rwxr-xr-x | .local/share/bin/subrename | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/.local/share/bin/subrename b/.local/share/bin/subrename new file mode 100755 index 0000000..16d913f --- /dev/null +++ b/.local/share/bin/subrename @@ -0,0 +1,54 @@ +#!/bin/sh +file_extension=".srt" +season=1 +episode=1 + +PROGNAME="$(basename "$0")" +USAGE="$( cat << EOF +usage: $PROGNAME [-h] [-s season] [-e episode] [-x extension] file1 [file2 ...] + +rename files to s01e01.srt, s01e02.srt, etc. + +options: + -s set season number (default: $season) + -e set episode number of first file (default: $episode) + -x set file extension for output files (default: $file_extension) + -h show help + +example: + subrename -x .ja.srt *.srt +EOF +)" +usage() { + echo "$USAGE" + exit 0 +} +stupid() { + echo "use $PROGNAME -h for help" + exit 1 +} + +ARGC=0 +while getopts e:s:x:h OPT; do + [ $OPTIND -gt $ARGC ] && ARGC=$OPTIND + case "$OPT" in + e) episode="$OPTARG" ;; + h) usage ;; + s) season="$OPTARG" ;; + x) file_extension="$OPTARG" ;; + \?|*) stupid ;; + esac +done +shift "$(( $OPTIND - 1 ))" + +if [ $# -eq 0 ] ; then + echo "error: no files provided" + stupid +fi + +for file in "$@" ; do + new_filename="$(printf 's%02de%02d%s\n' "$season" "$episode" "$file_extension")" + mv --verbose "$file" "$new_filename" + episode=$(( $episode + 1 )) +done + |