findAllTorrents 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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}" | ~/bin/download
  36. # Print the series name on error
  37. if [ $? -ne 0 ]; then
  38. echo "${SERIES}"
  39. fi
  40. # Loop on the null-delimited list of monitored series/seasons
  41. done < <(~/bin/video/torrentMonitored.pl null)
  42. # Cleanup
  43. exit 0