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 ParseCommand(self, mycgi): (category, search, allShows, calendar, date, page, thumbnail, resume) = mycgi.Params(u'category', u'search', u'allShows', u'calendar', u'date', u'page', u'thumbnail', u'resume') self.log( u"category: %s, search: %s, allShows: %s, calendar: %s, date: %s, page: %s, thumbnail: %s, resume: %s" % (category, str(search), str(allShows), calendar, date, page, thumbnail, str(resume)), xbmc.LOGDEBUG) if search <> u'': return self.DoSearch() if category <> u'': return self.ShowCategory(category) if allShows <> u'': if thumbnail <> u'': return self.ListAToZ(thumbnail) else: return self.ListAToZ() if calendar <> u'': return self.ListCalendar() if date <> u'': return self.ListByDate(date) if page == u'': # "Can't find 'page' parameter " logException = LoggingException(logMessage=self.language(30030)) # 'Cannot proceed', Error processing command logException.process(self.language(30755), self.language(30780), self.logLevel(xbmc.LOGERROR)) return False self.log(u"page = %s" % page, xbmc.LOGDEBUG) page = mycgi.URLUnescape(page) self.log(u"mycgi.URLUnescape(page) = %s" % page, xbmc.LOGDEBUG) if u' ' in page: page = page.replace(u' ', u'%20') resumeFlag = False if resume <> u'': resumeFlag = True try: return self.PlayVideoWithDialog(self.PlayEpisode, (page, resumeFlag)) except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) # "Error playing or downloading episode %s" exception.addLogMessage(self.language(30051) % u"") # "Error processing video" exception.process(severity=self.logLevel(xbmc.LOGERROR)) return False
def DoSearchQuery(self, query): self.log(u"query: %s" % query, xbmc.LOGDEBUG) values = {u'queryString': query, u'limit': 20} # headers = {'DNT':'1', 'X-Requested-With':'XMLHttpRequest' } headers = {} headers[u'DNT'] = u'1' headers[u'Referer'] = u'http://www.tv3.ie/3player/' headers[ u'Content-Type'] = u'application/x-www-form-urlencoded; charset=UTF-8' html = self.httpManager.GetWebPage(searchUrl, 1800, values=values, headers=headers) if html is None or html == u'': # Data returned from web page: %s, is: '%s' logException = LoggingException(logMessage=self.language(30060) % (searchUrl, html)) # Error getting web page logException.process(self.language(30050), u'', self.logLevel(xbmc.LOGERROR)) return False # Fix fcuked up TV3 HTML formatting html = html.replace(u"<h3 id='search_heading'>Videos</h2>", "<h3 id='search_heading'>Videos</h3>") self.ListSearchShows(html) return True
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 AttemptLogin(self, values, logUrl = False): self.log(u"", xbmc.LOGDEBUG) try: loginJSONText = None loginJSON = None url = self.GetAPIUrl(values) loginJSONText = self.httpManager.GetWebPageDirect(url, logUrl = logUrl) loginJSON = _json.loads(loginJSONText) for key in loginJSON: self.log(u"loginJSON['%s'] exists" % key, xbmc.LOGDEBUG) if u'user' in loginJSON: self.log(u"loginJSON['user']", xbmc.LOGDEBUG) for key in loginJSON[u'user']: if key == u'fname' or key == u'lname' or key == 'email': self.log(u"loginJSON['user']['%s'] exists" % key, xbmc.LOGDEBUG) else: self.log(u"loginJSON['user']['%s'] = %s" % (key, utils.drepr(loginJSON[u'user'][key])), xbmc.LOGDEBUG) # Check for failed login if loginJSON[u'user'][u'login'] != True: # Show error message if u'status' in loginJSON[u'user']: statusMessage = loginJSON[u'user'][u'status'] else: statusMessage = u"None" # 'AerTV login failed', logException = LoggingException(self.language(30101)) # "Status Message: %s logException.process(self.language(30102) % statusMessage, u"", xbmc.LOGDEBUG) return None self.log(u"AerTV successful login", xbmc.LOGDEBUG) return loginJSON except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) if loginJSONText is not None: msg = u"loginJSONText:\n\n%s\n\n" % loginJSONText exception.addLogMessage(msg) if loginJSON is not None: msg = u"epgJSON:\n\n%s\n\n" % utils.drepr(loginJSON) exception.addLogMessage(msg) raise exception
def ListByDate(self, date): values = {u'queryString' : date} html = None html = self.httpManager.GetWebPage( calendarUrl, 3600, values = values) if html is None or html == u'': # Data returned from web page: %s, is: '%s' logException = LoggingException(logMessage = self.language(30060) % ( searchUrl, html )) # Error getting web page logException.process(self.language(30050), u'', self.logLevel(xbmc.LOGERROR)) return False soup = BeautifulSoup(html) listItems = [] htmlparser = HTMLParser.HTMLParser() videos = soup.findAll(u'div', {u'id':u'tooltip_showvideo_cal'}) if len(videos) == 1 and len(videos[0].findAll(u'a')) == 0: # No videos broadcast on this date. xbmc.executebuiltin(u'XBMC.Notification(IrishTV, %s)' % (videos[0].text)) return True for video in videos: try: anchors = video.findAll(u'a') time = anchors[2].small.text title = self.fullDecode( anchors[1].b.text + u", " + time ) description = self.fullDecode( anchors[3].text ) infoLabels = {u'Title': title, u'Plot': description, u'PlotOutline': description} page = anchors[0][u'href'] thumbnail = anchors[0].img[u'src'] self.AddEpisodeItem(title, thumbnail, infoLabels, page, listItems) except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) if video is not None: msg = u"video:\n\n%s\n\n" % video exception.addLogMessage(msg) # "Error processing video" exception.addLogMessage(logMessage = self.language(30063) % u"video\n" + repr(video)) # "Error processing video" exception.process(self.language(30063) % programme % u"video\n", u"", xbmc.LOGWARNING) continue xbmcplugin.addDirectoryItems( handle=self.pluginHandle, items=listItems ) xbmcplugin.endOfDirectory( handle=self.pluginHandle, succeeded=True ) return True
def executeCommand(): pluginHandle = int(sys.argv[1]) success = False if (mycgi.EmptyQS()): success = ShowProviders() else: (providerName, clearCache, testForwardedIP) = mycgi.Params(u'provider', u'clearcache', u'testforwardedip') if clearCache != u'': httpManager.ClearCache() return True elif testForwardedIP != u'': provider = Provider() provider.addon = addon httpManager.SetDefaultHeaders(provider.GetHeaders()) forwardedIP = provider.CreateForwardedForIP('0.0.0.0') return TestForwardedIP(forwardedIP) elif providerName != u'': log(u"providerName: " + providerName, xbmc.LOGDEBUG) if providerName <> u'': provider = providerfactory.getProvider(providerName) if provider is None: # ProviderFactory return none for providerName: %s logException = LoggingException( language(30000) % providerName) # 'Cannot proceed', Error processing provider name logException.process(language(30755), language(30020), xbmc.LOGERROR) return False if provider.initialise(httpManager, sys.argv[0], pluginHandle, addon, language, PROFILE_DATA_FOLDER, RESOURCE_PATH): success = provider.ExecuteCommand(mycgi) log(u"executeCommand done", xbmc.LOGDEBUG) """ print cookiejar print 'These are the cookies we have received so far :' for index, cookie in enumerate(cookiejar): print index, ' : ', cookie cookiejar.save() """ return success
def ParseCommand(self, mycgi): (category, search, allShows, calendar, date, page, thumbnail, resume) = mycgi.Params( u'category', u'search', u'allShows', u'calendar', u'date', u'page', u'thumbnail', u'resume' ) self.log(u"category: %s, search: %s, allShows: %s, calendar: %s, date: %s, page: %s, thumbnail: %s, resume: %s" % (category, str(search), str(allShows), calendar, date, page, thumbnail, str(resume)), xbmc.LOGDEBUG) if search <> u'': return self.DoSearch() if category <> u'': return self.ShowCategory(category) if allShows <> u'': if thumbnail <> u'': return self.ListAToZ(thumbnail) else: return self.ListAToZ() if calendar <> u'': return self.ListCalendar() if date <> u'': return self.ListByDate(date) if page == u'': # "Can't find 'page' parameter " logException = LoggingException(logMessage = self.language(30030)) # 'Cannot proceed', Error processing command logException.process(self.language(30755), self.language(30780), self.logLevel(xbmc.LOGERROR)) return False self.log(u"page = %s" % page, xbmc.LOGDEBUG) page = mycgi.URLUnescape(page) self.log(u"mycgi.URLUnescape(page) = %s" % page, xbmc.LOGDEBUG) if u' ' in page: page = page.replace(u' ', u'%20') resumeFlag = False if resume <> u'': resumeFlag = True try: return self.PlayVideoWithDialog(self.PlayEpisode, (page, resumeFlag)) except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) # "Error playing or downloading episode %s" exception.addLogMessage(self.language(30051) % u"") # "Error processing video" exception.process(severity = self.logLevel(xbmc.LOGERROR)) return False
def executeCommand(): pluginHandle = int(sys.argv[1]) success = False if ( mycgi.EmptyQS() ): success = ShowProviders() else: (providerName, clearCache, testForwardedIP) = mycgi.Params( u'provider', u'clearcache', u'testforwardedip' ) if clearCache != u'': httpManager.ClearCache() return True elif testForwardedIP != u'': provider = Provider() provider.addon = addon httpManager.SetDefaultHeaders( provider.GetHeaders() ) forwardedIP = provider.CreateForwardedForIP('0.0.0.0') return TestForwardedIP(forwardedIP) elif providerName != u'': log(u"providerName: " + providerName, xbmc.LOGDEBUG) if providerName <> u'': provider = providerfactory.getProvider(providerName) if provider is None: # ProviderFactory return none for providerName: %s logException = LoggingException(language(30000) % providerName) # 'Cannot proceed', Error processing provider name logException.process(language(30755), language(30020), xbmc.LOGERROR) return False if provider.initialise(httpManager, sys.argv[0], pluginHandle, addon, language, PROFILE_DATA_FOLDER, RESOURCE_PATH): success = provider.ExecuteCommand(mycgi) log (u"executeCommand done", xbmc.LOGDEBUG) """ print cookiejar print 'These are the cookies we have received so far :' for index, cookie in enumerate(cookiejar): print index, ' : ', cookie cookiejar.save() """ return success
def DoSearchQuery( self, query ): self.log(u"query: %s" % query, xbmc.LOGDEBUG) values = {u'queryString':query, u'limit':20} # headers = {'DNT':'1', 'X-Requested-With':'XMLHttpRequest' } headers = {} headers[u'DNT'] = u'1' headers[u'Referer'] = u'http://www.tv3.ie/3player/' headers[u'Content-Type'] = u'application/x-www-form-urlencoded; charset=UTF-8' html = self.httpManager.GetWebPage( searchUrl, 1800, values = values, headers = headers ) if html is None or html == u'': # Data returned from web page: %s, is: '%s' logException = LoggingException(logMessage = self.language(30060) % ( searchUrl, html )) # Error getting web page logException.process(self.language(30050), u'', self.logLevel(xbmc.LOGERROR)) return False # Fix fcuked up TV3 HTML formatting html = html.replace(u"<h3 id='search_heading'>Videos</h2>", "<h3 id='search_heading'>Videos</h3>") self.ListSearchShows(html) return True
def ListByDate(self, date): values = {u'queryString': date} html = None html = self.httpManager.GetWebPage(calendarUrl, 3600, values=values) if html is None or html == u'': # Data returned from web page: %s, is: '%s' logException = LoggingException(logMessage=self.language(30060) % (searchUrl, html)) # Error getting web page logException.process(self.language(30050), u'', self.logLevel(xbmc.LOGERROR)) return False soup = BeautifulSoup(html) listItems = [] htmlparser = HTMLParser.HTMLParser() videos = soup.findAll(u'div', {u'id': u'tooltip_showvideo_cal'}) if len(videos) == 1 and len(videos[0].findAll(u'a')) == 0: # No videos broadcast on this date. xbmc.executebuiltin(u'XBMC.Notification(IrishTV, %s)' % (videos[0].text)) return True for video in videos: try: anchors = video.findAll(u'a') time = anchors[2].small.text title = self.fullDecode(anchors[1].b.text + u", " + time) description = self.fullDecode(anchors[3].text) infoLabels = { u'Title': title, u'Plot': description, u'PlotOutline': description } page = anchors[0][u'href'] thumbnail = anchors[0].img[u'src'] self.AddEpisodeItem(title, thumbnail, infoLabels, page, listItems) except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) if video is not None: msg = u"video:\n\n%s\n\n" % video exception.addLogMessage(msg) # "Error processing video" exception.addLogMessage( logMessage=self.language(30063) % u"video\n" + repr(video)) # "Error processing video" exception.process( self.language(30063) % programme % u"video\n", u"", xbmc.LOGWARNING) continue xbmcplugin.addDirectoryItems(handle=self.pluginHandle, items=listItems) xbmcplugin.endOfDirectory(handle=self.pluginHandle, succeeded=True) return True
def ShowRootMenu(self): self.log(u"", xbmc.LOGDEBUG) try: html = None html = self.httpManager.GetWebPage(rootMenuUrl, 300) if html is None or html == u'': # Error getting %s Player "Home" page logException = LoggingException( logMessage=self.language(30001) % self.GetProviderId()) # 'Cannot show TV3 root menu', Error getting TV3 Player "Home" page logException.process( self.language(30002) % self.GetProviderId(), self.language(30001) % self.GetProviderId(), self.logLevel(xbmc.LOGERROR)) #raise logException return False #soup = BeautifulSoup(html, selfClosingTags=['img']) categories = self.GetCategories(html) if len(categories) == 0: # "Can't find dropdown-programmes" logException = LoggingException( logMessage=self.language(30003)) # 'Cannot show TV3 root menu', Error parsing web page logException.process(self.language(30002), self.language(30780), self.logLevel(xbmc.LOGERROR)) #raise logException return False listItems = [] # Search newLabel = self.language(30500) thumbnailPath = self.GetThumbnailPath(newLabel) newListItem = xbmcgui.ListItem(label=newLabel) newListItem.setThumbnailImage(thumbnailPath) url = self.GetURLStart() + u'&search=1' listItems.append((url, newListItem, True)) # self.AddFeatured(listItems, html) self.AddCategories(listItems, categories) # All Shows - A to Z newLabel = self.language(30061) thumbnailPath = self.GetThumbnailPath(newLabel) newListItem = xbmcgui.ListItem(label=newLabel) newListItem.setThumbnailImage(thumbnailPath) url = self.GetURLStart() + u'&allShows=1' listItems.append((url, newListItem, True)) # All Shows - By Date newLabel = self.language(30062) thumbnailPath = self.GetThumbnailPath(newLabel) newListItem = xbmcgui.ListItem(label=newLabel) newListItem.setThumbnailImage(thumbnailPath) url = self.GetURLStart() + u'&calendar=1' listItems.append((url, newListItem, True)) 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) # Cannot show root menu exception.addLogMessage(self.language(30010)) exception.process(severity=self.logLevel(xbmc.LOGERROR)) return False return True
httpManager.SetDefaultHeaders( provider.GetHeaders() ) forwardedIP = provider.CreateForwardedForIP('0.0.0.0') return TestForwardedIP(forwardedIP) elif providerName != u'': logger.debug(u"providerName: " + providerName) if providerName <> u'': provider = providerfactory.getProvider(providerName) if provider is None: # ProviderFactory return none for providerName: %s logException = LoggingException("ProviderFactory returned None for providerName: %s" % providerName) # 'Cannot proceed', Error processing provider name logException.process("Cannot proceed", "Error processing provider name", logging.ERROR) return False if provider.initialise(httpManager, sys.argv[0], PROFILE_DATA_FOLDER, RESOURCE_PATH, config): success = provider.ExecuteCommand(mycgi) if outputJsonFile: with open(outputJsonFile, "w") as f: if not success: f.write("[]\n") else: f.write(json.dumps(success)) print success logger.debug(u"executeCommand done") """ print cookiejar
def ShowRootMenu(self): self.log(u"", xbmc.LOGDEBUG) dialog = xbmcgui.Dialog() dialog.ok("Return", "This section doesn't work") return False try: html = None html = self.httpManager.GetWebPage(rootMenuUrl, 60) if html is None or html == '': # Error getting %s Player "Home" page logException = LoggingException( self.language(30001) % self.GetProviderId()) # 'Cannot show RTE root menu', Error getting RTE Player "Home" page logException.process( self.language(30002) % self.GetProviderId(), self.language(30001) % self.GetProviderId(), self.logLevel(xbmc.LOGERROR)) return False soup = BeautifulSoup(html, selfClosingTags=['img']) categories = soup.find(u'div', u"dropdown-programmes") if categories == None: # "Can't find dropdown-programmes" logException = LoggingException(self.language(30003)) # 'Cannot show RTE root menu', Error parsing web page logException.process( self.language(30002) % self.GetProviderId(), self.language(30780), self.logLevel(xbmc.LOGERROR)) #raise logException return False listItems = [] try: listItems.append(self.CreateSearchItem()) except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) # Not fatal, just means that we don't have the search option exception.process(severity=xbmc.LOGWARNING) if False == self.AddAllLinks(listItems, categories, autoThumbnails=True): return False newLabel = u"Live" thumbnailPath = self.GetThumbnailPath(newLabel) newListItem = xbmcgui.ListItem(label=newLabel) newListItem.setThumbnailImage(thumbnailPath) url = self.GetURLStart() + u'&live=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: 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) # Cannot show root menu exception.addLogMessage(self.language(30010)) exception.process(severity=self.logLevel(xbmc.LOGERROR)) return False
def ParseCommand(self, mycgi): (listshows, episodeId, listAvailable, search, page, live, resume) = mycgi.Params(u'listshows', u'episodeId', u'listavailable', u'search', u'page', u'live', u'resume') self.log(u"", xbmc.LOGDEBUG) self.log( u"listshows: %s, episodeId %s, listAvailable %s, search %s, page %s, resume: %s" % (str(listshows), episodeId, str(listAvailable), str(search), page, str(resume)), xbmc.LOGDEBUG) if episodeId <> '': resumeFlag = False if resume <> u'': resumeFlag = True #return self.PlayEpisode(episodeId) return self.PlayVideoWithDialog(self.PlayEpisode, (episodeId, resumeFlag)) if search <> '': if page == '': return self.DoSearch() else: return self.DoSearchQuery(queryUrl=urlRoot + page) if page == '': if live <> '': return self.ShowLiveMenu() # "Can't find 'page' parameter " logException = LoggingException(logMessage=self.language(30030)) # 'Cannot proceed', Error processing command logException.process(self.language(30010), self.language(30780), self.logLevel(xbmcc.LOGERROR)) return False page = page # TODO Test this self.log(u"page = %s" % page, xbmc.LOGDEBUG) #self.log(u"type(page): " + repr(type(page)), xbmc.LOGDEBUG) ##page = mycgi.URLUnescape(page) #self.log(u"page = %s" % page, xbmc.LOGDEBUG) #self.log(u"type(mycgi.URLUnescape(page)): " + repr(type(page)), xbmc.LOGDEBUG) # self.log(u"mycgi.URLUnescape(page) = %s" % page, xbmc.LOGDEBUG) if u' ' in page: page = page.replace(u' ', u'%20') try: self.log(u"urlRoot: " + urlRoot + u", page: " + page) html = None html = self.httpManager.GetWebPage(urlRoot + page, 1800) 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 web page exception.addLogMessage(self.language(30050)) exception.process(severity=self.logLevel(xbmc.LOGERROR)) return False if live <> '': #return self.PlayLiveTV(html) return self.PlayVideoWithDialog(self.PlayLiveTV, (html, None)) if listshows <> u'': return self.ListShows(html) if listAvailable <> u'': soup = BeautifulSoup(html) availableLink = soup.find('a', 'button-more-episodes') if availableLink is None: pattern = "/player/ie/show/(.+)/" match = re.search(pattern, html, re.DOTALL) if match is not None: episodeId = match.group(1) resumeFlag = False if resume <> u'': resumeFlag = True return self.PlayVideoWithDialog(self.PlayEpisode, (episodeId, resumeFlag)) return self.ListAvailable(html) return self.ListSubMenu(html)
def Login(self): self.log(u"", xbmc.LOGDEBUG) """ { 'epg': 'WEB_STD', 'user': { 'decay': 40, 'email': 'email', 'fname': 'fname', 'id': '87354', 'ipicid': 'aertv530916c892b25', 'is_paid_subscriber': 0/1, 'lname': 'lname', 'login': True, 'mailchimp': None, 'packages': [ { 'code': 'WEB_STD', 'desc': 'Free Channel Pack', 'package_id': '1' }, { "code":"AERTV_PLUS", "desc":"Aertv Plus", "package_id":"6" } ], 'session': 'YWVydHY1MzA5MTZjODkyYjI0_1393452432', 'status': '1', 'val_code': None } } """ loginJSON = None email = self.addon.getSetting( u'AerTV_email' ).decode(u'utf8') password = self.addon.getSetting( u'AerTV_password' ).decode(u'utf8') if len(email) == 0 or len(password) == 0: if not xbmcvfs.exists(self.aertvNoticeFilePath): file = open(self.aertvNoticeFilePath, u'w') try: file.write(" ") finally: file.close() dialog = xbmcgui.Dialog() dialog.ok(self.language(30105), self.language(30106)) self.addon.openSettings(sys.argv[ 0 ]) email = self.addon.getSetting( u'AerTV_email' ).decode(u'utf8') password = self.addon.getSetting( u'AerTV_password' ).decode(u'utf8') if len(email) == 0 or len(password) == 0: self.log(u"No AerTV login details", xbmc.LOGDEBUG) return False try: loginJSON = self.LoginViaCookie() except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) # 'AerTV login failed', exception.addLogMessage(self.language(30101)) exception.process(severity = self.logLevel(xbmc.LOGWARNING)) if loginJSON is None: try: values = [{u'api':u'login'},{u'user':email},{u'pass':password}] loginJSON = self.AttemptLogin(values, logUrl = False) self.log(u"After weblogin loginJSON is None: " + unicode(loginJSON is None), xbmc.LOGDEBUG) if loginJSON is None: # 'AerTV login failed', exception = LoggingException(self.language(30101)) # "Status Message: %s exception.process(severity = self.logLevel(xbmc.LOGERROR)) return False self.log(u"Login successful", xbmc.LOGDEBUG) sessionId = loginJSON[u'user'][u'session'] days02 = 2*24*60*60 expiry = int(time.time()) + days02 self.log(u"Aertv_login expiry: " + unicode(expiry), xbmc.LOGDEBUG) sessionCookie = self.MakeCookie(u'Aertv_login', sessionId, domain, expiry ) self.cookiejar.set_cookie(sessionCookie) self.cookiejar.save() loginJSON = self.LoginViaCookie() except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) # Error logging into AerTV exception.addLogMessage(self.language(30101)) exception.process(severity = self.logLevel(xbmc.LOGERROR)) return False self.LogLoginInfo(loginJSON) if len(utils.getDictionaryValue(loginJSON[u'user'], u'packages')) < 2: # Error logging into AerTV exception = LoggingException(self.language(30101)) exception.process(severity = self.logLevel(xbmc.LOGERROR)) return False return True
def ShowRootMenu(self): self.log(u"", xbmc.LOGDEBUG) try: html = None html = self.httpManager.GetWebPage(rootMenuUrl, 60) if html is None or html == '': # Error getting %s Player "Home" page logException = LoggingException(self.language(30001) % self.GetProviderId()) # 'Cannot show RTE root menu', Error getting RTE Player "Home" page logException.process(self.language(30002) % self.GetProviderId(), self.language(30001) % self.GetProviderId(), self.logLevel(xbmc.LOGERROR)) return False soup = BeautifulSoup(html, selfClosingTags=['img']) categories = soup.find(u'div', u"dropdown-programmes") if categories == None: # "Can't find dropdown-programmes" logException = LoggingException(self.language(30003)) # 'Cannot show RTE root menu', Error parsing web page logException.process(self.language(30002) % self.GetProviderId(), self.language(30780), self.logLevel(xbmc.LOGERROR)) #raise logException return False listItems = [] try: listItems.append( self.CreateSearchItem() ) except (Exception) as exception: if not isinstance(exception, LoggingException): exception = LoggingException.fromException(exception) # Not fatal, just means that we don't have the search option exception.process(severity = xbmc.LOGWARNING) if False == self.AddAllLinks(listItems, categories, autoThumbnails = True): return False newLabel = u"Live" thumbnailPath = self.GetThumbnailPath(newLabel) newListItem = xbmcgui.ListItem( label=newLabel ) newListItem.setThumbnailImage(thumbnailPath) url = self.GetURLStart() + u'&live=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: 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) # Cannot show root menu exception.addLogMessage(self.language(30010)) exception.process(severity = self.logLevel(xbmc.LOGERROR)) return False
def ParseCommand(self, mycgi): (listshows, episodeId, listAvailable, search, page, live, resume) = mycgi.Params( u'listshows', u'episodeId', u'listavailable', u'search', u'page', u'live', u'resume' ) self.log(u"", xbmc.LOGDEBUG) self.log(u"listshows: %s, episodeId %s, listAvailable %s, search %s, page %s, resume: %s" % (str(listshows), episodeId, str(listAvailable), str(search), page, str(resume)), xbmc.LOGDEBUG) if episodeId <> '': resumeFlag = False if resume <> u'': resumeFlag = True #return self.PlayEpisode(episodeId) return self.PlayVideoWithDialog(self.PlayEpisode, (episodeId, resumeFlag)) if search <> '': if page == '': return self.DoSearch() else: return self.DoSearchQuery( queryUrl = urlRoot + page) if page == '': if live <> '': return self.ShowLiveMenu() # "Can't find 'page' parameter " logException = LoggingException(logMessage = self.language(30030)) # 'Cannot proceed', Error processing command logException.process(self.language(30010), self.language(30780), self.logLevel(xbmcc.LOGERROR)) return False page = page # TODO Test this self.log(u"page = %s" % page, xbmc.LOGDEBUG) #self.log(u"type(page): " + repr(type(page)), xbmc.LOGDEBUG) ##page = mycgi.URLUnescape(page) #self.log(u"page = %s" % page, xbmc.LOGDEBUG) #self.log(u"type(mycgi.URLUnescape(page)): " + repr(type(page)), xbmc.LOGDEBUG) # self.log(u"mycgi.URLUnescape(page) = %s" % page, xbmc.LOGDEBUG) if u' ' in page: page = page.replace(u' ', u'%20') try: self.log(u"urlRoot: " + urlRoot + u", page: " + page ) html = None html = self.httpManager.GetWebPage( urlRoot + page, 1800 ) 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 web page exception.addLogMessage(self.language(30050)) exception.process(severity = self.logLevel(xbmc.LOGERROR)) return False if live <> '': #return self.PlayLiveTV(html) return self.PlayVideoWithDialog(self.PlayLiveTV, (html, None)) if listshows <> u'': return self.ListShows(html) if listAvailable <> u'': soup = BeautifulSoup(html) availableLink = soup.find('a', 'button-more-episodes') if availableLink is None: pattern= "/player/ie/show/(.+)/" match=re.search(pattern, html, re.DOTALL) if match is not None: episodeId = match.group(1) resumeFlag = False if resume <> u'': resumeFlag = True return self.PlayVideoWithDialog(self.PlayEpisode, (episodeId, resumeFlag)) return self.ListAvailable(html) return self.ListSubMenu(html)
def ShowRootMenu(self): self.log(u"", xbmc.LOGDEBUG) try: html = None html = self.httpManager.GetWebPage(rootMenuUrl, 300) if html is None or html == u'': # Error getting %s Player "Home" page logException = LoggingException(logMessage = self.language(30001) % self.GetProviderId()) # 'Cannot show TV3 root menu', Error getting TV3 Player "Home" page logException.process(self.language(30002) % self.GetProviderId(), self.language(30001) % self.GetProviderId(), self.logLevel(xbmc.LOGERROR)) #raise logException return False #soup = BeautifulSoup(html, selfClosingTags=['img']) categories = self.GetCategories(html) if len(categories) == 0: # "Can't find dropdown-programmes" logException = LoggingException(logMessage = self.language(30003)) # 'Cannot show TV3 root menu', Error parsing web page logException.process(self.language(30002), self.language(30780), self.logLevel(xbmc.LOGERROR)) #raise logException return False listItems = [] # Search newLabel = self.language(30500) thumbnailPath = self.GetThumbnailPath(newLabel) newListItem = xbmcgui.ListItem( label=newLabel ) newListItem.setThumbnailImage(thumbnailPath) url = self.GetURLStart() + u'&search=1' listItems.append( (url, newListItem, True) ) # self.AddFeatured(listItems, html) self.AddCategories(listItems, categories) # All Shows - A to Z newLabel = self.language(30061) thumbnailPath = self.GetThumbnailPath(newLabel) newListItem = xbmcgui.ListItem( label=newLabel ) newListItem.setThumbnailImage(thumbnailPath) url = self.GetURLStart() + u'&allShows=1' listItems.append( (url, newListItem, True) ) # All Shows - By Date newLabel = self.language(30062) thumbnailPath = self.GetThumbnailPath(newLabel) newListItem = xbmcgui.ListItem( label=newLabel ) newListItem.setThumbnailImage(thumbnailPath) url = self.GetURLStart() + u'&calendar=1' listItems.append( (url, newListItem, True) ) 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) # Cannot show root menu exception.addLogMessage(self.language(30010)) exception.process(severity = self.logLevel(xbmc.LOGERROR)) return False return True