#!/usr/bin/env bash set -euo pipefail usage() { echo "Использование: $0 --dir <корень библиотеки> [--strict]" } root="" strict=0 while [[ $# -gt 0 ]]; do case "$1" in --dir) root="${2:-}"; shift 2 ;; --strict) strict=1; shift ;; -h|--help) usage; exit 0 ;; *) echo "Неизвестный аргумент: $1" >&2; usage >&2; exit 2 ;; esac done if [[ -z "$root" || ! -d "$root" ]]; then echo "Укажите существующую папку через --dir" >&2 exit 2 fi issues=0 movies="$root/Movies" shows="$root/TV Shows" if [[ ! -d "$shows" ]]; then shows="$root/TV" fi if [[ -d "$movies" ]]; then echo "Фильмы: $movies" shopt -s nullglob for folder in "$movies"/*/; do folder="${folder%/}" name=$(basename "$folder") if [[ ! "$name" =~ \([0-9]{4}\)$ ]]; then echo " [!] нет года в папке: $name" issues=$((issues + 1)) fi found=0 for file in "$folder"/*; do [[ -f "$file" ]] || continue case "${file,,}" in *.mkv|*.mp4|*.avi|*.m4v|*.mov) found=1 ;; esac done if [[ "$found" -eq 0 ]]; then echo " [!] нет видеофайла: $name" issues=$((issues + 1)) fi done else echo "[!] Не найдена папка Movies" issues=$((issues + 1)) fi if [[ -d "$shows" ]]; then echo "Сериалы: $shows" shopt -s nullglob for show in "$shows"/*/; do show="${show%/}" seasons=("$show"/*/) if [[ ${#seasons[@]} -eq 0 ]]; then echo " [!] нет папок сезонов: $(basename "$show")" issues=$((issues + 1)) continue fi for season in "${seasons[@]}"; do season="${season%/}" season_name=$(basename "$season") if [[ ! "$season_name" =~ ^Season\ [0-9]{2}$ ]]; then echo " [!] формат сезона: $(basename "$show")/$season_name" issues=$((issues + 1)) fi for file in "$season"/*; do [[ -f "$file" ]] || continue base=$(basename "$file") if [[ ! "$base" =~ [Ss][0-9]{2}[Ee][0-9]{2,3} ]]; then echo " [!] нет SxxEyy: $(basename "$show")/$season_name/$base" issues=$((issues + 1)) fi done done done else echo "[!] Не найдена папка TV Shows или TV" issues=$((issues + 1)) fi echo "Проблем: $issues" if [[ "$strict" -eq 1 && "$issues" -gt 0 ]]; then exit 1 fi