import urllib,urllib2,string,re,sys,socket,os import xbmcplugin,xbmcgui import xml.dom.minidom # PLEASE EDIT settings.xml TO CHANGE ANY OTHER SETTINGS # def INDEX(): res=[] #WebSock = urllib.urlopen(webaddress + '/sage/Recordings') # Opens a 'Socket' to URL WebSock = urllib.urlopen(webaddress + '/sage/Search?SearchString=&searchType=TVFiles&search_fields=title&filename=&TimeRange=0&Categories=**Any**&Channels=**Any**&watched=any&dontlike=any&favorite=any&firstruns=any&hdtv=any&archived=any&manrec=any&autodelete=any&partials=none&sort1=airdate_asc&sort2=none&grouping=None&pagelen=inf') link = WebSock.read() # Reads Contents of URL and saves to Variable WebSock.close() # Closes connection to url match = re.compile('epgcell.*?MediaFileId=(\d+)">', re.DOTALL).findall(link) for url in match: url_txt= url addDir(url_txt,0) res=[] #WebSock = urllib.urlopen(webaddress + '/sage/Recordings') # Opens a 'Socket' to URL WebSock = urllib.urlopen(webaddress + '/sage/Home') link = WebSock.read() # Reads Contents of URL and saves to Variable WebSock.close() # Closes connection to url match = re.compile('epgcell.*?MediaFileId=(\d+)">', re.DOTALL).findall(link) for url in match: url_txt= url addDir(url_txt,1) def get_params(): param=[] paramstring=sys.argv[2] if len(paramstring)>=2: params=sys.argv[2] cleanedparams=params.replace('?','') if (params[len(params)-1]=='/'): params=params[0:len(params)-2] pairsofparams=cleanedparams.split('&') param={} for i in range(len(pairsofparams)): splitparams={} splitparams=pairsofparams[i].split('=') if (len(splitparams))==2: param[splitparams[0]]=splitparams[1] return param def addLink(name,url,iconimage): ok=True liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage) liz.setInfo( type="Video", infoLabels={ "Title": name } ) ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz) return ok def addDir(url,current_rec): u = webaddress + '/sage/DetailedInfo?MediaFileId=' + url mode = 2 WebSock = urllib.urlopen(u) # Opens a 'Socket' to URL link = WebSock.read() # Reads Contents of URL and saves to Variable WebSock.close() # Closes connection to url filematch = re.compile('Files:.*?Segment=0">(.*?)', re.DOTALL).findall(link)[0] duration = re.compile('Duration: (.*?)

', re.DOTALL).findall(link)[0] channel = re.compile('Channel:.*?-(.*?)

', re.DOTALL).findall(link)[0] name = re.compile('Detailed Information for (.*?)', re.DOTALL).findall(link)[0] try: namesub = ' - ' + re.compile('

Episode: (.*?)

', re.DOTALL).findall(link)[0] except: namesub = ' ' name = name + namesub try: description = re.compile('Description:(.*?)

', re.DOTALL).findall(link)[0] except: description = '' try: icon = 'http://'+ipaddress+':'+port+'/thumbs/'+re.compile('FavoriteId=(\d+)', re.DOTALL).findall(link)[0]+'.jpg' except: icon = webaddress + '/sage/sagelogo.gif' iconimage = icon if current_rec == 1: filematch = 'http://'+ipaddress+':'+port+'/sagepublic/MediaFile?MediaFileId='+url+'&Segment=0' else: if RecordingPath == [u'']: filematch = 'http://'+ipaddress+':'+port+'/sagepublic/MediaFile?MediaFileId='+url+'&Segment=0' else: ct = 0 for i in RecordingPath: filematch = filematch.replace(i,XBMCPath[ct]) ct = ct + 1 u = webaddress + '/sage/EditShowInfo?MediaFileId=' + url mode = 2 WebSock = urllib.urlopen(u) # Opens a 'Socket' to URL link = WebSock.read() # Reads Contents of URL and saves to Variable WebSock.close() # Closes connection to url try: dates = re.compile('air_start_yr" value="(\d+).*?start_mth.*?"(\d+)" selected.*?air_start_dd" value="(\d+).*?air_start_hh" value="(\d+).*?air_start_mm" value="(\d+)', re.DOTALL).findall(link)[0] year = (int(dates[0]) - 2000) * 372 * 24 + int(dates[1]) * 31 * 24 + int(dates[2]) * 24 + int(dates[3]) date = dates[0] +'-'+ dates[1] +'-'+ dates[2] ok=True liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage) liz.setInfo( type="video", infoLabels={ "Title": name, "Plot": description, "Rating": 4.5, "Size": year, "Genre": 'genre', "Duration": duration, "Date": date, "Writer": 'writer', "Tagline": 'tagline', "Plotoutline": description, "Studio": channel, "Year": int(dates[0])}) ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=filematch,listitem=liz,isFolder=False) except: ok=True return ok def Setting(tagname, attribname): XMLFile = open(dirHome + 'settings.xml', "r") XMLData = XMLFile.read() dom = xml.dom.minidom.parseString(XMLData) XMLFile.close() Item = dom.getElementsByTagName(tagname)[0] return Item.getAttribute(attribname) def update(tagname, attribname, newvalue): try: XMLFile = open(dirHome + 'settings.xml', "r") XMLData = XMLFile.read() dom = xml.dom.minidom.parseString(XMLData) XMLFile.close() Item = dom.getElementsByTagName(tagname)[0] Item.setAttribute(attribname, newvalue) xmlstring = dom.toxml() f = file(dirHome + 'settings.xml', 'wb') try: f.write(xmlstring) finally: f.close() except: dialog = xbmcgui.Dialog() dialog.ok("SageTV", "Cannot write to " + dirHome + "settings.xml") return True url=None name=None dirHome = os.getcwd() dirHome = dirHome.replace(";","") dirHome = dirHome +'\\' ipaddress = Setting("Connection", "Ipaddress") port = Setting("Connection", "Port") userid = Setting("Connection", "UserId") password = Setting("Connection", "Password") s = Setting("System", "RecordingPath") RecordingPath = s.split(',') s = Setting("System", "XBMCPath") XBMCPath = s.split(',') if ipaddress == "0.0.0.0": firstlaunch = True dialog = xbmcgui.Dialog() dialog.ok("SageTV", "Please enter the IP Adress of the SageTV webserver.") keyboard = xbmc.Keyboard(ipaddress) keyboard.doModal() if (keyboard.isConfirmed()): ipaddress = keyboard.getText() s = Setting("Connection", "Ipaddress") ok = update("Connection", "Ipaddress", ipaddress) dialog.ok("SageTV", "Please enter the port used on the SageTV webserver.") keyboard = xbmc.Keyboard(port) keyboard.doModal() if (keyboard.isConfirmed()): port = keyboard.getText() s = Setting("Connection", "Port") ok = update("Connection", "Port",port) dialog.ok("SageTV", "Please enter the username for the SageTV webserver.") keyboard = xbmc.Keyboard(userid) keyboard.doModal() if (keyboard.isConfirmed()): userid = keyboard.getText() s = Setting("Connection", "UserId") ok = update("Connection", "UserId",userid) dialog.ok("SageTV", "Please enter the password for the SageTV webserver.") keyboard = xbmc.Keyboard(password) keyboard.doModal() if (keyboard.isConfirmed()): password = keyboard.getText() s = Setting("Connection", "Password") ok = update("Connection", "Password",password) else: firstlaunch = False webaddress = "http://" + userid + ":" + password + "@" + ipaddress + ":" + port INDEX() xbmcplugin.endOfDirectory(int(sys.argv[1]))