findAllTorrents.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  2. # Parameters
  3. if [ -z "${TIMEOUT}" ]; then
  4. TIMEOUT=600
  5. fi
  6. VIDEO_DIR="${HOME}/bin/video"
  7. # Bail if the media share isn't available
  8. if ! "${VIDEO_DIR}/isMediaMounted"; then
  9. exit 0
  10. fi
  11. # Allow easy cancelation
  12. control_c() {
  13. echo "Canceled" 1>&2
  14. exit 1
  15. }
  16. trap control_c SIGINT
  17. trap control_c SIGTERM
  18. # Provide a method to skip ahead in the alphabetical list of series
  19. REGEX=""
  20. if [ -n "${1}" ]; then
  21. if ! echo "${1}" | grep -qi '^[a-z]$'; then
  22. echo "Usage: `basename "${0}"` [skip_to_char]" 1>&2
  23. exit 1
  24. fi
  25. REGEX="`echo "${1}" | tr 'A-Z' 'a-z'`"
  26. REGEX='^[0-9a-'"${REGEX}"']'
  27. fi
  28. # Run a search for each monitored series
  29. while read -d $'\0' SERIES ; do
  30. # Skip matching series
  31. if [ -n "${REGEX}" ]; then
  32. TITLE="`dirname "${SERIES}"`"
  33. TITLE="`basename "${TITLE}"`"
  34. if echo "${TITLE}" | grep -qi "${REGEX}"; then
  35. continue
  36. fi
  37. fi
  38. # Search and download
  39. DEBUG=-1 "${VIDEO_DIR}/findTorrent.sh" "${SERIES}"
  40. if [ $? -ne 0 ]; then
  41. echo "Skipping: ${SERIES}" 1>&2
  42. continue
  43. fi
  44. # Loop on the null-delimited list of monitored series/seasons
  45. done < <("${VIDEO_DIR}/torrentMonitored.pl" null)
  46. # Cleanup
  47. exit 0