import xbmc, xbmcgui
import os
import sys
import urllib
import time
import re
import socket
import string
ACTION_MOVE_LEFT = 1
ACTION_MOVE_RIGHT = 2
ACTION_MOVE_UP = 3
ACTION_MOVE_DOWN = 4
ACTION_PAGE_UP = 5
ACTION_PAGE_DOWN = 6
ACTION_SELECT_ITEM = 7
ACTION_HIGHLIGHT_ITEM = 8
ACTION_PARENT_DIR = 9
ACTION_PREVIOUS_MENU = 10
ACTION_SHOW_INFO = 11
ACTION_PAUSE = 12
ACTION_STOP = 13
ACTION_NEXT_ITEM = 14
ACTION_PREV_ITEM = 15
ACTION_MUSIC_PLAY = 79
ACTION_CONTEXT_MENU = 117
ROOT_DIR = os.getcwd()[:-1]+'\\'
IMAGE_DIR = ROOT_DIR+'images\\'
dialogProgress = xbmcgui.DialogProgress()
#############################################################################
# autoscaling values
#############################################################################
HDTV_1080i = 0 #(1920x1080, 16:9, pixels are 1:1)
HDTV_720p = 1 #(1280x720, 16:9, pixels are 1:1)
HDTV_480p_4x3 = 2 #(720x480, 4:3, pixels are 4320:4739)
HDTV_480p_16x9 = 3 #(720x480, 16:9, pixels are 5760:4739)
NTSC_4x3 = 4 #(720x480, 4:3, pixels are 4320:4739)
NTSC_16x9 = 5 #(720x480, 16:9, pixels are 5760:4739)
PAL_4x3 = 6 #(720x576, 4:3, pixels are 128:117)
PAL_16x9 = 7 #(720x576, 16:9, pixels are 512:351)
PAL60_4x3 = 8 #(720x480, 4:3, pixels are 4320:4739)
PAL60_16x9 = 9 #(720x480, 16:9, pixels are 5760:4739)
#############################################################################
class TVLink(xbmcgui.Window):
def __init__(self):
try:
self.setCoordinateResolution(PAL_4x3)
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",]
self.ctrlBackGround = xbmcgui.ControlImage(0, 0, 720,576, IMAGE_DIR + 'background.png')
self.ctrlLogo = xbmcgui.ControlImage(30, 5, 50, 100, IMAGE_DIR + 'logo.png')
self.addControl(self.ctrlBackGround)
self.addControl(self.ctrlLogo)
self.ctrlList = xbmcgui.ControlList(205, 130, 500, 400, font='font14',textColor='0xFFFFFFFF', buttonFocusTexture=IMAGE_DIR + 'focus.png', itemTextXOffset=-7, itemTextYOffset=-2, itemHeight=15)
self.addControl(self.ctrlList)
self.lblPage = xbmcgui.ControlLabel(100, 75, 455, 500, 'test', 'font14','0xFFFFFFFF')
self.addControl(self.lblPage)
self.ctrlList.reset()
self.makeButtons()
self.ctrlList.controlLeft(self.btnCategories[0])
self.prev = ""
self.prevs = ""
self.pages = ["", "", "", ""]
self.curcat = 0
self.pages[0] = self.Cats[0]
self.do_page()
self.get_list(self.Links[0])
for z in sorted(self.list):
self.page = 1
self.ctrlList.addItem(xbmcgui.ListItem(label=z))
self.setFocus(self.ctrlList)
#self.addControl(xbmcgui.ControlImage(90, 3, 60, 60,ROOT_DIR + 'default.tbn'))
except Exception, e:
dialog = xbmcgui.Dialog()
dialog.ok("Error", "Error initializing script.\n\nReason:\n"+str(e))
def do_page(self):
try:
if self.pages[0] != "":
self.lblPage.setLabel(self.pages[0])
if self.pages[1] != "":
self.lblPage.setLabel(self.pages[0]+" > "+self.pages[1])
if self.pages[2] != "":
self.lblPage.setLabel(self.pages[0]+" > "+self.pages[2])
if self.pages[3] != "":
self.lblPage.setLabel(self.pages[0]+" > "+self.pages[2]+" > "+self.pages[3])
except Exception, e:
dialog = xbmcgui.Dialog()
dialog.ok("Error", "Error printing selected path.\n\nReason:\n"+str(e))
def getCategory(self):
try:
if self.pages[2] != "":
name=self.pages[2]
if self.pages[3] != "":
name=self.pages[2]+", "+self.pages[3]
return name
except Exception, e:
dialog = xbmcgui.Dialog()
dialog.ok("Error", "Playlist could not be opened.\n\nReason:\n"+str(e))
return ""
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
self.list = list
except Exception, e:
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:
dialog = xbmcgui.Dialog()
dialog.ok("Error", "Unable to look up episodes.\n\nReason:\n"+str(e))
def get_link(self, url):
link = ""
try:
#dialog = xbmcgui.Dialog()
#dialog.ok("Error", url)
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('