Advertisement
metalx1000

Kodi Shell Remote Control for WebUI

Dec 29th, 2021
4,892
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.48 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2021  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. ######################################################################
  19. ip="192.168.1.4"
  20. port="8080"
  21. cmd="  play-pause"
  22.  
  23. function main(){
  24.   playerid="$(get_playerid)"
  25.   while [ 1 ]
  26.   do
  27.     menu  
  28.   done
  29. }
  30.  
  31. function get_playerid(){
  32.   send_cmd '[{"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":1,"params":[]},{"jsonrpc":"2.0","method":"Application.GetProperties","id":2,"params":[["volume","muted"]]}]'|\
  33.     jq -r '.[0].result[0].playerid'
  34.   }
  35.  
  36. function menu(){
  37.   cmd="$(echo "$cmd
  38.   quit
  39.   play-pause
  40.   seek 10
  41.   seek -10
  42.   seek 30
  43.   seek -30
  44.   volume"|fzf)"
  45.   $cmd
  46. }
  47.  
  48. function quit(){
  49.   exit
  50. }
  51.  
  52. function send_cmd(){
  53.   curl -s 'http://192.168.1.4:8080/jsonrpc' \
  54.     -H 'Connection: keep-alive' \
  55.     -H 'Accept: application/json, text/javascript, */*; q=0.01' \
  56.     -H 'X-Requested-With: XMLHttpRequest' \
  57.     -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36' \
  58.     -H 'Content-Type: application/json' \
  59.     -H 'Sec-GPC: 1' \
  60.     -H "Origin: http://$ip:$port" \
  61.     -H "Referer: http://$ip:$port/" \
  62.     -H 'Accept-Language: en-US,en;q=0.9' \
  63.     --data-raw "$*" \
  64.     --compressed \
  65.     --insecure|jq .
  66.  
  67. }
  68.  
  69. function play-pause(){
  70.   send_cmd "{\"jsonrpc\":\"2.0\",\"method\":\"Player.PlayPause\",\"id\":1,\"params\":[$playerid,\"toggle\"] }"
  71. }
  72.  
  73. function seek(){
  74.   send_cmd "{\"jsonrpc\":\"2.0\", \"method\":\"Player.Seek\", \"params\": { \"playerid\":$playerid, \"value\":{ \"seconds\": $* } }, \"id\":1}"
  75. }
  76.  
  77. function volume(){
  78.   volume="$(seq 0 100|fzf --prompt "Select a Volume: ")"
  79.   send_cmd "{\"jsonrpc\":\"2.0\",\"method\":\"Application.SetVolume\",\"id\":1,\"params\":[$volume]}"
  80. }
  81.  
  82. main $*
  83.  
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement