findTorrent.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. # Resolve relative paths
  10. if echo "${SERIES}" | grep -qE "\.\.?/"; then
  11. SERIES="`cd "${SERIES}" && pwd`"
  12. fi
  13. # Split the season directory, if provided
  14. if echo "${SERIES}" | grep -qE '\/Season [0-9]*\/?$'; then
  15. SEASON="`basename "${SERIES}" | sed 's%^Season %%'`"
  16. SERIES="`dirname "${SERIES}"`"
  17. fi
  18. # Construct the series directory path
  19. if echo "${SERIES}" | grep -q "/"; then
  20. SERIES_DIR="${SERIES}"
  21. else
  22. SERIES_DIR="${BASE_DIR}/${SERIES}"
  23. fi
  24. # Standardize the series name
  25. SERIES="`basename "${SERIES_DIR}"`"
  26. # Sanity check
  27. if [ ! -d "${SERIES_DIR}" ]; then
  28. echo "No such series directory: ${SERIES_DIR}" 1>&2
  29. usage
  30. fi
  31. # Find the season directory -- if no season is provided, use the last season in the series directory
  32. if [ -z "${SEASON}" ]; then
  33. SEASON="`ls "${SERIES_DIR}" | awk '$1 == "Season" && $2 ~ "[0-9]*" {print $2}' | sort -n -r | head -n 1`"
  34. SEASON=$(( $SEASON + 0 ))
  35. fi
  36. SEASON_DIR="${SERIES_DIR}/Season ${SEASON}"
  37. # Sanity check
  38. if [ ! -d "${SEASON_DIR}" ]; then
  39. echo "No such season directory: ${SEASON_DIR}" 1>&2
  40. usage
  41. fi
  42. # Enable DEBUG by default
  43. DEBUG=1
  44. if [ -n "${SILENT}" ]; then
  45. DEBUG=0
  46. fi
  47. export DEBUG
  48. # Special handling for search-by-date folders
  49. if [ -r "${SERIES_DIR}/search_by_date" ]; then
  50. SEARCH_STR=`cat "${SERIES_DIR}/search_by_date"`
  51. ~/bin/video/findDate.sh "${SERIES}" "${SEARCH_STR}" 0 3 | download
  52. exit $?
  53. fi
  54. # Run the standard command, in debug mode
  55. ~/bin/video/findTorrent.pl "${SEASON_DIR}" | download