def run(self): # Connect try: htsp = HTSPClient((host, port)) msg = htsp.hello() sernam = msg['servername'] server = msg['serverversion'] xbmc.log( '[%s] %s connected to [%s] / %s [%s] / HTSP v%d' % (addonname, htsp._name, host, sernam, server, htsp._version)) # msg = '%s connected to [%s] / %s [%s] / HTSP v%d' % (htsp._name, host, sernam, server, htsp._version) # xbmcgui.Dialog().notification(addonname, msg, xbmcgui.NOTIFICATION_INFO, 2000) except Exception, e: constngs = addon.getLocalizedString(30000) tvhehost = 'TVh Host' # addon.getLocalizedString(30001) htspport = 'HTSP Port' # addon.getLocalizedString(30002) # notify user of error xbmc.log( '[%s] %s %s [%s] %s [%s] %s' % (addonname, constngs, tvhehost, host, htspport, port, str(e))) xbmcgui.Dialog().ok( addonname, '%s\n%s [%s] %s [%s]\n%s' % (constngs, tvhehost, host, htspport, port, str(e))) isc.set() # set event flag for indication to the main thread return
def createHTSPConn(): '''Create a HTSP connection.''' # Attempt to connect to the server try: htsp = HTSPClient(('localhost', 9982)) msg = htsp.hello() # Initial handshake htsp.authenticate(tvhaccount[0], tvhaccount[1]) # Authenticate htsp.send('getDiskSpace') # Test message msg = htsp.recv() if msg is None: logPrint('Error sending message to TVHeadend server. null response received.') htsp = None elif 'noaccess' in msg: logPrint('Error sending message to TVHeadend server. Invalid credentials supplied.') htsp = None else: logPrint('Successfully connected to TVHeadend HTSP interface.') except Exception, err: logPrint('Error connecting to TVHeadend server: %s' % str(err)) htsp = None
import sys from tvh.htsp import HTSPClient from tvh.api import HTSPApi from scripts import CONFIG try: limit = int(sys.argv[1]) except (IndexError, ValueError): limit = 500 try: filename = sys.argv[2] except (IndexError): filename = 'channels.txt' htsp = HTSPClient((CONFIG['hostname'], 9982)) msg = htsp.hello() htsp.authenticate(CONFIG['username'], CONFIG['password']) htspapi = HTSPApi(htsp=htsp) chans_kwargs = { 'start': 0, 'limit': 999999, 'sort': 'number', 'dir': 'ASC', 'filter': [ {'type': 'numeric', 'comparison': 'gt', 'value': 1*1000000, 'intsplit': 1000000, 'field': 'number'}, {'type': 'numeric', 'comparison': 'lt', 'value': limit*1000000, 'intsplit': 1000000, 'field': 'number'} ], 'all': 1 }
CONFIG = json.load(config_file) HOSTNAME = CONFIG['hostname'] #optional: try to read user and password try: USER = CONFIG['username'] PASSWORD = CONFIG['password'] except: pass except: #error, use default settings print( 'ERROR: config.json does not exist or is wrong. Use localhost and no auth' ) HOSTNAME = 'localhost' #set up connector HTSP = HTSPClient((HOSTNAME, 9982)) msg = HTSP.hello() #try to authenticate try: HTSP.authenticate(USER, PASSWORD) print('Authentification successful') except: print('Authentification skipped or failed - go on without auth') #update all recordings without really changing anything upd_all() #debug: print list of recordings #print(get_autorecs())