folderFixup.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. # Parameters
  3. inFolder="/mnt/media/TV"
  4. # Command line
  5. if [ -n "${1}" ]; then
  6. inFolder="${1}"
  7. fi
  8. if [ ! -e "${inFolder}" ]; then
  9. echo "Usage: `basename "${0}"` input_folder" 1>&2
  10. exit 1
  11. fi
  12. # Bail if we're already running
  13. me="`basename "${0}"`"
  14. if [ `ps auwx | grep -v grep | grep "${me}" | wc -l` -gt 2 ]; then
  15. exit 0
  16. fi
  17. # Bail if the load average is high
  18. LOAD="`uptime | awk -F ': ' '{print $2}' | cut -d '.' -f 1`"
  19. CPU_COUNT="`sysctl -n hw.ncpu`"
  20. if [ $LOAD -gt $(( 2 * $CPU_COUNT )) ]; then
  21. exit 0
  22. fi
  23. # Bail if WoW is running
  24. if ps auwx | grep -v grep | grep -q "World of Warcraft/World of Warcraft.app/Contents/MacOS/World of Warcraft"; then
  25. exit 0
  26. fi
  27. # Bail if the media share isn't available
  28. if ! ~/bin/video/isMediaMounted; then
  29. exit 0
  30. fi
  31. # Cache output
  32. tmp="`mktemp -t 'folderFixup.XXXXXXXX'`"
  33. # Re-wrap or recode as needed
  34. find "${inFolder}" -mindepth 1 -type d -exec ~/bin/video/folderToMKV.sh {} \; 1>>"${tmp}" 2>&1
  35. # Filter the output
  36. cat "${tmp}" | \
  37. grep -Ev "^cp: .*: could not copy extended attributes to .*: Operation not permitted$" | \
  38. grep -v "GetFileInfo: could not get info about file (-1401)" | \
  39. grep -v "ERROR: Unexpected Error. (-1401) on file: " | \
  40. grep -v "ERROR: Unexpected Error. (-5000) on file: "