def AddEpisodeToList(self, listItems, episode): self.log(u"", xbmc.LOGDEBUG) try: htmlparser = HTMLParser.HTMLParser() href = episode[u'href'] title = htmlparser.unescape( episode.find(u'span', u"thumbnail-title").contents[0] ) date = episode.find(u'span', u"thumbnail-date").contents[0] #description = ... thumbnail = episode.find(u'img', u'thumbnail')[u'src'] newLabel = title + u", " + date newListItem = xbmcgui.ListItem( label=newLabel ) newListItem.setThumbnailImage(thumbnail) if self.addon.getSetting( u'RTE_descriptions' ) == u'true': infoLabels = self.GetEpisodeInfo(self.GetEpisodeIdFromURL(href)) else: infoLabels = {u'Title': title, u'Plot': title} newListItem.setInfo(u'video', infoLabels) newListItem.setProperty(u"Video", u"true") #newListItem.setProperty('IsPlayable', 'true') self.log(u"label == " + newLabel, xbmc.LOGDEBUG) if u"episodes available" in date: url = self.GetURLStart() + u'&listavailable=1' + u'&page=' + mycgi.URLEscape(href) folder = True else: newListItem.setProperty("Video", "true") #newListItem.setProperty('IsPlayable', 'true') folder = False match = re.search( u"/player/[^/]+/show/([0-9]+)/", href ) if match is None: self.log(u"No show id found in page href: '%s'" % href, xbmc.LOGWARNING) return episodeId = match.group(1) url = self.GetURLStart() + u'&episodeId=' + mycgi.URLEscape(episodeId) if self.resumeEnabled: resumeKey = episodeId self.ResumeListItem(url, newLabel, newListItem, resumeKey) listItems.append( (url, newListItem, folder) ) except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) msg = u"episode:\n\n%s\n\n" % utils.drepr(episode) exception.addLogMessage(msg) # Error getting episode details exception.addLogMessage(self.language(30099)) exception.process(self.logLevel(xbmc.LOGWARNING))
def DoSearchQuery(self, query=None, queryUrl=None): if query is not None: queryUrl = urlRoot + self.GetSearchURL() + mycgi.URLEscape(query) self.log(u"queryUrl: %s" % queryUrl, xbmc.LOGDEBUG) try: html = None html = self.httpManager.GetWebPage(queryUrl, 1800) if html is None or html == '': # Data returned from web page: %s, is: '%s' logException = LoggingException( logMessage=self.language(30060) % (__SEARCH__ + mycgi.URLEscape(query), html)) # Error getting web page logException.process(self.language(30050), u'', severity=self.logLevel(xbmc.LOGWARNING)) return False self.ListSearchShows(html) return True except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) if html is not None: msg = "html:\n\n%s\n\n" % html exception.addLogMessage(msg) # Error performing query %s exception.addLogMessage(self.language(30052) % query) exception.process(severity=self.logLevel(xbmc.LOGERROR)) return False
def AddPageToListItems(self, category, label, order, page, listItems): """ {"count":50,"results":[ { "title":"The Function Room", "url":"/4od/the-function-room", "img":"http://cache.channel4.com/assets/programmes/images/the-function-room/7d5d701c-f7f8-4357-a128-67cac7896f95_200x113.jpg" },... """ try: jsonText = None pageInt = int(page) url = categoryUrl % (category, order, u'/page-%s' % page) jsonText = self.httpManager.GetWebPage(url, 963) jsonData = _json.loads(jsonText) results = jsonData[u'results'] for entry in results: id = entry[u'url'] pattern = u'/4od/(.+)' match = re.search(pattern, id, re.DOTALL | re.IGNORECASE) showId = match.group(1) thumbnail = entry[u'img'] progTitle = unicode(entry[u'title']) progTitle = progTitle.replace(u'&', u'&') progTitle = progTitle.replace(u'£', u'£') newListItem = xbmcgui.ListItem(progTitle) newListItem.setThumbnailImage(thumbnail) newListItem.setInfo(u'video', {u'Title': progTitle}) url = self.GetURLStart( ) + u'&category=' + category + u'&show=' + mycgi.URLEscape( showId) + u'&title=' + mycgi.URLEscape(progTitle) listItems.append((url, newListItem, True)) nextPageCount = jsonData[u'nextPageCount'] if nextPageCount == 0: return False return True except (Exception) as exception: exception = LoggingException.fromException(exception) if jsonText is not None: msg = u"url: %s\n\n%s\n\n" % (unicode(url), jsonText) exception.addLogMessage(msg) # Error getting programme list web page exception.addLogMessage(self.language(30805)) exception.process(u"", u"", severity=self.logLevel(xbmc.LOGERROR)) raise exception
def ShowLiveMenu(self): self.log(u"", xbmc.LOGDEBUG) listItems = [] try: html = None page = self.GetLivePageUrl() html = self.httpManager.GetWebPage(urlRoot + page, 60) soup = BeautifulSoup(html, selfClosingTags=['img']) schedule = soup.find('div', 'live-schedule-strap clearfix') liList = schedule.findAll('li') for li in liList: logoName = li.find('span', {'class': re.compile('live-logo')}) channel = logoName.text thumbnailPath = self.GetThumbnailPath( (channel.replace(u'RT\xc9 ', '')).replace(' ', '')) page = li.a['href'] infoList = li.findAll('span', "live-channel-info") programme = "" for info in infoList: text = info.text.replace(" ", "") if len(text) == 0: continue comma = "" if len(programme) == 0: programme = info.text else: programme = programme + ", " + info.text programme = programme.replace(''', "'") newListItem = xbmcgui.ListItem(label=programme) newListItem.setThumbnailImage(thumbnailPath) newListItem.setProperty("Video", "true") #newListItem.setProperty('IsPlayable', 'true') url = self.GetURLStart( ) + u'&live=1' + u'&page=' + mycgi.URLEscape(page) listItems.append((url, newListItem, False)) xbmcplugin.addDirectoryItems(handle=self.pluginHandle, items=listItems) xbmcplugin.endOfDirectory(handle=self.pluginHandle, succeeded=True) return True except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) if html is not None: msg = "html:\n\n%s\n\n" % html exception.addLogMessage(msg) # Error getting Live TV information exception.addLogMessage(self.language(30047)) exception.process(severity=self.logLevel(xbmc.LOGERROR)) return False
def AddAllLinks(self, listItems, html, listshows = False, autoThumbnails = False): htmlparser = HTMLParser.HTMLParser() try: for link in html.findAll(u'a'): page = link[u'href'] newLabel = htmlparser.unescape(link.contents[0]) thumbnailPath = self.GetThumbnailPath(newLabel.replace(u' ', u'')) newListItem = xbmcgui.ListItem( label=newLabel) newListItem.setThumbnailImage(thumbnailPath) url = self.GetURLStart() + u'&page=' + mycgi.URLEscape(page) # "Most Popular" does not need a submenu, go straight to episode listing if listshows or u"Popular" in newLabel: url = url + u'&listshows=1' self.log(u"url: %s" % url, xbmc.LOGDEBUG) listItems.append( (url,newListItem,True) ) return True except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) if html is not None: msg = "html:\n\n%s\n\n" % html exception.addLogMessage(msg) # Error adding links exception.addLogMessage(self.language(30047)) exception.process(severity = self.logLevel(xbmc.LOGERROR)) return False
def AddEpisodeItem(self, label, thumbnail, infoLabels, page, listItems): label = label.replace(u''', u"'") page = mycgi.URLUnescape(page) if u' ' in page: page = page.replace(u' ', u'%20') resumeKey = unicode(zlib.crc32(page)) url = self.GetURLStart( ) + u'&episodeId=' + resumeKey + u'&page=' + mycgi.URLEscape(page) contextMenuItems = [] newListItem = { 'label': label, 'episodeId': resumeKey, 'thumbnail': thumbnail, 'Video': True, 'contextMenuItems': contextMenuItems, 'videoInfo': infoLabels, 'url': url } # newListItem = self.ResumeWatchListItem(url, resumeKey, contextMenuItems, infoLabels, thumbnail) listItems.append((url, newListItem, False))
def AddExtraLinks(self, category, label, order, listItems): if order == u'/atoz': newOrder = "/latest" # Default order, latest newLabel = u' [' + u'Latest' + u' ' + label + u']' thumbnail = u'latest' else: newOrder = u'/atoz' # Alphanumerical newLabel = u' [' + 'A - Z' + u' ' + label + u']' thumbnail = u'title' thumbnailPath = self.GetThumbnailPath(thumbnail) newListItem = xbmcgui.ListItem(label=newLabel) newListItem.setThumbnailImage(thumbnailPath) url = self.GetURLStart() + u'&category=' + mycgi.URLEscape( category) + u'&title=' + mycgi.URLEscape( label) + u'&order=' + mycgi.URLEscape(newOrder) + u'&page=1' listItems.append((url, newListItem, True))
def AddEpisodeToSearchList(self, listItems, article): """ <article class="search-result clearfix"><a href="/player/ie/show/10098947/" class="thumbnail-programme-link"><span class="sprite thumbnail-icon-play">Watch Now</span><img class="thumbnail" alt="Watch Now" src="http://img.rasset.ie/0006d29f-261.jpg"></a> <h3 class="search-programme-title"><a href="/player/ie/show/10098947/">Nuacht and <span class="search-highlight">News</span> with Signing</a></h3> <p class="search-programme-episodes"><a href="/player/ie/show/10098947/">Sun 30 Dec 2012</a></p> <!-- p class="search-programme-date">30/12/2012</p --> <p class="search-programme-description">Nuacht and <span class="search-highlight">News</span> with Signing.</p> <span class="sprite logo-rte-one search-channel-icon">RTÉ 1</span> </article> """ episodeLink = article.find(u'a', u"thumbnail-programme-link") href = episodeLink[u'href'] title = self.GetTextFromElement( article.find(u'h3', u"search-programme-title").a) dateShown = article.findNextSibling( u'p', u"search-programme-episodes").a.text description = self.GetTextFromElement( article.findNextSibling(u'p', u"search-programme-description")) thumbnail = article.find('img', 'thumbnail')['src'] title = title + u' [' + dateShown + u']' infoLabels = { u'Title': title, u'Plot': description, u'PlotOutline': description, 'pubDate': dateShown } match = re.search(u"/player/[^/]+/show/([0-9]+)/", href) if match is None: self.log(u"No show id found in page href: '%s'" % href, logging.WARNING) return episodeId = match.group(1) url = self.GetURLStart() + u'&episodeId=' + mycgi.URLEscape(episodeId) contextMenuItems = [] newListItem = { 'label': title, 'episodeId': episodeId, 'thumbnail': thumbnail, "Video": True, 'contextMenuItems': contextMenuItems, 'videoInfo': infoLabels, 'url': url } #self.ResumeWatchListItem(url, episodeId, contextMenuItems, infoLabels, thumbnail) listItems.append((url, newListItem, True))
def ShowCategories(self): listItems = [] categoryId = u"Cursai Reatha" urlFragment = u'&category=' + mycgi.URLEscape(categoryId) self.AddMenuItem(listItems, u"News", u"Nuacht", urlFragment) """ GET /tg4-player/main_cats_ie.xml HTTP/1.1 <portfolio> <categories> <category id="drama">Drámaíocht</category> <category id="sport">Spórt</category> <category id="music">Ceol</category> <category id="cula4">Cúla4</category> <category id="faisneis">Faisnéis</category> <category id="siamsaiocht">siamsaíocht</category> <category id="live">Beo</category> <category id="search">Toradh</category> </categories> </portfolio> """ try: xml = None xml = self.httpManager.GetWebPage( mainCategories % self.languageCode, 20000) soup = BeautifulStoneSoup(xml) categories = soup.portfolio.findAll(u'category') for category in categories: if category[u'id'] == u'live' or category[ u'id'] == u'search' or category[u'id'] == u'news': continue listItems.append(self.CreateCategoryItem(category)) # Replace "Results" with "Search" #xbmcplugin.addDirectoryItems( handle=self.pluginHandle, items=listItems ) #xbmcplugin.endOfDirectory( handle=self.pluginHandle, succeeded=True ) #return True return listItems except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) if xml is not None: msg = u"xml:\n\n%s\n\n" % xml exception.addLogMessage(msg) # Cannot show root menu exception.addLogMessage("Cannot show root menu") exception.process(severity=self.logLevel(logging.ERROR)) return False
def AddPageLink(self, category, order, previous, page, listItems): thumbnail = u'next' arrows = u'>>' if previous == True: thumbnail = u'previous' arrows = u'<<' thumbnailPath = self.GetThumbnailPath(thumbnail) # E.g. [Page 2] >> label = u'[' + self.language(30510) + u' ' + page + u'] ' + arrows newListItem = xbmcgui.ListItem(label=label) newListItem.setThumbnailImage(thumbnailPath) url = self.GetURLStart() + u'&category=' + mycgi.URLEscape( category) + u'&title=' + mycgi.URLEscape( label) + u'&order=' + mycgi.URLEscape( order) + u'&page=' + mycgi.URLEscape(page) listItems.append((url, newListItem, True))
def CreateCategoryItem(self, category): # First letter should be uppercase newLabel = category.text newLabel = newLabel[0].upper() + newLabel[1:] categoryId = category[u'id'].replace(u'music', u'Ceol') thumbnailPath = self.GetThumbnailPath(newLabel) newListItem = xbmcgui.ListItem( label=newLabel ) newListItem.setThumbnailImage(thumbnailPath) url = self.GetURLStart() + u'&category=' + mycgi.URLEscape(categoryId) return (url, newListItem, True)
def AddCategories(self, listItems, categories): for category in categories: newLabel = category thumbnailPath = self.GetThumbnailPath(newLabel.replace(u' ', u'')) newListItem = xbmcgui.ListItem(label=newLabel) newListItem.setThumbnailImage(thumbnailPath) url = self.GetURLStart() + u'&category=' + mycgi.URLEscape( category) self.log(u"url: %s" % url, xbmc.LOGDEBUG) listItems.append((url, newListItem, True))
def AddCategories(self, listItems, categories): for category in categories: newLabel = category thumbnailPath = self.GetThumbnailPath(newLabel.replace(u' ', u'')) newListItem = {'label': newLabel, 'thumbnail': thumbnailPath} # newListItem = xbmcgui.ListItem( label=newLabel) # newListItem.setThumbnailImage(thumbnailPath) url = self.GetURLStart() + u'&category=' + mycgi.URLEscape( category) logger.debug(u"url: %s" % url) listItems.append((url, newListItem, True))
def ListSubMenu(self, html): htmlparser = HTMLParser.HTMLParser() try: soup = BeautifulSoup(html, selfClosingTags=[u'img']) aside = soup.find(u'aside') if aside is None: return self.ListLatest(soup) atozTable = soup.find(u'table', u'a-to-z') if atozTable is not None: return self.ListAToZ(atozTable) listItems = [] categories = aside.findAll(u'a') for category in categories: href = category[u'href'] title = htmlparser.unescape(category.contents[0]) newListItem = { 'label': title, 'thumbnail': title.replace(" ", "") } # newListItem = xbmcgui.ListItem( label=title ) # newListItem.setThumbnailImage(title.replace(u' ', u'')) url = self.GetURLStart() + u'&page=' + mycgi.URLEscape( href) + u'&listshows=1' listItems.append((url, newListItem, True)) logger.debug(u"url: %s" % url) # xbmcplugin.addDirectoryItems( handle=self.pluginHandle, items=listItems ) # xbmcplugin.endOfDirectory( handle=self.pluginHandle, succeeded=True ) # # return True return listItems except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) if html is not None: msg = "html:\n\n%s\n\n" % html exception.addLogMessage(msg) # Error listing submenu exception.addLogMessage("Error listing submenu") exception.process(severity=self.logLevel(logging.ERROR)) return False
def ShowEPG(self, channels, epgJSON): self.log(u"", xbmc.LOGDEBUG) channelDetails = self.ParseEPGData(epgJSON) listItems = [] for anchor in channels: try: playerIndex = anchor[u'href'].find(u'#') if playerIndex == -1: continue slug = anchor[u'href'][playerIndex + 1:] (label, description, logo) = self.GetListItemDataForSlug(channelDetails, slug) newLabel = anchor.text + " " + label newListItem = xbmcgui.ListItem( label=newLabel ) newListItem.setThumbnailImage(logo) channelUrl = self.GetURLStart() + u'&channel=' + slug + u'&logo=' + mycgi.URLEscape(logo) infoLabels = {u'Title': newLabel, u'Plot': description, u'PlotOutline': description} newListItem.setInfo(u'video', infoLabels) newListItem.setProperty(u"Video", u"true") listItems.append( (channelUrl, newListItem, False) ) except (Exception) as exception: # Problem getting details for a particular channel, show a warning and keep going if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) # Error processing channel message = self.language(30067) try: message = message + u" " + anchor.text #message = message.encode('utf8') except NameError: pass exception.addLogMessage(message) exception.process(severity = self.logLevel(xbmc.LOGWARNING)) xbmcplugin.addDirectoryItems( handle=self.pluginHandle, items=listItems ) xbmcplugin.endOfDirectory( handle=self.pluginHandle, succeeded=True ) return True
def CreateSearchItem(self, pageUrl = None): try: if pageUrl is None or len(pageUrl) == 0: newLabel = u"Search" url = self.GetURLStart() + u'&search=1' else: newLabel = u"More..." url = self.GetURLStart() + u'&search=1' + u'&page=' + mycgi.URLEscape(pageUrl) thumbnailPath = self.GetThumbnailPath(u"Search") newListItem = xbmcgui.ListItem( label=newLabel ) newListItem.setThumbnailImage(thumbnailPath) return (url, newListItem, True) except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) # Error creating Search item exception.addLogMessage(self.language(30056)) raise exception
def ShowRootMenu(self): self.log(u"", xbmc.LOGDEBUG) """ <section id="categories" class="clearfix"> <aside class="catNav clearfix"> <nav> <h2>Most popular</h2> <ul> <li class="active"> <span class="chevron"></span> <a href="/4od/tags/comedy">Comedy (100)</a> </li> </ul> <h2>More categories</h2> <ul> <li> <span class="chevron"></span> <a href="/4od/tags/animals">Animals (4)</a> </li> """ try: html = None html = self.httpManager.GetWebPage(rootMenu, 338) soup = BeautifulSoup(html) categoriesSection = soup.find('section', id="categories") entries = categoriesSection.find('nav').findAll('a') contextMenuItems = [] contextMenuItems.append( (u'Clear HTTP Cache', u"XBMC.RunPlugin(%s?clearcache=1)" % sys.argv[0])) listItems = [] pattern = u'/4od/tags/(.+)' for entry in entries: href = entry['href'] match = re.search(pattern, href, re.DOTALL | re.IGNORECASE) categoryId = match.group(1) label = unicode(entry.text).replace('\r\n', '') label = re.sub(' +', ' ', label) newListItem = xbmcgui.ListItem(label=label) newListItem.addContextMenuItems(contextMenuItems) url = self.GetURLStart() + u'&category=' + mycgi.URLEscape( categoryId) + u'&title=' + mycgi.URLEscape( label) + u'&order=' + mycgi.URLEscape( u'/latest') + u'&page=1' listItems.append((url, newListItem, True)) xbmcplugin.addDirectoryItems(handle=self.pluginHandle, items=listItems) xbmcplugin.endOfDirectory(handle=self.pluginHandle, succeeded=True) return True except (Exception) as exception: exception = LoggingException.fromException(exception) if html is not None: msg = u"html:\n\n%s\n\n" % html exception.addLogMessage(msg) # Error processing categories exception.addLogMessage(self.language(30795)) exception.process(self.language(30765), self.language(30795), severity=xbmc.LOGWARNING) return False
def DoSearchQuery(self, query): queryUrl = searchUrl % mycgi.URLEscape(query) logger.debug(u"queryUrl: %s" % queryUrl) return self.ListEpisodes(queryUrl, showDate=True)
def ShowCategory(self, category): logger.debug(u"") url = searchCategory % mycgi.URLEscape(category) return self.ListEpisodes(url, True)
def AddPageToListItems(self, category, label, order, page, listItems): """ {"feed": {"link": {"self":"http:\/\/ps3.channel4.com\/pmlsd\/tags\/animals\/4od.json?platform=ps3", "up":"http:\/\/ps3.channel4.com\/pmlsd\/tags\/animals.json?platform=ps3"}, "$":"\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n", "id":"tag:ps3.channel4.com,2009:\/programmes\/tags\/animals\/4od", "title":"4oD Animals Programmes", "updated":"2013-01-29T15:12:58.105Z", "author": {"$":"\n \n ", "name":"Channel 4 Television" }, "logo": {"@imageSource":"default", "$":"http:\/\/cache.channel4.com\/static\/programmes\/images\/c4-atom-logo.gif" }, "fh:complete":"", "dc:relation.CategoryType":"None", "dc:relation.AllProgrammeCount":5, "dc:relation.4oDProgrammeCount":1, "dc:relation.platformClientVersion":1, "generator":{"@version":"1.43","$":"PMLSD"}, "entry": {"link": {"self":"http:\/\/ps3.channel4.com\/pmlsd\/the-horse-hoarder.json?platform=ps3", "related":["http:\/\/ps3.channel4.com\/pmlsd\/the-horse-hoarder\/4od.json?platform=ps3", "http:\/\/ps3.channel4.com\/pmlsd\/the-horse-hoarder\/episode-guide.json?platform=ps3"] }, "$":"\n \n \n \n \n \n \n \n \n \n \n \n ", "id":"tag:ps3.channel4.com,2009:\/programmes\/the-horse-hoarder", "title":"The Horse Hoarder", "summary": {"@type":"html", "$":"Pensioner Clwyd Davies has accumulated 52 untamed horses, which he keeps at his home in Wrexham's suburbs" }, "updated":"2013-01-07T12:30:53.872Z", "dc:relation.sortLetter":"H", "dc:date.TXDate":"2013-01-13T02:40:00.000Z", "dc:relation.BrandWebSafeTitle":"the-horse-hoarder", "content": {"$":"\n \n ", "thumbnail": {"@url":"http:\/\/cache.channel4.com\/assets\/programmes\/images\/the-horse-hoarder\/ea8a20f0-2ba9-4648-8eec-d25a0fe35d3c_200x113.jpg", "@height":"113", "@width":"200", "@imageSource":"own", "@altText":"The Horse Hoarder" } } } } } """ try: jsonText = None pageInt = int(page) url = None if pageInt == 1: url = ps3CategoryUrl % (category, order, '') else: url = ps3CategoryUrl % (category, order, u'/page-%s' % page) jsonText = self.httpManager.GetWebPage(url, 963) jsonData = simplejson.loads(jsonText) if isinstance(jsonData[u'feed'][u'entry'], list): entries = jsonData[u'feed'][u'entry'] else: # Single entry, put in a list entries = [jsonData[u'feed'][u'entry']] for entry in entries: id = entry[u'id'] pattern = u'/programmes/(.+)' match = re.search(pattern, id, re.DOTALL | re.IGNORECASE) showId = match.group(1) thumbnail = entry[u'content'][u'thumbnail'][u'@url'] progTitle = unicode(entry[u'title']) progTitle = progTitle.replace(u'&', u'&') progTitle = progTitle.replace(u'£', u'£') synopsis = entry[u'summary'][u'$'] synopsis = synopsis.replace(u'&', u'&') synopsis = synopsis.replace(u'£', u'£') newListItem = xbmcgui.ListItem(progTitle) newListItem.setThumbnailImage(thumbnail) newListItem.setInfo( u'video', { u'Title': progTitle, u'Plot': synopsis, u'PlotOutline': synopsis }) url = self.GetURLStart( ) + u'&category=' + category + u'&show=' + mycgi.URLEscape( showId) + u'&title=' + mycgi.URLEscape(progTitle) listItems.append((url, newListItem, True)) if u'next' in jsonData[u'feed'][u'link']: nextUrl = jsonData[u'feed'][u'link'][u'next'] else: nextUrl = None return nextUrl except (Exception), exception: exception = LoggingException.fromException(exception) if jsonText is not None: msg = u"url: %s\n\n%s\n\n" % (unicode(url), jsonText) exception.addLogMessage(msg) # Error getting programme list web page exception.addLogMessage(self.language(30805)) exception.process(u"", u"", severity=self.logLevel(xbmc.LOGERROR)) raise exception
def ShowRootMenu(self): self.log(u"", xbmc.LOGDEBUG) try: jsonText = None jsonText = self.httpManager.GetWebPage( rootMenu % int(time.time() * 1000), 338) jsonData = simplejson.loads(jsonText) listItemsAtoZ = [] if isinstance(jsonData[u'feed'][u'entry'], list): entries = jsonData[u'feed'][u'entry'] else: # Single entry, put in a list entries = [jsonData[u'feed'][u'entry']] contextMenuItems = [] contextMenuItems.append( (u'Clear HTTP Cache', u"XBMC.RunPlugin(%s?clearcache=1)" % sys.argv[0])) #TODO Error handling? orderedEntries = {} for entry in entries: """ {"link": {"self":"http:\/\/ps3.channel4.com\/pmlsd\/tags\/animals.json?platform=ps3", "related": ["http:\/\/ps3.channel4.com\/pmlsd\/tags\/animals\/title.json?platform=ps3", "http:\/\/ps3.channel4.com\/pmlsd\/tags\/animals\/4od.json?platform=ps3", "http:\/\/ps3.channel4.com\/pmlsd\/tags\/animals\/4od\/title.json?platform=ps3"] }, "$":"\n \n \n \n \n \n \n \n \n \n \n \n ", "id":"tag:ps3.channel4.com,2009:\/programmes\/categories\/animals", "title":"Animals", "summary": {"@type":"html", "$":"Channel 4 Animals Programmes" }, "updated":"2013-01-29T13:34:11.491Z", "dc:relation.CategoryType":"None", "dc:relation.AllProgrammeCount":5, "dc:relation.4oDProgrammeCount":1 } """ if entry[u'dc:relation.4oDProgrammeCount'] == 0: continue id = entry[u'id'] pattern = u'/programmes/categories/(.+)' match = re.search(pattern, id, re.DOTALL | re.IGNORECASE) categoryName = match.group(1) label = unicode(entry[u'title']) + u' (' + unicode( entry[u'dc:relation.4oDProgrammeCount']) + u')' newListItem = xbmcgui.ListItem(label=label) newListItem.addContextMenuItems(contextMenuItems) url = self.GetURLStart() + u'&category=' + mycgi.URLEscape( categoryName) + u'&title=' + mycgi.URLEscape( label) + u'&order=' + mycgi.URLEscape( u'/title') + u'&page=1' if u'dc:relation.CategoryOrder' in entry: order = entry[u'dc:relation.CategoryOrder'] orderedEntries[order] = (url, newListItem, True) else: listItemsAtoZ.append((url, newListItem, True)) # Add listItems in "category" order listItems = [] index = 0 while len(orderedEntries) > 0: if index in orderedEntries: listItems.append(orderedEntries[index]) del orderedEntries[index] index = index + 1 listItems.extend(listItemsAtoZ) xbmcplugin.addDirectoryItems(handle=self.pluginhandle, items=listItems) xbmcplugin.endOfDirectory(handle=self.pluginhandle, succeeded=True) return True except (Exception), exception: exception = LoggingException.fromException(exception) if jsonText is not None: msg = u"jsonText:\n\n%s\n\n" % jsonText exception.addLogMessage(msg) # Error processing categories exception.addLogMessage(self.language(30795)) exception.process(self.language(30765), self.language(30795), severity=xbmc.LOGWARNING) return False
def DoSearchQuery( self, query): queryUrl = searchUrl % mycgi.URLEscape(query) self.log(u"queryUrl: %s" % queryUrl, xbmc.LOGDEBUG) return self.ListEpisodes(queryUrl, showDate = True)
def AddEpisodeToList(self, listItems, episode): logger.debug(u"") try: htmlparser = HTMLParser.HTMLParser() href = episode[u'href'] title = htmlparser.unescape( episode.find(u'span', u"thumbnail-title").contents[0]) date = episode.find(u'span', u"thumbnail-date").contents[0] #description = ... thumbnail = episode.find(u'img', u'thumbnail')[u'src'] newLabel = title + u", " + date if self.config.get("RTE", 'descriptions', "True") == 'True': infoLabels = self.GetEpisodeInfo( self.GetEpisodeIdFromURL(href)) else: infoLabels = {u'Title': newLabel, u'Plot': title} logger.debug(u"label == " + newLabel) if u"episodes available" in date: url = self.GetURLStart( ) + u'&listavailable=1' + u'&page=' + mycgi.URLEscape(href) newListItem = { 'label': newLabel, 'thumbnail': thumbnail, 'videoInfo': infoLabels } # newListItem = xbmcgui.ListItem( label=newLabel ) # newListItem.setThumbnailImage(thumbnail) # newListItem.setInfo(u'video', infoLabels) folder = True else: #newListItem.setProperty('IsPlayable', 'true') folder = False match = re.search(u"/player/[^/]+/show/([0-9]+)/", href) if match is None: logger.warning(u"No show id found in page href: '%s'" % href) return episodeId = match.group(1) url = self.GetURLStart() + u'&episodeId=' + mycgi.URLEscape( episodeId) contextMenuItems = [] newListItem = { 'label': newLabel, 'episodeId': episodeId, 'thumbnail': thumbnail, 'Video': True, 'contextMenuItems': contextMenuItems, 'videoInfo': infoLabels, 'url': url } # newListItem = self.ResumeWatchListItem(url, episodeId, contextMenuItems, infoLabels, thumbnail) listItems.append((url, newListItem, folder)) except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) msg = u"episode:\n\n%s\n\n" % utils.drepr(episode) exception.addLogMessage(msg) # Error getting episode details exception.addLogMessage("Error getting episode details") exception.process(self.logLevel(logging.WARNING))
def ListLatest(self, soup): self.log(u"", xbmc.LOGDEBUG) listItems = [] calendar = soup.find(u'table', u'calendar') links = calendar.findAll(u'a') links.reverse() # Today page = links[0][u'href'] newLabel = u"Today" newListItem = xbmcgui.ListItem(label=newLabel) match = re.search(u"/([0-9][0-9][0-9][0-9]-[0-9][0-9]?-[0-9][0-9]?)/", page) if match is None: self.log(u"No date match for page href: '%s'" % page, xbmc.LOGWARNING) else: url = self.GetURLStart() + u'&page=' + mycgi.URLEscape( page) + u'&listshows=1' listItems.append((url, newListItem, True)) # Yesterday page = links[1][u'href'] newLabel = u"Yesterday" newListItem = xbmcgui.ListItem(label=newLabel) match = re.search(u"/([0-9][0-9][0-9][0-9]-[0-9][0-9]?-[0-9][0-9]?)/", page) if match is None: self.log(u"No date match for page href: '%s'" % page, xbmc.LOGWARNING) else: url = self.GetURLStart() + u'&page=' + mycgi.URLEscape( page) + u'&listshows=1' listItems.append((url, newListItem, True)) # Weekday page = links[2][u'href'] match = re.search(u"/([0-9][0-9][0-9][0-9]-[0-9][0-9]?-[0-9][0-9]?)/", page) if match is None: self.log(u"No date match for page href: '%s'" % page, xbmc.LOGWARNING) else: linkDate = date.fromtimestamp( mktime(strptime(match.group(1), u"%Y-%m-%d"))) newLabel = linkDate.strftime(u"%A") newListItem = xbmcgui.ListItem(label=newLabel) url = self.GetURLStart() + u'&page=' + mycgi.URLEscape( page) + u'&listshows=1' listItems.append((url, newListItem, True)) # Weekday page = links[3][u'href'] match = re.search(u"/([0-9][0-9][0-9][0-9]-[0-9][0-9]?-[0-9][0-9]?)/", page) if match is None: self.log(u"No date match for page href: '%s'" % page, xbmc.LOGWARNING) else: linkDate = date.fromtimestamp( mktime(strptime(match.group(1), u"%Y-%m-%d"))) newLabel = linkDate.strftime(u"%A") newListItem = xbmcgui.ListItem(label=newLabel) url = self.GetURLStart() + u'&page=' + mycgi.URLEscape( page) + u'&listshows=1' listItems.append((url, newListItem, True)) for link in links[4:]: page = link[u'href'] match = re.search( u"/([0-9][0-9][0-9][0-9]-[0-9][0-9]?-[0-9][0-9]?)/", page) if match is None: self.log(u"No date match for page href: '%s'" % page, xbmc.LOGWARNING) continue linkDate = date.fromtimestamp( mktime(strptime(match.group(1), u"%Y-%m-%d"))) newLabel = linkDate.strftime(u"%A, %d %B %Y") newListItem = xbmcgui.ListItem(label=newLabel) url = self.GetURLStart() + u'&page=' + mycgi.URLEscape( page) + u'&listshows=1' listItems.append((url, newListItem, True)) xbmcplugin.addDirectoryItems(handle=self.pluginHandle, items=listItems) xbmcplugin.endOfDirectory(handle=self.pluginHandle, succeeded=True) return True
def ShowCategory(self, category): self.log(u"", xbmc.LOGDEBUG) url = searchCategory % mycgi.URLEscape(category) self.ListEpisodes(url, True)
def ListAToZ(self, page=None): self.log(u"", xbmc.LOGDEBUG) """ <div id="g1" class="gridshow"> <a href="javascript:void(0)"> <img src="./3player All Shows_files/304_180x102.jpg" class="shadow smallroundcorner"> </a> <h3> <a href="http://www.tv3.ie/3player/show/304/0/0/24+Hours+To+Kill">24 Hours To Kill</a> </h3> </div> """ try: html = None html = self.httpManager.GetWebPage(rootMenuUrl, 300) soup = BeautifulSoup(html) allShowsUrl = self.GetAllShowsLink(soup) html = self.httpManager.GetWebPage(allShowsUrl, 1800) soup = BeautifulSoup(html) htmlparser = HTMLParser.HTMLParser() listItems = [] if page is None: gridshows = soup.findAll(u'div', {u'class': re.compile(u'^gridshow')}) for gridshow in gridshows: try: title = u'' thumbnailPath = gridshow.a.img[u'src'] tooltip = gridshow.a.img[u'title'] soup = BeautifulSoup(tooltip) videos = soup.findAll(u'div', {u'id': u'tooltip_showvideo'}) page = soup.find(u'a')[u'href'] slash = page.rindex(u'/') title = page[slash + 1:].replace(u'+', u' ') title = self.fullDecode(title) # If there's just one episode then link directly to the episode if len(videos) == 1: self.AddAllShowListItem(title, videos[0], listItems, thumbnailPath) else: title = title + u", " + unicode( len(videos)) + u" episodes available" description = soup.find( u'div', { u'id': u'tooltip_showcontent' }).contents[0] if description is None or not isinstance( description, NavigableString): description = u'' else: description = self.fullDecode(description) infoLabels = { u'Title': title, u'Plot': description, u'PlotOutline': description } newListItem = xbmcgui.ListItem(label=title) newListItem.setInfo(u'video', infoLabels) newListItem.setThumbnailImage(thumbnailPath) url = self.GetURLStart( ) + u'&thumbnail=' + mycgi.URLEscape( thumbnailPath) + u'&allShows=1' listItems.append((url, newListItem, True)) except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException( exception) programme = self.GetNameFromGridshow(gridshow) # "Error processing <programme>" exception.addLogMessage( logMessage=self.language(30063) % programme + u"\n" + repr(gridshow)) exception.process( self.language(30063) % programme, "", xbmc.LOGWARNING) else: imageTag = soup.find(src=page) tooltip = imageTag[u'title'] soup = BeautifulSoup(tooltip) videos = soup.findAll(u'div', {u'id': u'tooltip_showvideo'}) page = soup.find(u'a')[u'href'] slash = page.rindex(u'/') title = page[slash + 1:].replace(u'+', u' ') title = self.fullDecode(title) for video in videos: try: self.AddAllShowListItem(title, video, listItems) except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException( exception) # "Error processing <programme>" exception.addLogMessage( logMessage=self.language(30063) % title + u"\n" + repr(video)) exception.process( self.language(30063) % title, u"", xbmc.LOGWARNING) xbmcplugin.addDirectoryItems(handle=self.pluginHandle, items=listItems) xbmcplugin.endOfDirectory(handle=self.pluginHandle, succeeded=True) except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) if html is not None: msg = u"html:\n\n%s\n\n" % html exception.addLogMessage(msg) # Error processing "Show All" menu exception.addLogMessage(self.language(30023)) exception.process(severity=self.logLevel(xbmc.LOGERROR)) return False return True
def ListEpisodes(self, url, showDate = False): self.log(u"", xbmc.LOGDEBUG) """ [{ "id":"2160442511001", "name":"Nuacht TG4 16-43 (P1)", "shortDescription":"The day\u2019s main news stories from a regional, national and international perspective.", "creationDate":"1360700199450", "videoStillURL":"http:\/\/tgfour.brightcove.com.edgesuite.net\/pd\/1290862567001\/1290862567001_2160571128001_vs-511aa327e4b04ce8a4582520-672293875001.jpg?pubId=1290862567001", "thumbnailURL":"http:\/\/tgfour.brightcove.com.edgesuite.net\/pd\/1290862567001\/1290862567001_2160571130001_th-511aa327e4b04ce8a4582520-672293875001.jpg?pubId=1290862567001", "length":1047777, "customFields":{ "title":"Nuacht TG4", "longdescgaeilge":"M\u00f3rimeachta\u00ed an lae \u00f3 Aonad Nuachta TG4.", "seriestitle":"Nuacht TG4", "date":"12.02.13" } } """ try: jsonData = None item = None headers = { 'Content-Type' : 'application/x-www-form-urlencoded', 'X-Requested-With' : 'XMLHttpRequest' } jsonData = self.httpManager.GetWebPage (url, 300, headers = headers) jsonObject = _json.loads(jsonData) listItems = [] for item in jsonObject: try: title = item[u'customFields'][u'title'] # Exclude Live TV if title.startswith("TG4 Beo"): continue self.log(u"Title: " + title) if self.languageCode == u'ie': description = item[u'customFields'][u'longdescgaeilge'] else: if u'longDescription' in item: description = item[u'longDescription'] else: description = item[u'shortDescription'] dateString = item[u'customFields'][u'date'] airDate = self.GetAirDate(dateString) self.log(u"airDate: " + repr(airDate), xbmc.LOGDEBUG) self.log(u"showDate: " + repr(showDate), xbmc.LOGDEBUG) if showDate and airDate is not None: title = title + " [" + airDate.strftime(u"%A, %d %B %Y") + "]" infoLabels = { u'Title': title, u'Plot': description, u'PlotOutline': description, u'Date': airDate.strftime(u"%d.%m.%Y"), u'PremiereDate': airDate.strftime(u"%d.%m.%Y") } id = item['id'] thumbnail = item[u'videoStillURL'] if u'name' in item: newLabel = item[u'name'] if showDate: newLabel = newLabel + " [" + airDate.strftime(u"%A, %d %B %Y") + "]" else: newLabel = title newListItem = xbmcgui.ListItem( label=newLabel) newListItem.setThumbnailImage(thumbnail) newListItem.setInfo(u'video', infoLabels) newListItem.setProperty("Video", "true") #newListItem.setProperty('IsPlayable', 'true') url = self.GetURLStart() + u'&episodeId=' + mycgi.URLEscape(id) + u'&series=' + mycgi.URLEscape(item['customFields']['seriestitle']) listItems.append( (url, newListItem, False) ) except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) if item is not None: msg = u"item:\n\n%s\n\n" % repr(item) exception.addLogMessage(msg) if item is not None and u'customFields' in item and u'title' in item[u'customFields'] : programme = item[u'customFields'][u'title'] else: programme = u"programme" exception.addLogMessage((self.language(30063) % programme)) exception.process(self.language(30063) % programme, "", xbmc.LOGWARNING) xbmcplugin.addDirectoryItems( handle=self.pluginHandle, items=listItems ) xbmcplugin.endOfDirectory( handle=self.pluginHandle, succeeded=True ) return True except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) if jsonData is not None: msg = u"jsonData:\n\n%s\n\n" % jsonData exception.addLogMessage(msg) if item is not None: msg = u"item:\n\n%s\n\n" % jsonData exception.addLogMessage(msg) # Error preparing or playing stream exception.addLogMessage(self.language(40340)) exception.process(severity = self.logLevel(xbmc.LOGERROR)) return False