-
Notifications
You must be signed in to change notification settings - Fork 6
/
widgetFunctions.py
executable file
·60 lines (52 loc) · 1.93 KB
/
widgetFunctions.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
import xbmc
import xbmcgui
import xbmcplugin
import xbmcaddon
import xbmcvfs
import random
import urllib
import datetime
import socket
from traceback import print_exc
from time import gmtime, strftime
if sys.version_info < (2, 7):
import simplejson
else:
import json as simplejson
__addon__ = xbmcaddon.Addon()
__addonversion__ = __addon__.getAddonInfo('version')
__addonid__ = __addon__.getAddonInfo('id')
__addonname__ = __addon__.getAddonInfo('name')
__localize__ = __addon__.getLocalizedString
def log(txt):
message = '%s: %s' % (__addonname__, txt.encode('ascii', 'ignore'))
xbmc.log(msg=message, level=xbmc.LOGDEBUG)
class Main:
def __init__(self):
self._parse_argv()
try:
clientsocket = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
clientsocket.connect( ( "localhost", 45354 ) )
if self.ID is None:
log( "### (WIDGET) Sending message %s|%s" %( self.TYPE, sys.argv[ 1 ] ) )
clientsocket.send( "%s|%s" %( self.TYPE, sys.argv[ 1 ] ) )
else:
log( "### (WIDGET) Sending message %s|%s|%s" %( self.TYPE, self.ID, sys.argv[ 1 ] ) )
clientsocket.send( "%s|%s|%s" %( self.TYPE, self.ID, sys.argv[ 1 ] ) )
message = clientsocket.recv( 128 )
log( "### (WIDGET) Recieved message: " + message )
clientsocket.close()
except:
log( "Unable to establish connection to service" )
xbmcplugin.endOfDirectory(handle= int(sys.argv[1]))
def _parse_argv( self ):
try:
params = dict( arg.split( "=" ) for arg in sys.argv[ 2 ].split( "&" ) )
except:
params = {}
self.TYPE = params.get( "?type", "" )
self.ID = params.get( "id", None )