findTorrent.sh 894 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. BASE_DIR="/mnt/media/TV"
  3. SERIES="${1}"
  4. SEASON="${2}"
  5. usage() {
  6. echo "Usage: `basename "${0}"` series_name [season]" 1>&2
  7. exit 1
  8. }
  9. # Find the series directory
  10. if echo "${SERIES}" | grep -q "/"; then
  11. SERIES_DIR="${SERIES}"
  12. else
  13. SERIES_DIR="${BASE_DIR}/${SERIES}"
  14. fi
  15. if [ ! -d "${SERIES_DIR}" ]; then
  16. echo "No such series directory: ${SERIES_DIR}" 1>&2
  17. usage
  18. fi
  19. # Find the season directory -- if no season is provided, use the last season in the series directory
  20. if [ -z "${SEASON}" ]; then
  21. SEASON="`ls "${SERIES_DIR}" | awk '$1 == "Season" && $2 ~ "[0-9]*" {print $2}' | sort -n -r | head -n 1`"
  22. SEASON=$(( $SEASON + 0 ))
  23. fi
  24. SEASON_DIR="${SERIES_DIR}/Season ${SEASON}"
  25. if [ ! -d "${SEASON_DIR}" ]; then
  26. echo "No such season directory: ${SEASON_DIR}" 1>&2
  27. usage
  28. fi
  29. # Run the standard command, in debug mode
  30. DEBUG=1 ~/bin/video/findTorrent.pl "${SEASON_DIR}" | download