import xbmc, xbmcgui import os import sys import urllib import time import re import socket import string import traceback ROOT_DIR = os.getcwd()[:-1]+'\\' dialogProgress = xbmcgui.DialogProgress() class TVLink: def __init__(self): try: self.Cats = ["Shows", "Cartoons", "Documentaries", "Anime", "Movies", "Music Videos"] self.Links = ["http://www.tv-links.co.uk/index.do/1", "http://www.tv-links.co.uk/index.do/2", "http://www.tv-links.co.uk/index.do/9", "http://www.tv-links.co.uk/index.do/3", "http://www.tv-links.co.uk/index.do/4", "http://www.tv-links.co.uk/index.do/5",] except Exception, e: traceback.print_exc(file=sys.stdout) dialog = xbmcgui.Dialog() dialog.ok("Error", "Error initializing script.\n\nReason:\n"+str(e)) def get_list(self, url): try: self.list = {} sock = urllib.urlopen(url) htmlSource = sock.read() sock.close() reCAT = re.compile('
(.+?)
\n\s+\n\s+\n\s+\n\s+', re.DOTALL) reLIST = re.compile('(.+?)', re.DOTALL) list = {} for i in reCAT.finditer(htmlSource): links = {} for x in reLIST.finditer(i.group(2)): links[x.group(2)] = 'http://www.tv-links.co.uk/listings/' + x.group(1) list[i.group(1)] = links return list except Exception, e: traceback.print_exc(file=sys.stdout) dialog = xbmcgui.Dialog() dialog.ok("Error", "Playlist could not be opened.\n\nReason:\n"+str(e)) def get_eps(self, url): try: self.list = {} self.morder = {} sock = urllib.urlopen(url) htmlSource = sock.read() sock.close() reEP = re.compile('

(.+?)

\n\s+(.+?)
', re.DOTALL) reSINGEP = re.compile('\n\s+\n\s+(.+?)\s\n\s+\n\s+(.+?).+?', re.DOTALL) reSINGEPNAME = re.compile('(.+?)', re.DOTALL) rePART = re.compile('^Part \d', re.DOTALL) last = ""; for i in reEP.finditer(htmlSource): links = {} a = 0 order = {} for x in reSINGEP.finditer(i.group(2)): for y in reSINGEPNAME.finditer(x.group(2)): name = y.group(2) if rePART.search(name): name = last+" "+name else: last = y.group(2) order[a] = x.group(1)+" "+name a = a+1 links[x.group(1)+" "+name] = 'http://www2.tv-links.co.uk'+y.group(1) self.list[i.group(1)] = links self.morder[i.group(1)] = order except Exception, e: traceback.print_exc(file=sys.stdout) dialog = xbmcgui.Dialog() dialog.ok("Error", "Unable to look up episodes.\n\nReason:\n"+str(e)) def addLink(self,name,url): xbmc.setDirectoryEntry(handle=self.handle,name=name,url=url,isDirectory=int(0)) def addDir(self,name,url,code,letter=" "): u="python://"+sys.argv[0]+"?code="+str(code)+"&url="+urllib.quote(url)+"&letter="+letter xbmc.setDirectoryEntry(handle=self.handle,name=name,url=u,isDirectory=int(-1)) def get_link(self, url): link = "" try: sock = urllib.urlopen(url) htmlSource = sock.read() sock.close() reDIVX = re.compile('http://www([0-9]?)\.tv-links\.co\.uk/video/(.+?)\.divx', re.DOTALL) reFLV = re.compile('videoFile: \'(.+?)\'', re.DOTALL) reSWF = re.compile('