def TopItems(self): """ Gets the top 50 items """ #check for cookie: logFile.info("Checking for NOS cookies.") if uriHandler.CookieCheck('UGSES') and uriHandler.CookieCheck('CheckUGCookie'):# and uriHandler.CookieCheck('quuid'): logFile.info("Cookies found. Continuing") else: logFile.info("No cookies found. Opening main site") temp = uriHandler.Open(self.baseUrl) items = [] data = uriHandler.Open("http://www.uitzendinggemist.nl/index.php/top50") results = common.DoRegexFindAll('<td style=[^>]+><a href="/index.php/aflevering(\?aflID=\d+&md5=[^"]+)">([^<]+)</a></td>\W+<td align="right">([^<]+)</td>', data) logFile.debug("Adding %s top50 items", len(results)) for result in results: tmp = common.clistItem(result[1], common.StripAmp(result[0])) tmp.icon = self.icon tmp.date = result[2] tmp.type = 'video' items.append(tmp) return items
def CreateEpisodeItem(self, resultSet): """ Accepts an arraylist of results. It returns an item. """ #logFile.info('starting CreateEpisodeItem for %s', self.channelName) #<div class="enddep"><a\W+href="([^"]+)"[^>]+>([^<]+)</a></div> # 0 1 item = common.clistItem(resultSet[1], common.StripAmp(urlparse.urljoin(self.baseUrl, resultSet[0]))) item.description = "%s%s" % (self.categoryName, item.name) item.icon = self.icon logFile.debug("%s (%s)", item.name, item.url) return item
def CreateEpisodeItem(self, resultSet): """ Accepts an arraylist of results. It returns an item. """ #logFile.info('starting CreateEpisodeItem for %s', self.channelName) #<a class='nArrow' href='([^']+)' title='[^']*'>([^<]+)</a> # 0 1 item = common.clistItem( resultSet[1], common.StripAmp("%s%s" % (self.baseUrl, resultSet[0]))) item.icon = self.icon logFile.debug("%s (%s)", item.name, item.url) return item
def CreateFolderItem(self, resultSet): # <div class="enddep"><a[^>]+href="([^"]+)"[^>]*>([^<]+)</a>\W*</div> # 0 1 # <td class="image"><a[^>]+><img[^>]+src="([^"]+)"[^>]+></a></td>\W+<td[^>]+><div[^>]+><div class="enddep"><a[^>]+href="([^"]+)"[^>]*>([^<]+)</a>\W*</div> # # 0 1 2 item = common.clistItem(resultSet[1], common.StripAmp(urlparse.urljoin(self.baseUrl, resultSet[0]))) item.description = "%s%s" % (self.categoryName, item.name) item.thumb = self.noImage item.type = "folder" item.complete = True item.icon = self.folderIcon return item
def SearchSite(self): """ accepts an url and returns an list with items of type CListItem Items have a name and url. """ items = [] #check for cookie: logFile.info("Checking for NOS cookies.") if uriHandler.CookieCheck('UGSES') and uriHandler.CookieCheck('CheckUGCookie'):# and uriHandler.CookieCheck('quuid'): logFile.info("Cookies found. Continuing") else: logFile.info("No cookies found. Opening main site") temp = uriHandler.Open(self.baseUrl) keyboard = xbmc.Keyboard('') keyboard.doModal() if (keyboard.isConfirmed()): needle = keyboard.getText() if len(needle)<4: dialog = xbmcgui.Dialog() dialog.ok("Uitzendinggemist","Geen geldig zoekopdracht. Een zoekopdracht\nheeft minimaal 4 characters.") return #get only first one logFile.info("Searching NOS for needle: "+needle) data = uriHandler.Open("http://www.uitzendinggemist.nl/index.php/search",params="searchitem=&qs_uitzending="+needle+"&titel=&dag=&net_zender=&omroep=&genre=") #resultSet = common.DoRegexFindAll('<a class="title" href="/index.php/search\?([^"]+)&sq=[^<]+">([^<]+)(<span[^>]+>)*([^<]+)(</span>)*</a></td>', data) resultSet = common.DoRegexFindAll('<a class="title" href="/index.php/search\?([^"]+)&sq=[^<]+">([^<]*)(<span[^>]+>)*([^<]*)(</span>)*([^<]*)</a></td>', data) for item in resultSet: logFile.debug(item) name = "" for part in item[1:]: if not part.find(">") > 0: name = "%s%s" % (name, part) tmp = common.clistItem(name, self.baseUrl + "/index.php/serie?" + common.StripAmp(item[0])) tmp.icon = self.folderIcon tmp.thumb = self.noImage tmp.description = name items.append(tmp) #because lists are downloaded according to date (else some programs will be missing), a sort on name is performed. items.sort(lambda x, y: cmp(x.name,y.name)) else: logFile.info('user canceled search') return items
def CreateEpisodeItem(self, resultSet): """ Accepts an arraylist of results. It returns an item. """ logFile.debug('starting CreateVideoItem for %s', self.channelName) #http://player.omroep.nl/?aflID=6954225&md5=e82938c934f962003ec7c9181ca0439e item = common.clistItem(resultSet[2], common.StripAmp(resultSet[1])) item.date = resultSet[0] if item.date == "": item.date = "Geen Datum" item.type = 'video' item.icon = self.icon return item
def CreateVideoItem(self, resultSet): """ Accepts an arraylist of results. It returns an item. """ logFile.debug('starting FormatVideoItem for %s', self.channelName) #(<td class="image"><img src="([^"]+)" [^>]+>\W*</td>\W*<td [^>]+>)*<div class="video"><a [^>]+ href="([^"]+)" [^>]+>([^<]+)</a> # 0 1 2 3 name = common.ConvertHTMLEntities(resultSet[3]) item = common.clistItem(name, common.StripAmp(urlparse.urljoin(self.baseUrl, resultSet[2]))) item.description = "%s%s" % (self.categoryName, item.name) item.icon = self.icon if resultSet[1] != "": item.thumbUrl = common.StripAmp(urlparse.urljoin(self.baseUrl, resultSet[1])) logFile.debug("Setting thumburl=%s", item.thumbUrl) item.thumb = self.noImage item.type = 'video' item.complete = False return item
def NewItems(self): """ Filters the correct data from www.uitzendinggemist.nl page and calls """ items = [] data = uriHandler.Open("http://www.uitzendinggemist.nl/") selectedData = common.DoRegexFindAll("Meer nieuwe programma([\w\W]+)<!--// options -->", data) if len(selectedData) > 0: data = selectedData[0] results = common.DoRegexFindAll("<a href=\"/index.php/aflevering(\?aflID=\d+&md5=[0-9a-f]+)\"[^>]+>([^<]+)</a>", data) for result in results: tmp = common.clistItem(result[1], common.StripAmp(result[0])) tmp.icon = self.icon tmp.type = 'video' items.append(tmp) return items
def TipItems(self): """ Filters the tips from www.uitzendinggemist.nl """ items = [] data = uriHandler.Open("http://www.uitzendinggemist.nl/") selectedData = common.DoRegexFindAll("<!--<h1>Eerdere tips van Uitzendinggemist</h1>([\W\w]+)<!--// eerdere tips van uitzendinggemist -->", data) if len(selectedData) > 0: data = selectedData[0] results = common.DoRegexFindAll("<a href=\"http://player.omroep.nl/(\?aflID=\d+&md5=[0-9a-f]+)\" [^>]+>([^<]+)</a>", data) for result in results: tmp = common.clistItem(result[1], common.StripAmp(result[0])) tmp.icon = self.icon tmp.type = 'video' items.append(tmp) return items
def PopularItems(self): """ Filters the NewItems from www.uitzendinggemist.nl """ items = [] data = uriHandler.Open("http://www.uitzendinggemist.nl/") selectedData = common.DoRegexFindAll("<thead id=\"tooltip_populair\"([\w\W]+)<script type=\"text/javascript\">", data) if len(selectedData) > 0: data = selectedData[0] results = common.DoRegexFindAll("<td><a href=\"/index.php/aflevering(\?aflID=\d+&md5=[0-9a-f]+)\">([^<]+)</a></td>\W+<td [^>]+>([^<]+)</td>", data) for result in results: tmp = common.clistItem(result[1], common.StripAmp(result[0])) tmp.date = result[2] tmp.icon = self.icon tmp.type = 'video' items.append(tmp) return items
def UpdateVideoItem(self, item): """ Accepts an item. It returns an updated item. Usually retrieves the MediaURL and the Thumb! It should return a completed item. """ logFile.info('starting UpdateVideoItem for %s (%s)', item.name, self.channelName) # download the thumb item.thumb = self.CacheThumb(item.thumbUrl) # load the url and get the info for the media urls: data = uriHandler.Open(item.url, pb=False) acts = common.DoRegexFindAll('<media:content url="([^=]+=\d+&hiLoPref=hi)"[^>]+>', data) #retrieve the first real url rtmpUrls = [] if len(acts)>0: rtmpData = uriHandler.Open(common.StripAmp(acts[0]), pb=False) #<src>rtmp://cp40493.edgefcs.net/ondemand/comedystor/_!/com/sp/acts/Season01/E_0102/compressed/flv/0102_3_DI_640x480_500kbps.flv</src> #rtmp://cp40493.edgefcs.net/ondemand?slist=comedystor/_!/com/sp/acts/Season01/E_0106/compressed/flv/0106_4_DI_640x480_700kbps parts = common.DoRegexFindAll('<src>([^<]+ondemand)/([^<]+flv/\d+_)\d+(_[^<]+)[.]flv</src>', rtmpData) rtmpUrlParts = [] for part in parts: rtmpUrlParts = part actNr = 1 for act in acts: rtmpUrl = "%s?slist=%s%s%s" % (rtmpUrlParts[0], rtmpUrlParts[1], actNr ,rtmpUrlParts[2]) rtmpUrls.append(rtmpUrl) actNr = actNr + 1 logFile.debug('Appending: %s', rtmpUrl) item.mediaurl = rtmpUrls else: logFile.critical("Error retrieving rtmp stream from %s", item.url) if item.mediaurl != "": logFile.debug("Media url was found: %s", item.mediaurl) item.complete = True else: logFile.debug("Media url was not found.") return item
def CreatePageItem(self, resultSet): """ Accepts an resultset """ logFile.debug("Starting CreatePageItem") total = '' for set in resultSet: total = "%s%s" % (total, set) total = common.StripAmp(total) if not self.pageNavigationRegexIndex == '': item = common.clistItem(resultSet[self.pageNavigationRegexIndex], urlparse.urljoin(self.baseUrl, total)) else: item = common.clistItem("0") item.type = "page" logFile.debug("Created '%s' for url %s", item.name, item.url) return item
def CreateVideoItem(self, resultSet): """ Accepts an arraylist of results. It returns an item. """ logFile.debug('starting FormatVideoItem for %s', self.channelName) #<img id='([^']+)' src='([^']+)' class='vThumb' alt='[^']*'/></a></div></div><div class='sCenter vTitle'><span class='title'><a[^>]+title='([^']+)'> # 0 1 2 name = common.ConvertHTMLEntities(resultSet[2]) item = common.clistItem( name, common.StripAmp("%s%s" % (self.baseUrl, resultSet[0]))) item.description = "%s\n%s" % (self.categoryName, resultSet[2]) item.icon = self.icon item.thumb = self.noImage item.thumbUrl = resultSet[1] # now create the video url using the # http://myvideo-550.vo.llnwd.net/nl/d3/movie7/4a/thumbs/3384551_1.jpg # http://myvideo-550.vo.llnwd.net/nl/d3/movie7/4a/3384551.flv # het script: http://myvideo-906.vo.llnwd.net/nl/d2/movie4/d93548906.flv # de pagina: http://myvideo-906.vo.llnwd.net/nl/d2/movie4/d9/3548906.flv urlResult = common.DoRegexFindAll( "(http://myvideo[^_]+)/thumbs(/\d+)_\d+.jpg", item.thumbUrl) item.mediaurl = "" if len(urlResult) > 0: for part in urlResult[0]: item.mediaurl = "%s%s" % (item.mediaurl, part) item.mediaurl = "%s.flv" % (item.mediaurl) logFile.debug("Updated mediaurl for %s to: %s", item.name, item.mediaurl) item.type = 'video' item.complete = False return item
def ProcessFolderList(self, url): logFile.info('starting ParseFolder for ' + url) items = [] # get the data for most current episode try: # load first page as "pageBase" data = uriHandler.Open(url, pb=True) # see if it is an extended page or not: extended = common.DoRegexFindAll('<u>terug naar programma</u>', data) if extended != []: items = self.ProcessExtendedPages(data) else: items = self.ProcessNormalPage(data) # determine if an extended page item should be added pageExtUrl = common.DoRegexFindAll( '<a href="(/index.php/serie2\?serID=\d+&md5=[0-9a-f]+)"', data) if pageExtUrl != []: # add an folder item for it to the list folderItem = common.clistItem( "Oudere afleveringen", self.baseUrl + common.StripAmp(pageExtUrl[0]), type='folder') folderItem.icon = self.folderIcon folderItem.thumb = self.noImage folderItem.description = "Oudere, gearchiveerde items van '%s'." % items[ 0].name #items.append(folderItem) items.insert(0, folderItem) return items except: logFile.critical("Error Parsing with new methode", exc_info=True) return items
def ParseMainList(self): """ accepts an url and returns an list with items of type CListItem Items have a name and url. """ if len(self.mainListItems) > 1: return self.mainListItems items = [] logFile.info('Mainlist for %s parsing %s', self.channelName, self.mainListUri) #check for cookie: logFile.info("Checking for %s cookies.", self.channelName) if uriHandler.CookieCheck('UGSES') and uriHandler.CookieCheck( 'CheckUGCookie'): # and uriHandler.CookieCheck('UGWMC'): logFile.info("Cookies found. Continuing") else: logFile.info("No cookies found. Opening main site") if not uriHandler.CookieCheck( 'UGSES') and not uriHandler.CookieCheck('CheckUGCookie'): logFile.debug("Opening %s for cookie UGSES", self.baseUrl) temp = uriHandler.Open(self.baseUrl) #if not uriHandler.CookieCheck('UGWMC'): # logFile.debug("Opening %s for cookie UGWMC", self.baseUrl2) # temp = uriHandler.Open(self.baseUrl2) #now start opening pb = xbmcgui.DialogProgress() pb.create("Opening %s" % (self.channelName, ), "Opening page 1 of ??") try: data = uriHandler.Open(self.mainListUri, pb=False) # find number of subpages and load them numPages = common.DoRegexFindAll("&pgNum=(\d+)", data) numPages.sort() if len(numPages) > 0: numPages = int(numPages[-1]) if numPages > self.maxNumberOfFrontPages: numPages = self.maxNumberOfFrontPages else: numPages = 1 logFile.debug("Loading %s pages from the frontpage of uzg", numPages) # now loop through the pages for page in range(1, numPages + 1): if page > 1: pb.update(int((page - 1) * 100 / numPages), "Opening page %s of %s" % (page, numPages)) data = uriHandler.Open("%s&pgNum=%s" % (self.mainListUri, page), pb=False) # programma's resultItems = common.DoRegexFindAll(self.episodeItemRegex, data) for item in resultItems: #tmp = common.clistItem(item[1], self.baseUrl + '/index.php/serie?' + common.StripAmp(item[0])) tmp = common.clistItem( item[1], self.baseUrl + common.StripAmp(item[0])) if len(item) > 2: tmp.date = item[2] tmp.icon = self.icon items.append(tmp) if pb.iscanceled(): break #because lists are downloaded according to date (else some programs will be missing), a sort on name is performed. pb.update(int((page) * 100 / numPages), "Sorting Items") if self.sortAlphabetically: items.sort(lambda x, y: cmp(x.name, y.name)) pb.close() except: logFile.error("Error parsing mainlist", exc_info=True) pb.close() self.mainListItems = items return items