findTorrent.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/bash
  2. BASE_DIR="`~/bin/video/mediaPath`/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. SERIES="`basename "${SERIES_DIR}"`"
  23. # Find the season directory -- if no season is provided, use the last season in the series directory
  24. if [ -z "${SEASON}" ]; then
  25. SEASON="`ls "${SERIES_DIR}" | awk '$1 == "Season" && $2 ~ "[0-9]*" {print $2}' | sort -n -r | head -n 1`"
  26. SEASON=$(( $SEASON + 0 ))
  27. fi
  28. SEASON_DIR="${SERIES_DIR}/Season ${SEASON}"
  29. if [ ! -d "${SEASON_DIR}" ]; then
  30. echo "No such season directory: ${SEASON_DIR}" 1>&2
  31. usage
  32. fi
  33. # Special handling for search-by-date folders
  34. if [ -r "${SERIES_DIR}/search_by_date" ]; then
  35. SEARCH_STR=`cat "${SERIES_DIR}/search_by_date"`
  36. DEBUG=1 ~/bin/video/findDate.sh "${SERIES}" "${SEARCH_STR}" 0 3 | download
  37. exit $?
  38. fi
  39. # Run the standard command, in debug mode
  40. DEBUG=1 ~/bin/video/findTorrent.pl "${SEASON_DIR}" | download