If you ripped a bunch of TV programmes off DVD for storage and you named them dodge, quickly copy them to the correct place with this:

copy_season() {
  local show="$1"
  local season="$2"
  local quality="$3"

  if [ -z "$quality" ] || [ -z "$show" ] || [ -z "$season" ]; then
    echo "Usage: copy_season <show> <season> <quality>" >&2
    return 1
  fi

  mkdir -p "/path/to/media/$show/Season $season"

  for f in *; do
    # match S<season>E<ep> where season can be written with or without leading zero
    if [[ $f =~ [sS]0*${season}[eE]([0-9]{2}) ]]; then
      ep="${BASH_REMATCH[1]}"
      ext="${f##*.}"
      new=$(printf "S%02dE%02d - en - %s.%s" "$season" "$ep" "$quality" "$ext")
      cp -a -- "$f" "/path/to/media/$show/Season $season/$new"
    fi
  done
}

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.