| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #!/bin/bash
- # Parameters
- if [ -z "${TIMEOUT}" ]; then
- TIMEOUT=600
- fi
- VIDEO_DIR="${HOME}/bin/video"
- # Bail if the media share isn't available
- if ! "${VIDEO_DIR}/isMediaMounted"; then
- exit 0
- fi
- # Allow easy cancelation
- control_c() {
- echo "Canceled" 1>&2
- exit 1
- }
- trap control_c SIGINT
- trap control_c SIGTERM
- # Provide a method to skip ahead in the alphabetical list of series
- REGEX=""
- if [ -n "${1}" ]; then
- if ! echo "${1}" | grep -qi '^[a-z]$'; then
- echo "Usage: `basename "${0}"` [skip_to_char]" 1>&2
- exit 1
- fi
- REGEX="`echo "${1}" | tr 'A-Z' 'a-z'`"
- REGEX='^[0-9a-'"${REGEX}"']'
- fi
- # Run a search for each monitored series
- while read -d $'\0' SERIES ; do
- # Skip matching series
- if [ -n "${REGEX}" ]; then
- TITLE="`dirname "${SERIES}"`"
- TITLE="`basename "${TITLE}"`"
- if echo "${TITLE}" | grep -qi "${REGEX}"; then
- continue
- fi
- fi
- # Actual search, with timeout to ensure we don't get stuck
- URLS="`"${VIDEO_DIR}/timeout" -t "${TIMEOUT}" "${VIDEO_DIR}/findTorrent.pl" "${SERIES}"`"
- RET=$?
- if [ $RET -ne 0 ]; then
- if [ $RET -eq 143 ]; then
- echo "Timeout (${TIMEOUT}) searching: ${SERIES}" 1>&2
- else
- echo "Error (${RET}) searching: ${SERIES}" 1>&2
- fi
- continue
- fi
- # Download, if we found anything
- if [ -n "${URLS}" ]; then
- if ! echo "${URLS}" | bash -x "${VIDEO_DIR}/download.sh"; then
- echo "Error downloading: ${SERIES}" 1>&2
- continue
- fi
- fi
- # Loop on the null-delimited list of monitored series/seasons
- done < <("${VIDEO_DIR}/torrentMonitored.pl" null)
- # Cleanup
- exit 0
|