sync.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash
  2. # Target path
  3. TARGET="Heady"
  4. # Establish a base of operations
  5. BASE_DIR="`~/bin/video/mediaPath`"
  6. # We need an input directory
  7. SUB_DIR="${1}"
  8. # Allow absolute paths, or those relative to the media path
  9. if [ "`echo "${SUB_DIR}" | head -c 1`" == '/' ]; then
  10. SUB_DIR="`echo "${SUB_DIR}" | sed "s%^${BASE_DIR}/%%"`"
  11. fi
  12. # Allow single-file use
  13. if [ -f "${BASE_DIR}/${SUB_DIR}" ]; then
  14. FILE="`basename "${SUB_DIR}"`"
  15. SUB_DIR="`dirname "${SUB_DIR}"`"
  16. fi
  17. # Construct the final paths
  18. IN_DIR="${BASE_DIR}/${SUB_DIR}"
  19. OUT_DIR="${BASE_DIR}/${TARGET}/${SUB_DIR}"
  20. # Sanity check
  21. if [ ! -d "${IN_DIR}" ]; then
  22. echo "Invalid input directory: ${IN_DIR}" 1>&2
  23. exit 1
  24. fi
  25. # Remember where we came from
  26. START_DIR="`pwd`"
  27. # Go home
  28. cd "${IN_DIR}"
  29. # Ensure the output directory exists
  30. if [ ! -d "${OUT_DIR}" ]; then
  31. mkdir -p "${OUT_DIR}"
  32. fi
  33. # Export options for the encode script
  34. export OUT_DIR
  35. export MOBILE=1
  36. # Handle single-file, whole-folder, or recursive use
  37. if [ -n "${FILE}" ]; then
  38. FILES="${FILE}"
  39. else
  40. FILES="`ls [0-9]*\ -\ *.* 2>/dev/null`"
  41. fi
  42. # Allow recursive use for seasons
  43. for season in Season\ [0-9]*; do
  44. if [ ! -d "${season}" ]; then
  45. continue
  46. fi
  47. # Recurse for the season directory
  48. CMD="${0}"
  49. if [ "`echo "${CMD}" | head -c 1`" != '/' ]; then
  50. CMD="${START_DIR}/${0}"
  51. fi
  52. "${CMD}" "${IN_DIR}/${season}"
  53. # Disable the non-recursive case processing
  54. FILES=""
  55. done
  56. # Encode any missing files
  57. IFS=$'\n'
  58. for infile in $FILES; do
  59. # Skip non-files
  60. if [ ! -f "${infile}" ]; then
  61. continue
  62. fi
  63. # Don't get hung up on file extensions
  64. nobase="`echo "${infile}" | sed 's%\....$%%'`"
  65. # Skip files that exist
  66. if ls "${OUT_DIR}/${nobase}".* >/dev/null 2>&1; then
  67. continue
  68. fi
  69. # Encode things that do not
  70. ~/bin/video/encode.pl "${IN_DIR}/${infile}"
  71. done