folderFixup.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/bash
  2. # Parameters
  3. inFolder="`~/bin/video/mediaPath`/TV"
  4. # Debug
  5. if [ -n "${DEBUG}" ] && [ $DEBUG -gt 0 ]; then
  6. echo -n "Starting `basename "${0}"`: "
  7. date
  8. fi
  9. # Command line
  10. if [ -n "${1}" ]; then
  11. inFolder="${1}"
  12. fi
  13. if [ ! -e "${inFolder}" ]; then
  14. echo "Usage: `basename "${0}"` input_folder" 1>&2
  15. exit 1
  16. fi
  17. # Bail if we're already running
  18. me="`basename "${0}"`"
  19. if [ `ps auwx | grep -v grep | grep "${me}" | wc -l` -gt 3 ]; then
  20. if [ -n "${DEBUG}" ] && [ $DEBUG -gt 0 ]; then
  21. echo 'Already running' 1>&2
  22. fi
  23. exit 0
  24. fi
  25. # Bail if the load is high
  26. if ! ~/bin/video/checkLoad.sh; then
  27. if [ -n "${DEBUG}" ] && [ $DEBUG -gt 0 ]; then
  28. echo 'Load too high' 1>&2
  29. fi
  30. exit 0
  31. fi
  32. # Bail if the media share isn't available
  33. if ! ~/bin/video/isMediaMounted; then
  34. echo 'Media not mounted' 1>&2
  35. exit 1
  36. fi
  37. # Cache output
  38. tmp="`mktemp -t 'folderFixup.XXXXXXXX'`"
  39. # Re-wrap or recode as needed
  40. find "${inFolder}" -mindepth 1 -type d -exec ~/bin/video/folderToMKV.sh {} \; 1>>"${tmp}" 2>&1
  41. # Filter the output
  42. cat "${tmp}" | \
  43. grep -Ev "^cp: .*: could not copy extended attributes to .*: Operation not permitted$" | \
  44. grep -v "GetFileInfo: could not get info about file (-1401)" | \
  45. grep -v "ERROR: Unexpected Error. (-1401) on file: " | \
  46. grep -v "ERROR: Unexpected Error. (-5000) on file: " | \
  47. grep -v "^ *$"
  48. # Cleanup
  49. rm -rf "${tmp}"
  50. # Debug
  51. if [ -n "${DEBUG}" ] && [ $DEBUG -gt 0 ]; then
  52. echo -n 'Complete: '
  53. date
  54. fi