def INDEX(provider): #Create a list of top level folders as scraped from TV3's website doc = tools.gethtmlpage("%s/tabid/56/default.aspx" % (base_url(provider))) #Get our HTML page with a list of video categories if doc: a_tag = SoupStrainer('a') html_atag = BeautifulSoup(doc, parseOnlyThese = a_tag) links = html_atag.findAll(attrs={"rel": "nofollow", "href": re.compile(tv3_urls["CAT_RE"])}) #, "title": True if len(links) > 0: count = 0 for link in links: info = tools.defaultinfo(1) info["Title"] = link.string caturl = link['href'] catid = re.search('%s([0-9]+)' % (tv3_urls["CAT_RE"]), caturl).group(1) if info["Title"] == "Title (A - Z)": cat = "atoz" elif info["Title"] == "TV3 Shows": cat = "tv3" #elif info["Title"] == "C4TV Shows": elif info["Title"] == "FOUR Shows": cat = "c4tv" else: cat = "tv" if catid: info["Count"] = count count += 1 info["FileName"] = "%s?ch=TV3&cat=%s&catid=%s" % (sys.argv[0], cat, catid) tools.addlistitem(int(sys.argv[1]), info, tv3_urls["Fanart"], 1) else: sys.stderr.write("Couldn't find any categories") else: sys.stderr.write("Couldn't get index webpage")
def SHOW_SHOW(catid, title, provider): #Show video items from a TV Show style TV3 webpage baseurl = "" if catid[:4] <> "http": baseurl = tv3_urls["TV3"] geturl = "%s%s" % (baseurl, catid) doc = tools.gethtmlpage(geturl) if doc: div_tag=SoupStrainer('div') html_divtag = BeautifulSoup(doc, parseOnlyThese = div_tag) tables = html_divtag.find(attrs={"xmlns:msxsl": "urn:schemas-microsoft-com:xslt"}) if tables: programs = tables.findAll('table') if len(programs) > 0: count = 0 for soup in programs: add_item_show(soup, provider, count, title) count += 1 else: programs = tables.findAll('tr') if len(programs) > 0: count = -1 for soup in programs: count += 1 if count > 0: add_item_table(soup, provider, count, title) else: sys.stderr.write("Couldn't find any videos in list") else: sys.stderr.write("Couldn't find video list") else: sys.stderr.write("Couldn't get index webpage")
def INDEX_SHOWS(provider): #Create a second level list of TV Shows from a TV3 webpage #doc = tools.gethtmlpage("%s/Shows/tabid/64/Default.aspx" % ("http://www.tv3.co.nz")) #Get our HTML page with a list of video categories doc = tools.gethtmlpage("%s/Shows.aspx" % ("http://www.tv3.co.nz")) #Get our HTML page with a list of video categories if doc: html_divtag = BeautifulSoup(doc) linksdiv = html_divtag.find('div', attrs = {"id": "pw_8171"}) if linksdiv: links = linksdiv.findAll('a') if len(links) > 0: count = 0 for link in links: info = tools.defaultinfo(1) info["Title"] = link.string.strip() catid = link['href'] if info["Title"] == "60 Minutes": #The URL on the next line has more videos info["FileName"] = "%s?ch=TV3&cat=%s&title=%s&catid=%s" % (sys.argv[0], "shows", urllib.quote(info["Title"]), urllib.quote(catid)) #"http://ondemand.tv3.co.nz/Default.aspx?TabId=80&cat=22" else: info["FileName"] = "%s?ch=TV3&cat=%s&title=%s&catid=%s" % (sys.argv[0], "shows", urllib.quote(info["Title"]), urllib.quote(catid)) info["Count"] = count count += 1 tools.addlistitem(int(sys.argv[1]), info, tv3_urls["Fanart"], 1) else: sys.stderr.write("Couldn't find any videos in list") else: sys.stderr.write("Couldn't find video list") else: sys.stderr.write("Couldn't get index webpage")
def getEpisodes(id, url): link = tools.gethtmlpage(url, "ps3") if link: node = tools.getxmldocument(link) if node: for ep in node.getElementsByTagName('Episode'): addEpisode(ep) for ep in node.getElementsByTagName('Extra'): addEpisode(ep)
def PROGRAMMES(type, urlext): if type == "channel": folder = 1 url = ziln_urls["ZILN"] elif type == "video": folder = 0 #url = "%s/channel/%s" % (ziln_urls["ZILN"], urlext) url = "%s/assets/php/slider.php?channel=%s" % (ziln_urls["ZILN"], urlext) elif type == "search": folder = 0 url = "%s/search?search_keyword=%s" % (ziln_urls["ZILN"], urlext.replace(" ", "+")) doc = tools.gethtmlpage(url) if doc: if type == "channel" or type == "search": div_tag = SoupStrainer('div') html_divtag = BeautifulSoup(doc, parseOnlyThese = div_tag) programmes = html_divtag.findAll(attrs={'class' : 'programmes'}) elif type == "video": div_tag = SoupStrainer('body') html_divtag = BeautifulSoup(doc, parseOnlyThese = div_tag) programmes = html_divtag.findAll(attrs={'class' : 'slider slider-small'}) if type == "search": type = "video" if len(programmes) > 0: for programme in programmes: list = programme.find('ul') if list: listitems = list.findAll('li') if len(listitems) > 0: count = 0 for listitem in listitems: link = listitem.find('a', attrs={'href' : re.compile("^/%s/" % type)}) if link.img: if re.search("assets/images/%ss/" % type, link.img["src"]): info = tools.defaultinfo(1) #info["Title"] = link.img["alt"] if listitem.p.string: info["Title"] = listitem.p.string.strip() else: info["Title"] = link.img["alt"] info["Thumb"] = "%s/%s" % (ziln_urls["ZILN"], link.img["src"]) info["Count"] = count count += 1 #channelurl = re.search("/%s/(.*)" % type, link["href"]).group(1) channelurl = re.search("assets/images/%ss/([0-9]*?)-mini.jpg" % type, link.img["src"]).group(1) #infourl = "&info=%s" % urllib.quote(str(info)) info["FileName"] = "%s?ch=Ziln&%s=%s" % (sys.argv[0], type, urllib.quote(channelurl)) tools.addlistitem(int(sys.argv[1]), info, ziln_urls["Fanart"], folder) else: sys.stderr.write("Search returned no results") else: sys.stderr.write("Couldn't find any programs") else: sys.stderr.write("Couldn't get page")
def SHOW_EPISODES(id): getEpisodes(id, "%s/content/%s/ps3_xml_skin.xml" % (BASE_URL, id)) link = tools.gethtmlpage("%s/content/%s_extras_group/ps3_xml_skin.xml" % (BASE_URL, id[:-15]), "ps3") if link: node = tools.getxmldocument(link) if node: info = tools.defaultinfo(1) info["FileName"] = "%s?ch=TVNZ&type=shows&id=%s_extras_group" % (sys.argv[0], id[:-15]) info["Title"] = "Extras" tools.addlistitem(int(sys.argv[1]), info, FANART_URL, 1) return
def RESOLVE(index): #, info doc = tools.gethtmlpage("%s/playlist/null/%s" % (ziln_urls["ZILN"], index)) if doc: soup = BeautifulStoneSoup(doc) #tools.message(soup.find('media:content')["url"]) #minidom.parseString(doc).documentElement.getElementsByTagName("media:content")[0].attributes["url"].value info = tools.defaultinfo(0) info["Title"] = soup.find('item').title.contents[0] info["Thumb"] = soup.find('jwplayer:image').contents[0] info["Plot"] = soup.find('description').contents[0] uri = "%s%s" % (ziln_urls["ZILN"], soup.find('media:content')["url"]) tools.addlistitem(int(sys.argv[1]), info, ziln_urls["Fanart"], 0, 1, uri)
def SHOW_DISTRIBUTORS(id): link = tools.gethtmlpage("%s/content/%s/ps3_xml_skin.xml" % (BASE_URL, id), "ps3") if link: node = tools.getxmldocument(link) if node: print node.toxml().encode('latin1') urls = list() for distributor in node.getElementsByTagName('Distributor'): url,liz = getShow(distributor) if not urls.count(url): xbmcplugin.addDirectoryItem( handle=int(sys.argv[1]), url=url, listitem=liz, isFolder=True ) urls.append(url)
def getAdvert(chapter): advert = chapter.getElementsByTagName('ref') if len(advert): # fetch the link - it'll return a .asf file link = tools.gethtmlpage(advert[0].attributes['src'].value, "ps3") if link: node = tools.getxmldocument(link) if node: # grab out the URL to the actual flash ad for flv in node.getElementsByTagName('FLV'): if flv.firstChild and len(flv.firstChild.wholeText): return(flv.firstChild.wholeText)
def RESOLVE(id, info): link = tools.gethtmlpage("%s/content/%s/ta_ent_smil_skin.smil?platform=PS3" % (BASE_URL, id), "ps3") if link: node = tools.getxmldocument(link) if node: urls=list() for chapter in node.getElementsByTagName('seq'): # grab out the advert link if addon.getSetting('TVNZ_showads') == 'true': ad = getAdvert(chapter) if len(ad) > 0: urls.append(ad) maxbitrate = 0 minbitrate = 9999999999 for video in chapter.getElementsByTagName('video'): bitrate = int(video.attributes["systemBitrate"].value) if bitrate > maxbitrate: maxbitrate = bitrate if bitrate < minbitrate: minbitrate = bitrate requiredbitrate = 700000 #Medium = 700000 if addon.getSetting('TVNZ_quality') == "High": #High = 1500000 requiredbitrate = maxbitrate elif addon.getSetting('TVNZ_quality') == "Low": #Low = 300000 requiredbitrate = minbitrate for video in chapter.getElementsByTagName('video'): bitrate = int(video.attributes["systemBitrate"].value) if bitrate == requiredbitrate: url = video.attributes["src"].value if url[:7] == 'http://': # easy case - we have an http URL urls.append(url) sys.stderr.write("HTTP URL: " + url) elif url[:5] == 'rtmp:': # rtmp case rtmp_url = "rtmpe://fms-streaming.tvnz.co.nz/tvnz.co.nz" playpath = " playpath=" + url[5:] flashversion = " flashVer=MAC%2010,0,32,18" swfverify = " swfurl=http://tvnz.co.nz/stylesheets/tvnz/entertainment/flash/ondemand/player.swf swfvfy=true" conn = " conn=S:-720" urls.append(rtmp_url + playpath + flashversion + swfverify + conn) sys.stderr.write("RTMP URL: " + rtmp_url + playpath + flashversion + swfverify + conn) if len(urls) == 0: sys.stderr.write("No playback URLs found!") return if len(urls) == 1: uri = urls[0] elif len(urls) > 1: uri = tools.constructStackURL(urls) tools.addlistitem(int(sys.argv[1]), info, FANART_URL, 0, 1, uri)
def SHOW_ATOZ(catid, provider): #Show video items from an AtoZ style TV3 webpage doc = tools.gethtmlpage("%s%s%s" % (base_url("tv3"), tv3_urls["CAT"], catid)) if doc: a_tag=SoupStrainer('div') html_atag = BeautifulSoup(doc, parseOnlyThese = a_tag) programs = html_atag.findAll(attrs={"class": "wideArticles"}) if len(programs) > 0: count = 0 for soup in programs: add_item_atoz(soup, provider, count) count += 1 else: sys.stderr.write("Couldn't find any videos") else: sys.stderr.write("Couldn't get videos webpage")
def SHOW_SEARCH(catid, searchterm): #Show video items from a normal TV3 webpage doc = tools.gethtmlpage("%s/search/tabid/%s/Default.aspx?amq=%s" % (base_url("tv3"), catid, searchterm.replace(" ", "+"))) if doc: a_tag=SoupStrainer('div') html_atag = BeautifulSoup(doc, parseOnlyThese = a_tag) programs = html_atag.findAll(attrs={"class": "results"}) if len(programs) > 0: count = 0 for soup in programs: provider = "tv3" add_item_search(soup, "tv3", count) count += 1 else: sys.stderr.write("Couldn't find any videos") else: sys.stderr.write("Couldn't get videos webpage")
def INDEX(): link = tools.gethtmlpage("%s/content/ps3_navigation/ps3_xml_skin.xml" % (BASE_URL), "ps3") if link: count = 0 node = tools.getxmldocument(link) if node: for stat in node.getElementsByTagName('MenuItem'): type = stat.attributes["type"].value if type in ('shows', 'alphabetical'): #, 'distributor' m = re.search('/([0-9]+)/',stat.attributes["href"].value) if m: info = tools.defaultinfo(1) info["Title"] = stat.attributes["title"].value info["Count"] = count count += 1 info["FileName"] = "%s?ch=TVNZ&type=%s&id=%s" % (sys.argv[0], type, m.group(1)) tools.addlistitem(int(sys.argv[1]), info, FANART_URL, 1)
def SHOW_LIST(id): link = tools.gethtmlpage("%s/content/%s/ps3_xml_skin.xml" % (BASE_URL, id), "ps3") node = tools.getxmldocument(link) if node: urls = list() count = 0 infoitems = {} for show in node.getElementsByTagName('Show'): se = re.search('/content/(.*)_(episodes|extras)_group/ps3_xml_skin.xml', show.attributes["href"].value) if se: if se.group(2) == "episodes": #videos = int(show.attributes["videos"].value) #channel = show.attributes["channel"].value info = tools.defaultinfo(1) info["FileName"] = "%s?ch=TVNZ&type=singleshow&id=%s_episodes_group" % (sys.argv[0], se.group(1)) info["Title"] = show.attributes["title"].value info["Count"] = count count += 1 infoitems[info["Title"]] = info tools.addlistitems(int(sys.argv[1]), infoitems, FANART_URL, 1)
def RESOLVE(id, info): #Scrape a page for a given OnDemand video and build an RTMP URL from the info in the page, then play the URL ids = id.split(",") if len(ids) == 4: pageUrl = "%s/%s/%s/%s/%s/%s/%s/%s/%s" % (base_url(info["Studio"]), ids[0], tv3_urls["VIDEO1"], ids[1], tv3_urls["VIDEO2"], ids[2], tv3_urls["VIDEO3"], ids[3], tv3_urls["VIDEO4"]) doc = tools.gethtmlpage(pageUrl) else: doc = tools.gethtmlpage("id") if doc: #videoid = re.search('var video ="/\*transfer\*([0-9]+)\*([0-9A-Z]+)";', doc) videoid = re.search('var video ="\*(.*?)\*([0-9]+)\*(.*?)";', doc) if videoid: #videoplayer = re.search('var fo = new FlashObject\("(http://static.mediaworks.co.nz/(.*?).swf)', doc) videoplayer = re.search('swfobject.embedSWF\("(http://static.mediaworks.co.nz/(.*?).swf)', doc) if videoplayer: auth = re.search('random_num = "([0-9]+)";', doc) realstudio = 'tv3' site = re.search("var pageloc='TV-(FOUR|TV3)-Video(Extras)?-OnDemand-", doc) if site: if site.group(1) <> 'TV3': realstudio = 'c4' playlist=list() #if addon.getSetting('TV3_showads') == 'true': #playlist.append(ad) fifteen = re.search('flashvars.fifteenHundred = "yes";', doc) seven = re.search('flashvars.sevenHundred = "yes";', doc) if fifteen and seven: LowQuality = "330K" MediumQuality = "700K" HighQuality = "1500K" elif fifteen: LowQuality = "128K" MediumQuality = "330K" HighQuality = "1500K" elif seven: LowQuality = "128K" MediumQuality = "330K" HighQuality = "700K" else: LowQuality = "128K" MediumQuality = "330K" HighQuality = "330K" #elif re.search('flashvars.highEnd = "true";', doc): quality = HighQuality quality2 = MediumQuality quality3 = LowQuality if addon.getSetting('TV3_quality') == "Low": quality = LowQuality quality3 = HighQuality elif addon.getSetting('TV3_quality') == "Medium": quality = MediumQuality quality2 = HighQuality geo = re.search('var geo= "(no|geo)";', doc) if (geo.group(1) == 'no'): url = '%s%s/%s/%s_%s.%s' % (http(realstudio), videoid.group(1), videoid.group(2), urllib.quote(videoid.group(3)), quality, "mp4") else: #swfverify = ' swfUrl=%s swfVfy=true' % (videoplayer.group(1)) #rtmpurl = '%s%s/%s/%s_%s' % (rtmp(info["Studio"]), videoid.group(1), videoid.group(2), urllib.quote(videoid.group(3)), quality) url = '%s%s/%s/%s_%s' % (rtmp(realstudio), videoid.group(1), videoid.group(2), urllib.quote(videoid.group(3)), quality) if auth: swfverify = ' swfUrl=%s?rnd=%s pageUrl=%s swfVfy=true' % (videoplayer.group(1), auth.group(1), pageUrl) else: swfverify = ' swfUrl=%s pageUrl=%s swfVfy=true' % (videoplayer.group(1), pageUrl) url += swfverify sys.stderr.write("URL: %s" % (url)) #sys.stderr.write("Flash Player: %s" % (videoplayer.group(1))) playlist.append(url) if len(playlist) > 1: uri = constructStackURL(playlist) elif len(playlist) == 1: uri = playlist[0] #liz = xbmcgui.ListItem(id, iconImage = info["Icon"], thumbnailImage = info["Thumb"]) #liz.setInfo( type = "Video", infoLabels = info) #liz.setProperty("IsPlayable", "true") #liz.setPath(uri) #xbmcplugin.setResolvedUrl(handle = int(sys.argv[1]), succeeded = True, listitem = liz) info["FileName"] = url tools.addlistitem(int(sys.argv[1]), info, tv3_urls["Fanart"], 0, 1, uri) else: sys.stderr.write("Couldn't get video player URL") else: sys.stderr.write("Couldn't get video RTMP URL") else: sys.stderr.write("Couldn't get video webpage")