discToMkv.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. # Config
  3. DRIVE_NUM=1
  4. DR_DRIVE_NUM=$(( $DRIVE_NUM + 1 ))
  5. OUT_DIR="${HOME}/Desktop/Docs/Downloads"
  6. APP_PATH="/Applications/Zach/Media/MakeMKV.app"
  7. # Globals
  8. BIN_PATH="${APP_PATH}/Contents/MacOS/makemkvcon"
  9. TMP="`mktemp -t discToMkv`"
  10. # Sanity check
  11. if [ ! -d "${OUT_DIR}" ]; then
  12. echo "Invalid output directory: ${OUT_DIR}"
  13. exit 1
  14. fi
  15. # Ensure a disk is inserted
  16. if drutil -drive "${DR_DRIVE_NUM}" status | grep -q 'Type: No Media Inserted'; then
  17. echo "No disk available" 1>&2
  18. drutil -drive "${DR_DRIVE_NUM}" tray open
  19. exit 1
  20. fi
  21. # Parse the disc
  22. "${BIN_PATH}" --noscan --robot "--messages=${TMP}" info "disc:${DRIVE_NUM}"
  23. # Find the disk title -- long if available, short if not
  24. CINFO="`grep '^CINFO\:' "${TMP}"`"
  25. LONG="`echo "${CINFO}" | awk -F ',' '$1 == "CINFO:2" && $2 == "0" {print $3}' | sed 's%^"\(.*\)"$%\1%'`"
  26. SHORT="`echo "${CINFO}" | awk -F ',' '$1 == "CINFO:32" && $2 == "0" {print $3}' | sed 's%^"\(.*\)"$%\1%'`"
  27. NAME="${LONG}"
  28. if [ -z "${NAME}" ]; then
  29. NAME="${SHORT}"
  30. fi
  31. # Cleanup the parse data
  32. rm -f "${TMP}"
  33. # Sanity check
  34. if [ -z "${NAME}" ]; then
  35. echo "Unable to determine disc name" 1>&2
  36. exit 1
  37. fi
  38. # Create the output directory
  39. if [ ! -d "${OUT_DIR}/${NAME}" ]; then
  40. mkdir "${OUT_DIR}/${NAME}"
  41. fi
  42. # Extract all tracks to MKVs
  43. # Tracks are selected with the default profile (as set in the GUI)
  44. # Recommended selection string: -sel:all,+sel:(favlang|nolang),-sel:(core),+sel:special,-sel:mvcvideo,=100:all,-10:favlang
  45. # 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
  46. "${BIN_PATH}" --noscan --robot mkv "disc:${DRIVE_NUM}" all "${OUT_DIR}/${NAME}"
  47. # Bail on error
  48. if [ $? -ne 0 ]; then
  49. exit $?
  50. fi
  51. # Eject when complete
  52. DISK="`drutil -drive "${DR_DRIVE_NUM}" status | awk '$3 == "Name:" {print $4}'`"
  53. if [ -n "${DISK}" ]; then
  54. diskutil eject "${DISK}"
  55. fi