forked from NightRang3r/Broadlink-e-control-db-dump
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgetBroadlinkSharedData.py
121 lines (83 loc) · 3.18 KB
/
getBroadlinkSharedData.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*-
'''
This script will "parse" the broadlink e-Control Android application "SharedData" json files and dump the IR / RF codes for selected accessories into a text file which can be later used with broadlink-python to send the codes to the RM PRO hub
NO ROOT ACCESS REQUIRED
Just connect your Android device to your computer and browse the SD card / External Storage folder "/broadlink/newremote/SharedData/"
You need to get the following files:
jsonSubIr
jsonButton
jsonIrCode
and put them in the same folder as this script.
run: python getBroadlinkSharedData.py
or duplicate code by number
python getBroadlinkSharedData.py 5
'''
import base64, sys
try:
# Python 2.6+
import json
except ImportError:
try:
# from http://code.google.com/p/simplejson
import simplejson as json
except ImportError:
json = None
if json is None:
def dump_json(x, indent=None):
"""dumb not safe!
Works for the purposes of this specific script as quotes never
appear in data set.
Parameter indent ignored"""
if indent:
result = pprint.pformat(x, indent)
else:
result = repr(x).replace("'", '"')
return result
def load_json(x):
"""dumb not safe! Works for the purposes of this specific script"""
x = x.replace('\r', '')
return eval(x)
else:
dump_json = json.dumps
load_json = json.loads
IS_PY2 = sys.version_info[0] == 2
def hex2bin(x):
if IS_PY2:
return x.decode('hex')
else:
return bytes.fromhex(x)
if len(sys.argv) > 1:
MultipleCode = sys.argv[1]
else:
MultipleCode = "1"
buttonIDS = []
buttonNames = []
jsonSubIr = open("jsonSubIr").read()
jsonSubIrData = load_json(jsonSubIr)
for i in range(0, len(jsonSubIrData)):
print("ID:", jsonSubIrData[i]['id'], "| Name:", jsonSubIrData[i]['name'])
choice = input("Select accessory ID: ")
choice = int(choice)
for i in range(0, len(jsonSubIrData)):
if jsonSubIrData[i]['id'] == choice:
accessory_name = jsonSubIrData[i]['name']
print("[+] You selected: ", accessory_name)
jsonButton = open("jsonButton").read()
jsonButtonData = load_json(jsonButton)
for i in range(0, len(jsonButtonData)):
if jsonButtonData[i]['subIRId'] == choice:
buttonIDS.append(jsonButtonData[i]['id'])
buttonNames.append(jsonButtonData[i]['name'])
jsonIrCode = open("jsonIrCode").read()
jsonIrCodeData = load_json(jsonIrCode)
print("[+] Dumping codes to " + accessory_name + ".txt")
codesFile = open(accessory_name + '.txt', 'wb')
for i in range(0, len(jsonIrCodeData)):
for j in range(0, len(buttonIDS)):
if jsonIrCodeData[i]['buttonId'] == buttonIDS[j]:
code = ''.join('%02x' % (i & 0xff) for i in jsonIrCodeData[i]['code']) * int(MultipleCode)
code_bytes = hex2bin(code)
code_base64 = base64.b64encode(code_bytes)
code_base64 = code_base64.decode('utf-8')
result = "Button Name: " + buttonNames[j] + "\r\n" + "Button ID: " + str(jsonIrCodeData[i]['buttonId']) + "\r\n" + "Code: " + code + "\r\n" + "Base64: " + "\r\n" + code_base64 + "\r\n"
codesFile.write(result.encode('utf-8'))