-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.py
59 lines (50 loc) · 2.17 KB
/
default.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
import xbmc,re,httplib
import xml.etree.ElementTree as etree
import xbmcaddon
xbmcplugin = xbmcaddon.Addon()
lgtv = {}
lgtv["ipaddress"] = xbmcplugin.getSetting("ipaddress")
lgtv["pairingKey"] = xbmcplugin.getSetting("pairingkey")
lgtv["regex"] = xbmcplugin.getSetting("expression")
lgtv["sleep"] = int(xbmcplugin.getSetting("sleep"))
lgtv["ok"] = int(xbmcplugin.getSetting("ok"))
headers = {"Content-Type": "application/atom+xml"}
def getSessionid():
conn = httplib.HTTPConnection( lgtv["ipaddress"], port=8080)
pairCmd = "<?xml version=\"1.0\" encoding=\"utf-8\"?><auth><type>AuthReq</type><value>" \
+ lgtv["pairingKey"] + "</value></auth>"
conn.request("POST", "/roap/api/auth", pairCmd, headers=headers)
httpResponse = conn.getresponse()
if httpResponse.reason != "OK" : return False
tree = etree.XML(httpResponse.read())
return tree.find('session').text
def handleCommand(cmdcode):
conn = httplib.HTTPConnection( lgtv["ipaddress"], port=8080)
cmdText = "<?xml version=\"1.0\" encoding=\"utf-8\"?><command>" \
+ "<name>HandleKeyInput</name><value>" \
+ cmdcode \
+ "</value></command>"
conn.request("POST", "/roap/api/command", cmdText, headers=headers)
httpResponse = conn.getresponse()
class MyPlayer(xbmc.Player) :
global lgtv
def _init_ (self):
xbmc.Player._init_(self)
def onPlayBackStarted(self):
if xbmc.Player().isPlayingVideo():
currentPlayingFile = xbmc.Player().getPlayingFile()
if re.search(lgtv["regex"], currentPlayingFile, re.I):
lgtv["session"] = getSessionid()
if lgtv["session"]:
xbmc.sleep(lgtv["sleep"]) # sleep for a while, may need modification depending on your TV
handleCommand("400") # Send 3D button
xbmc.sleep(lgtv["ok"])
handleCommand("20") # Send Select button
lgtv["3Dmode"] = 1
def onPlayBackStopped(self):
if lgtv["3Dmode"] == 1:
handleCommand("400") # Send 3D button
lgtv["3Dmode"] = 0
player=MyPlayer()
while(1):
xbmc.sleep(500)