Guest User

Untitled

a guest
Oct 27th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. #!/bin/python3
  2. """Usage: kontrol.py <command>
  3. - : decrease volume
  4. + : increase volume
  5. m/mute : mute
  6. p/play : play/pause
  7. s/stop : stop playback"""
  8.  
  9. import sys
  10. try:
  11. from kodipydent import Kodi
  12. except ModuleNotFoundError:
  13. print("kodipydent is required. pip3 install kodipydent\n")
  14. sys.exit(1)
  15.  
  16. HOSTNAME = 'grapefruit'
  17. PORT = 8080
  18. USERNAME = 'kodi'
  19. PASSWORD = None
  20. KODI = Kodi(HOSTNAME, username=USERNAME, password=PASSWORD)
  21.  
  22.  
  23. def volume(increment=None, mute=False):
  24. if mute:
  25. _mute = KODI.Application.GetProperties(['muted'])['result']['muted']
  26. if _mute:
  27. KODI.Application.SetMute(False)
  28. else:
  29. KODI.Application.SetMute(True)
  30. else:
  31. _volume = KODI.Application.GetProperties(['volume'])['result']['volume']
  32. if '-' in increment:
  33. increment = increment.strip('-')
  34. adjustment = _volume - int(increment)
  35. else:
  36. increment = increment.strip('+')
  37. adjustment = _volume + int(increment)
  38. KODI.Application.SetVolume(adjustment)
  39.  
  40.  
  41. def playback(playpause=False, stop=False):
  42. try:
  43. _playerid = KODI.Player.GetActivePlayers()['result'][0]['playerid']
  44. except IndexError:
  45. # if nothing is playing
  46. pass
  47. if playpause:
  48. KODI.Player.PlayPause(_playerid)
  49. else:
  50. KODI.Player.Stop(_playerid)
  51.  
  52.  
  53. def senttext():
  54. pass
  55.  
  56.  
  57. def main():
  58. arg = None
  59. try:
  60. arg = sys.argv[1]
  61. except IndexError:
  62. print(__doc__)
  63. else:
  64. if '+' in arg or '-' in arg:
  65. volume(increment=arg)
  66. elif arg == 'm' or arg == 'mute':
  67. volume(mute=True)
  68. elif arg == 'p' or arg == 'play':
  69. playback(playpause=True)
  70. elif arg == 's' or arg == 'stop':
  71. playback(stop=True)
  72. # Movement
  73. elif arg == 'up':
  74. KODI.Input.Up()
  75. elif arg == 'down':
  76. KODI.Input.Down()
  77. elif arg == 'left':
  78. KODI.Input.Left()
  79. elif arg == 'right':
  80. KODI.Input.Right()
  81. elif arg == 'enter':
  82. KODI.Input.Select()
  83. elif arg == 'back':
  84. KODI.Input.Back()
  85. elif arg == 'senttext':
  86. #senttext()
  87. pass
  88. else:
  89. pass
  90.  
  91. if __name__ == "__main__": main()
Add Comment
Please, Sign In to add comment