tvdup.sh 654 B

12345678910111213141516171819202122232425262728
  1. #!/bin/bash
  2. set failglob
  3. cd /mnt/media/TV
  4. lastNum=0
  5. while IFS= read -r -d '' lpath; do
  6. count=0
  7. file="`basename "${lpath}"`"
  8. dir="`dirname "${lpath}"`"
  9. num="`echo "${file}" | sed 's%\([0-9]*\).*%\1%'`"
  10. if [ -z "${num}" ]; then
  11. echo "Error on: ${lpath}" 1>&2
  12. continue
  13. fi
  14. if [ $num -eq $lastNum ]; then
  15. continue
  16. fi
  17. for i in "${dir}/${num} - "*; do
  18. count=$(( $count + 1 ))
  19. done
  20. if [ $count -ne 1 ]; then
  21. lastNum=$num
  22. echo "Multiple matches for: ${dir}/${num} - " 1>&2
  23. ls -lhtQ "${dir}/${num} - "*
  24. sudo chattr -i "${dir}/${num} - "*
  25. touch "${dir}/${num} - "*
  26. fi
  27. done< <(find . -type f -path '*Season*' -name '[0-9]*.*' -print0)