plex 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  2. # Parameters
  3. USER="plex"
  4. PASS="bobola22"
  5. HOST="localhost"
  6. PORT="3000"
  7. # Figure out what we should do
  8. CMD="`basename "${0}" | sed 's%^plex\-%%' | tr a-z A-Z`"
  9. # Reduce typing
  10. CURL="curl --silent --get --user ${USER}:${PASS}"
  11. RPATH="/xbmcCmds/xbmcHttp"
  12. URL="http://${HOST}:${PORT}${RPATH}"
  13. OUTPUT=0
  14. # Pick a command
  15. if [ "${CMD}" == "UPDATE" ]; then
  16. URL="${URL}/?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video)"
  17. elif [ "${CMD}" == "CLEAN" ]; then
  18. URL="${URL}?command=ExecBuiltIn&parameter=XBMC.CleanLibrary(video)"
  19. elif [ "${CMD}" == "FILES" ]; then
  20. URL="${URL}?command=queryvideodatabase(SELECT%20path.strPath,%20files.strFilename%20FROM%20path%20JOIN%20files%20ON%20path.idPath%20=%20files.idPath%20JOIN%20episode%20ON%20files.idFile%20=%20episode.idFile)"
  21. OUTPUT=1
  22. elif [ "${CMD}" == "BUTTON" ]; then
  23. URL="${URL}?command=SendKey(${1})"
  24. elif [ "${CMD}" == "PLAYING" ]; then
  25. URL="${URL}?command=GetCurrentlyPlaying"
  26. OUTPUT=1
  27. elif [ "${CMD}" == "RESOLUTION" ]; then
  28. URL="${URL}?command=GetGuiDescription"
  29. OUTPUT=1
  30. elif [ "${CMD}" == "GUI" ]; then
  31. URL="${URL}?command=GetGuiStatus"
  32. OUTPUT=1
  33. else
  34. echo "Unknown command: ${CMD}" 1>&2
  35. exit 1
  36. fi
  37. # Bail if Plex is not running
  38. if ! ps awx -o comm= | grep -v 'Media Server' | grep -q 'MacOS/Plex'; then
  39. if [ $OUTPUT -gt 0 ]; then
  40. echo "Plex is not running" 1>&2
  41. exit 1
  42. fi
  43. exit 0
  44. fi
  45. # Run the command
  46. if [ $OUTPUT -gt 0 ]; then
  47. $CURL "${URL}"
  48. else
  49. $CURL "${URL}" >/dev/null
  50. fi