folderToMKV.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. # Command line
  3. inFolder="${1}"
  4. if [ -z "${inFolder}" ] || [ ! -e "${inFolder}" ]; then
  5. echo "Usage: `basename "${0}"` input_folder" 1>&2
  6. exit 1
  7. fi
  8. # Bail if we're already running a lot
  9. me="`basename "${0}"`"
  10. if [ `ps auwx | grep -v grep | grep "${me}" | wc -l` -gt 10 ]; then
  11. exit 0
  12. fi
  13. # Bail if the load average is high
  14. LOAD="`uptime | awk -F ': ' '{print $2}' | cut -d '.' -f 1`"
  15. CPU_COUNT="`sysctl -n hw.ncpu`"
  16. if [ $LOAD -gt $(( 2 * $CPU_COUNT )) ]; then
  17. exit 0
  18. fi
  19. # Bail if WoW is running
  20. if ps auwx | grep -v grep | grep -q "World of Warcraft/World of Warcraft.app/Contents/MacOS/World of Warcraft"; then
  21. exit 0
  22. fi
  23. # Prefer recoding to rewrapping if the file is overrate
  24. ~/bin/video/findRecode0 "${inFolder}" | xargs -0 -n1 ~/bin/video/recode
  25. # MPEGs must be recoded, not just re-wrapped
  26. for i in "${inFolder}/"*.[mM][pP][gG] "${inFolder}/"*.[mM][pP][eE][gG]; do
  27. # Make sure the file is reasonable
  28. if [ ! -e "${i}" ]; then
  29. continue
  30. fi
  31. # Recode
  32. ~/bin/video/recode "${i}"
  33. done
  34. # Move to the input folder
  35. inFolder="`cd "${inFolder}" && pwd`"
  36. cd "${inFolder}"
  37. # Cycle through the folder looking for certain video files that should be converted to better containers
  38. for i in *.[aA][vV][iI] *.[wW][mM][vV] *.[dD][iI][vV][xX] *.[fF][lL][vV]; do
  39. # Construct the full path
  40. file="${inFolder}/${i}"
  41. # Make sure the file is reasonable
  42. if [ ! -e "${file}" ]; then
  43. continue
  44. fi
  45. # Rewrap as MOV
  46. ~/bin/video/toMKV.sh "${file}"
  47. done