discToMkv.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. # Config
  3. DRIVE_NUM="1"
  4. OUT_DIR="${HOME}/Desktop/Docs/Downloads"
  5. APP_PATH="/Applications/Zach/Media/MakeMKV.app"
  6. # Globals
  7. BIN_PATH="${APP_PATH}/Contents/MacOS/makemkvcon"
  8. TMP="`mktemp -t discToMkv`"
  9. # Sanity check
  10. if [ ! -d "${OUT_DIR}" ]; then
  11. echo "Invalid output directory: ${OUT_DIR}"
  12. exit 1
  13. fi
  14. # Parse the disc
  15. "${BIN_PATH}" --noscan --robot "--messages=${TMP}" info "disc:${DRIVE_NUM}"
  16. # Find the disk title -- long if available, short if not
  17. CINFO="`grep '^CINFO\:' "${TMP}"`"
  18. LONG="`echo "${CINFO}" | awk -F ',' '$1 == "CINFO:2" && $2 == "0" {print $3}' | sed 's%^"\(.*\)"$%\1%'`"
  19. SHORT="`echo "${CINFO}" | awk -F ',' '$1 == "CINFO:32" && $2 == "0" {print $3}' | sed 's%^"\(.*\)"$%\1%'`"
  20. NAME="${LONG}"
  21. if [ -z "${NAME}" ]; then
  22. NAME="${SHORT}"
  23. fi
  24. # Cleanup the parse data
  25. rm -f "${TMP}"
  26. # Sanity check
  27. if [ -z "${NAME}" ]; then
  28. echo "Unable to determine disc name" 1>&2
  29. exit 1
  30. fi
  31. # Create the output directory
  32. if [ ! -d "${OUT_DIR}/${NAME}" ]; then
  33. mkdir "${OUT_DIR}/${NAME}"
  34. fi
  35. # Extract all tracks to MKVs
  36. # Tracks are selected with the default profile (as set in the GUI)
  37. # Recommended selection string: -sel:all,+sel:(favlang|nolang),-sel:(core),+sel:special,-sel:mvcvideo,=100:all,-10:favlang
  38. # This preserves all audio and subtitles in your prefered language, all audio and subtitles with no language, and all special tracks, but excludes the core audio from DTS-HD tracks
  39. exec "${BIN_PATH}" --noscan --robot mkv "disc:${DRIVE_NUM}" all "${OUT_DIR}/${NAME}"