Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/python3
- """Usage: kontrol.py <command>
- - : decrease volume
- + : increase volume
- m/mute : mute
- p/play : play/pause
- s/stop : stop playback"""
- import sys
- try:
- from kodipydent import Kodi
- except ModuleNotFoundError:
- print("kodipydent is required. pip3 install kodipydent\n")
- sys.exit(1)
- HOSTNAME = 'grapefruit'
- PORT = 8080
- USERNAME = 'kodi'
- PASSWORD = None
- KODI = Kodi(HOSTNAME, username=USERNAME, password=PASSWORD)
- def volume(increment=None, mute=False):
- if mute:
- _mute = KODI.Application.GetProperties(['muted'])['result']['muted']
- if _mute:
- KODI.Application.SetMute(False)
- else:
- KODI.Application.SetMute(True)
- else:
- _volume = KODI.Application.GetProperties(['volume'])['result']['volume']
- if '-' in increment:
- increment = increment.strip('-')
- adjustment = _volume - int(increment)
- else:
- increment = increment.strip('+')
- adjustment = _volume + int(increment)
- KODI.Application.SetVolume(adjustment)
- def playback(playpause=False, stop=False):
- try:
- _playerid = KODI.Player.GetActivePlayers()['result'][0]['playerid']
- except IndexError:
- # if nothing is playing
- pass
- if playpause:
- KODI.Player.PlayPause(_playerid)
- else:
- KODI.Player.Stop(_playerid)
- def senttext():
- pass
- def main():
- arg = None
- try:
- arg = sys.argv[1]
- except IndexError:
- print(__doc__)
- else:
- if '+' in arg or '-' in arg:
- volume(increment=arg)
- elif arg == 'm' or arg == 'mute':
- volume(mute=True)
- elif arg == 'p' or arg == 'play':
- playback(playpause=True)
- elif arg == 's' or arg == 'stop':
- playback(stop=True)
- # Movement
- elif arg == 'up':
- KODI.Input.Up()
- elif arg == 'down':
- KODI.Input.Down()
- elif arg == 'left':
- KODI.Input.Left()
- elif arg == 'right':
- KODI.Input.Right()
- elif arg == 'enter':
- KODI.Input.Select()
- elif arg == 'back':
- KODI.Input.Back()
- elif arg == 'senttext':
- #senttext()
- pass
- else:
- pass
- if __name__ == "__main__": main()
Add Comment
Please, Sign In to add comment