scan.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. SCAN_CMD="/Applications/Zach/Media/Plex Media Server.app/Contents/MacOS/Plex Media Scanner"
  3. # Default to "scan" if no action is provided
  4. if ! echo "${@}" | grep -q -E -- '--(refresh|analyze|index|scan|info|list|generate|tree|reset|add-section|del-section)'; then
  5. exec "${0}" '--scan' ${@}
  6. fi
  7. # Bail if the media share isn't mounted
  8. if ! ~/bin/video/isMediaMounted; then
  9. exit 0
  10. fi
  11. # Bail if we are already scanning
  12. if ~/bin/video/pms/isScanning.sh; then
  13. exit 0
  14. fi
  15. # Scan each section individually if no scope is provided
  16. if echo "${@}" | grep -q -E -- '--(section|item|directory|file)'; then
  17. "${SCAN_CMD}" ${@}
  18. else
  19. for i in `~/bin/video/pms/sections.sh`; do
  20. "${SCAN_CMD}" --section "${i}" ${@}
  21. done
  22. fi
  23. # Check the return code; kill the PMS if things did not go well
  24. if [ $? -ne 0 ]; then
  25. ~/bin/video/pms/killPMS.sh
  26. fi
  27. # Empty the trash if we scanned and conditions are safe
  28. if echo "${@}" | grep -q -- '--scan'; then
  29. ~/bin/video/pms/emptyTrash.sh
  30. fi
  31. # Force an optimization after deep scans
  32. if echo "${@}" | grep -q -- '--deep'; then
  33. ~/bin/video/pms/optimize.sh
  34. fi