-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote.py
103 lines (85 loc) · 2.46 KB
/
remote.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import socket
from urllib.parse import urlparse
import configparser
import ssdp
import sys
class Tatasky:
buttonPower = 'e0 00'
buttonSelect = 'e0 01'
buttonBack = 'e0 02'
buttonVolumeUp = 'e0 03'
buttonVolumeDown = 'e0 04'
buttonMute = 'e0 05'
buttonChannelUp = 'e0 06'
buttonChannelDown = 'e0 07'
buttonApps = 'e0 08'
buttonHelp = 'e0 09'
buttonSettings = 'e0 0a'
buttonGuide = 'e0 0b'
buttonInfo = 'e0 0e'
buttonHome = 'e0 10'
buttonUp = 'e1 00'
buttonDown = 'e1 01'
buttonLeft = 'e1 02'
buttonRight = 'e1 03'
buttonRed = 'e2 00'
buttonGreen = 'e2 01'
buttonYellow = 'e2 02'
buttonBlue = 'e2 03'
button0 = 'e3 00'
button1 = 'e3 01'
button2 = 'e3 02'
button3 = 'e3 03'
button4 = 'e3 04'
button5 = 'e3 05'
button6 = 'e3 06'
button7 = 'e3 07'
button8 = 'e3 08'
button9 = 'e3 09'
buttonPlay = 'e4 00'
buttonPause = 'e4 01'
buttonRecord = 'e4 03'
buttonForward = 'e4 04'
buttonRewind = 'e4 06'
buttonTV = 'ef 00'
buttonFavs = 'ef 01'
buttonPlan = 'ef 02'
buttonOnDemand = 'ef 03'
def __init__(self, p_hostIP, p_hostPORT=5900):
self.ip = p_hostIP
self.port = p_hostPORT
self.socket = self.__createSocket()
def click(self, button):
self.socket.send(bytes.fromhex(
f'04 01 00 00 00 00 {button} 04 00 00 00 00 00 {button}'))
def __createSocket(self):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((self.ip, self.port))
assert s.recv(
50) == b'RFB 003.008\n', "Incorrect Init data from remote. Should be RFB 003.008\n"
s.send(bytes('RFB 003.008\n', 'ascii'))
assert s.recv(50) == bytes.fromhex('01 01')
s.send(bytes.fromhex('01'))
_ = s.recv(50)
s.send(bytes.fromhex('01'))
_ = s.recv(50)
return s
def __del__(self):
self.socket.close()
if __name__ == '__main__':
config = configparser.ConfigParser()
config.read('config.ini')
try:
hostIP = config['Tatasky']['ip']
except:
tvs = ssdp.scan_network()
if(len(tvs) == 0):
print('No devices found')
sys.exit()
for x in tvs:
hostIP = urlparse(x).hostname
config['Tatasky'] = {'ip': hostIP}
with open('config.ini', 'w') as configfile:
config.write(configfile)
t = Tatasky(hostIP)
t.click(Tatasky.buttonMute)