findAllTorrents.sh 1.4 KB

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