findTorrent.sh 977 B

123456789101112131415161718192021222324252627282930313233343536373839
  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 -qE "\.\.?/"; then
  11. SERIES="`cd "${SERIES}" && pwd`"
  12. fi
  13. if echo "${SERIES}" | grep -q "/"; then
  14. SERIES_DIR="${SERIES}"
  15. else
  16. SERIES_DIR="${BASE_DIR}/${SERIES}"
  17. fi
  18. if [ ! -d "${SERIES_DIR}" ]; then
  19. echo "No such series directory: ${SERIES_DIR}" 1>&2
  20. usage
  21. fi
  22. # Find the season directory -- if no season is provided, use the last season in the series directory
  23. if [ -z "${SEASON}" ]; then
  24. SEASON="`ls "${SERIES_DIR}" | awk '$1 == "Season" && $2 ~ "[0-9]*" {print $2}' | sort -n -r | head -n 1`"
  25. SEASON=$(( $SEASON + 0 ))
  26. fi
  27. SEASON_DIR="${SERIES_DIR}/Season ${SEASON}"
  28. if [ ! -d "${SEASON_DIR}" ]; then
  29. echo "No such season directory: ${SEASON_DIR}" 1>&2
  30. usage
  31. fi
  32. # Run the standard command, in debug mode
  33. DEBUG=1 ~/bin/video/findTorrent.pl "${SEASON_DIR}" | download