Guest User

Untitled

a guest
Oct 22nd, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #!/bin/python3
  2. import sys
  3. try:
  4. from kodipydent import Kodi
  5. except ModuleNotFoundError:
  6. print("kodipydent is required. pip3 install kodipydent\n")
  7. sys.exit(1)
  8.  
  9. # Just a Kodi remote
  10.  
  11. HOSTNAME = 'grapefruit'
  12. PORT = 8080
  13. USERNAME = 'kodi'
  14. PASSWORD = None
  15.  
  16. def main():
  17. help = "Usage: kontrol.py <command>\n" \
  18. "- : decrease volume\n" \
  19. "+ : increase volume\n" \
  20. "m/mute : mute\n" \
  21. "p/play : play/pause\n" \
  22. "s/stop : stop playback\n"\
  23.  
  24. _kodi = Kodi(HOSTNAME, username=USERNAME, password=PASSWORD)
  25. _mute = _kodi.Application.GetProperties(['muted'])['result']['muted']
  26. _volume = _kodi.Application.GetProperties(['volume'])['result']['volume']
  27. _playerid = _kodi.Player.GetActivePlayers()['result'][0]['playerid']
  28.  
  29. arg = None
  30. try:
  31. arg = sys.argv[1]
  32. except IndexError:
  33. print(help)
  34. else:
  35. if arg == '-':
  36. _kodi.Application.SetVolume(int(_volume - 5))
  37. elif arg == '+':
  38. _kodi.Application.SetVolume(int(_volume + 5))
  39. elif arg == 'm' or arg == 'mute':
  40. if _mute:
  41. _kodi.Application.SetMute(False)
  42. else:
  43. _kodi.Application.SetMute(True)
  44. elif arg == 'p' or arg == 'play':
  45. _kodi.Player.PlayPause(_playerid)
  46. elif arg == 's' or arg == 'stop':
  47. _kodi.Player.Stop(_playerid)
  48. else:
  49. print("Command doesn't exist")
  50.  
  51. main()
Add Comment
Please, Sign In to add comment