plex 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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}" == "GUI" ]; then
  28. URL="${URL}?command=GetGuiDescription"
  29. OUTPUT=1
  30. else
  31. echo "Unknown command: ${CMD}" 1>&2
  32. exit 1
  33. fi
  34. # Bail if Plex is not running
  35. if ! ps awx -o comm= | grep -v 'Media Server' | grep -q 'MacOS/Plex'; then
  36. if [ $OUTPUT -gt 0 ]; then
  37. echo "Plex is not running" 1>&2
  38. exit 1
  39. fi
  40. exit 0
  41. fi
  42. # Run the command
  43. if [ $OUTPUT -gt 0 ]; then
  44. $CURL "${URL}"
  45. else
  46. $CURL "${URL}" >/dev/null
  47. fi