Last active
September 13, 2015 08:53
-
-
Save kawashirov/38642a45e6777ac66c81 to your computer and use it in GitHub Desktop.
LG Control
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import http.client | |
| import sys | |
| from time import sleep | |
| headers = {'Content-Type': 'application/atom+xml'} | |
| key = { | |
| # | |
| # BLOCK MAIN | |
| 'POWER': 1, | |
| 'NUM_0': 2, | |
| 'NUM_1': 3, | |
| 'NUM_2': 4, | |
| 'NUM_3': 5, | |
| 'NUM_4': 6, | |
| 'NUM_5': 7, | |
| 'NUM_6': 8, | |
| 'NUM_7': 9, | |
| 'NUM_8': 10, | |
| 'NUM_9': 11, | |
| 'UP': 12, | |
| 'DOWN': 13, | |
| 'LEFT': 14, | |
| 'RIGHT': 15, | |
| # SKIP 16-19 | |
| 'OK': 20, | |
| 'HOME': 21, | |
| 'MENU': 22, | |
| 'BACK': 23, | |
| 'VOL_UP': 24, | |
| 'VOL_DOWN': 25, | |
| 'MUTE': 26, | |
| 'CH_UP': 27, | |
| 'CH_DOWN': 28, | |
| 'BLUE': 29, | |
| 'GREEN': 30, | |
| 'RED': 31, | |
| 'YELLOW': 32, | |
| 'PLAY': 33, | |
| 'PAUSE': 34, | |
| 'STOP': 35, | |
| 'FAST_FORWARD': 36, # FF | |
| 'REWIND': 37, # REW | |
| 'SKIP_FORWARD': 38, | |
| 'SKIP_BACKWARD': 39, | |
| 'RECORD': 40, | |
| 'RECORDING_LIST': 41, | |
| 'REPEAT': 42, | |
| 'LIVE_TV': 43, | |
| 'EPG': 44, # WTF? | |
| 'CURRENT_INFO': 45, # Current program information | |
| 'ASPECT_RATIO': 46, | |
| 'EXT_INPUT': 47, # External input | |
| 'PIP_SECONDARY_VIDEO': 48, # WTF? | |
| 'SUBTITLE': 49, | |
| 'PROGRAM_LIST': 50, # WTF? | |
| 'TELETEXT': 51, | |
| 'MARK': 52, | |
| # | |
| # BLOCK 4xx | |
| '3D_VIDEO': 400, | |
| '3D_LR': 401, | |
| 'DASH': 402, # '-' | |
| 'FALSH_BACK': 403, # WTF? Previous channel? | |
| 'FAVORITE': 404, | |
| 'QUICK_MENU': 405, | |
| 'TEXT_OPTION': 406, | |
| 'AUDIO_DESCRIPTION': 407, | |
| 'NET_CAST': 408, # same with Home menu | |
| 'ENERGY_SAVING': 409, | |
| 'AV_MODE': 410, | |
| 'SIMPLINK': 411, | |
| 'EXIT': 412, | |
| 'RESERVATION_PROGRAMS': 413, # WTF? | |
| 'PIP_CH_UP': 414, # WTF? | |
| 'PIP_CH_DOWN': 415, # WTF? | |
| 'VIDEO_SWITCH': 416, # Switching between primary/secondary video | |
| 'MY_APPS': 417 | |
| } | |
| def call_raw(ip, cmd, wait=0.5): | |
| conn = http.client.HTTPConnection( ip, port=8080) | |
| cmd_text = '<?xml version="1.0" encoding="utf-8"?><command><name>HandleKeyInput</name><value>' + cmd + '</value></command>' | |
| print('Calling HandleKeyInput(' + cmd + ')') | |
| conn.request("POST", "/roap/api/command", cmd_text, headers=headers) | |
| if wait : sleep(0.5) | |
| def call_int(ip, num): | |
| istr = str(num) | |
| for i in range(len(istr)): | |
| j = int(istr[i]) | |
| call_raw(ip, str(j + 2)) | |
| def call_btn(ip, btn, wait=0.5): | |
| call_raw(ip, str(key[btn]), wait) | |
| def call_seq(ip, seq): | |
| signals = seq.split(',') | |
| for signal in signals: | |
| t, v = signal.split(':') | |
| if t == 'R': call_raw(ip, v) | |
| elif t == 'I': call_int(ip, int(v)) | |
| elif t == 'B': call_btn(ip, v) | |
| else : print('UNKNOWN TYPE: ' + t) | |
| call_seq("192.168.1.50", sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment