findAllTorrents.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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
  40. "${VIDEO_DIR}/findTorrent.sh" "${SERIES}" 2>/var/tmp/find.err
  41. if [ $? -ne 0 ]; then
  42. echo "Skipping: ${SERIES}" 1>&2
  43. continue
  44. fi
  45. # Loop on the null-delimited list of monitored series/seasons
  46. done < <("${VIDEO_DIR}/torrentMonitored.pl" null)
  47. # Cleanup
  48. exit 0