findAllTorrents.sh 1.1 KB

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