def CreateLiveChannel(self, resultSet): Logger.Trace(resultSet) item = mediaitem.MediaItem(resultSet[0], resultSet[1]) item.type = "video" item.isGeoLocked = resultSet[3].lower() == "true" dateTime = DateHelper.GetDateFromPosix(int(resultSet[2]) * 1 / 1000) item.SetDate(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second) thumb = resultSet[4] if not thumb.startswith("http"): thumb = "%s%s" % (self.baseUrl, thumb) item.thumb = thumb return item
def CreateVideoItemJson(self, resultSet): Logger.Trace(resultSet) title = resultSet['title'] url = "https://vod.medialaan.io/vod/v2/videos/%(id)s" % resultSet item = MediaItem(title, url, type="video") item.description = resultSet.get('text') item.thumb = self.parentItem.thumb if 'image' in resultSet: item.thumb = resultSet['image'].get("full", None) created = DateHelper.GetDateFromPosix(resultSet['created']) item.SetDate(created.year, created.month, created.day, created.hour, created.minute, created.second) return item
def CreateProgramFolder(self, resultSet): """Creates a MediaItem of type 'folder' using the resultSet from the regex. Arguments: resultSet : tuple(strig) - the resultSet of the self.folderItemRegex Returns: A new MediaItem of type 'folder' This method creates a new MediaItem from the Regular Expression or Json results <resultSet>. The method should be implemented by derived classes and are specific to the channel. """ Logger.Trace(resultSet) title = resultSet["title"] seriesId = resultSet.get("seriesId") if seriesId is None: return None categoryId = resultSet.get("categoryId", None) parentCategoryId = self.parentItem.metaData.get(self.__metaDataIndexCategory, None) if parentCategoryId is not None and parentCategoryId != categoryId: return None item = mediaitem.MediaItem(title, "%s/series/%s" % (self.baseUrl, seriesId)) item.icon = self.icon item.type = 'folder' item.fanart = self.fanart item.description = resultSet.get("description", "") item.HttpHeaders = self.httpHeaders imageId = resultSet.get("seriesImageId", None) if imageId is not None: item.thumb = "http://m.nrk.no/img?kaleidoId=%s&width=720" % (imageId, ) item.fanart = "http://m.nrk.no/img?kaleidoId=%s&width=1280" % (imageId, ) if "usageRights" in resultSet: item.isGeoLocked = resultSet["usageRights"].get("geoblocked", False) if "availableFrom" in resultSet["usageRights"]: timeStamp = int(resultSet["usageRights"]["availableFrom"]) / 1000 if 0 < timeStamp < sys.maxint: date = DateHelper.GetDateFromPosix(timeStamp) item.SetDate(date.year, date.month, date.day, date.hour, date.minute, date.second) return item
def CreateVideoItem(self, resultSet): Logger.Trace(resultSet) title = resultSet["title"] if "subTitle" in resultSet: title = "%s - %s" % (title, resultSet["subTitle"]) mgid = resultSet["id"].split(":")[-1] url = "http://feeds.mtvnservices.com/od/feed/intl-mrss-player-feed" \ "?mgid=mgid:arc:episode:mtvplay.com:%s" \ "&ep=%s" \ "&episodeType=segmented" \ "&imageEp=android.playplex.mtv.%s" \ "&arcEp=android.playplex.mtv.%s" \ % (mgid, self.__backgroundServiceEp, self.__region.lower(), self.__region.lower()) item = mediaitem.MediaItem(title, url) item.type = "video" item.icon = self.icon item.description = resultSet.get("description", None) item.thumb = self.parentItem.thumb item.fanart = self.parentItem.fanart item.isGeoLocked = True images = resultSet.get("images", []) if images: # mgid:file:gsp:scenic:/international/mtv.nl/playplex/dutch-ridiculousness/Dutch_Ridiculousness_Landscape.png # http://playplex.mtvnimages.com/uri/mgid:file:gsp:scenic:/international/mtv.nl/playplex/dutch-ridiculousness/Dutch_Ridiculousness_Landscape.png for image in images: if image["width"] > 500: pass # no fanart here else: item.thumb = "http://playplex.mtvnimages.com/uri/%(url)s" % image date = resultSet.get("originalAirDate", None) if not date: date = resultSet.get("originalPublishDate", None) if date: timeStamp = date["timestamp"] dateTime = DateHelper.GetDateFromPosix(timeStamp) item.SetDate(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second) return item
def CreateVideoItem(self, resultSet): """Creates a MediaItem of type 'video' using the resultSet from the regex. Arguments: resultSet : tuple (string) - the resultSet of the self.videoItemRegex Returns: A new MediaItem of type 'video' or 'audio' (despite the method's name) This method creates a new MediaItem from the Regular Expression or Json results <resultSet>. The method should be implemented by derived classes and are specific to the channel. If the item is completely processed an no further data needs to be fetched the self.complete property should be set to True. If not set to True, the self.UpdateVideoItem method is called if the item is focussed or selected for playback. """ item = chn_class.Channel.CreateVideoItem(self, resultSet) if "date" in resultSet: day, month, year = resultSet["date"].split("/") item.SetDate(year, month, day) # All of vier.be video's seem GEO locked. item.isGeoLocked = True # Set the correct url # videoId = resultSet["videoid"] # item.url = "https://api.viervijfzes.be/content/%s" % (videoId, ) if "timestamp" in resultSet: dateTime = DateHelper.GetDateFromPosix(int(resultSet["timestamp"])) item.SetDate(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second) return item
def CreateVideoItem(self, resultSet): """Creates a MediaItem of type 'video' using the resultSet from the regex. Arguments: resultSet : tuple (string) - the resultSet of the self.videoItemRegex Returns: A new MediaItem of type 'video' or 'audio' (despite the method's name) This method creates a new MediaItem from the Regular Expression or Json results <resultSet>. The method should be implemented by derived classes and are specific to the channel. If the item is completely processed an no further data needs to be fetched the self.complete property should be set to True. If not set to True, the self.UpdateVideoItem method is called if the item is focussed or selected for playback. """ Logger.Trace(resultSet) mediaLink = resultSet.get("ipadLink") title = resultSet.get("title") # it seems overkill, but not all items have a contentLink and of we set # the url to self.baseUrl it will be a duplicate item if the titles are # equal url = resultSet.get("contentLink") or mediaLink or self.baseUrl if not url.startswith("http"): url = urlparse.urljoin(self.baseUrl, url) item = mediaitem.MediaItem(title, url) item.thumb = self.noImage if mediaLink: item.AppendSingleStream(mediaLink, self.channelBitrate) # get the thumbs from multiple locations thumbUrls = resultSet.get("images", None) thumbUrl = None if thumbUrls: thumbUrl = \ thumbUrls[0].get("fullScreenLink", None) or \ thumbUrls[0].get("previewLink", None) or \ resultSet.get("imageLink", None) if thumbUrl and not thumbUrl.startswith("http"): thumbUrl = urlparse.urljoin(self.baseUrl, thumbUrl) item.thumb = self.noImage if thumbUrl: item.thumb = thumbUrl item.icon = self.icon item.type = 'video' item.description = resultSet.get("text") #if item.description: # item.description = item.description.replace("<br />", "\n") posix = resultSet.get("timestamp", None) if posix: broadcastDate = DateHelper.GetDateFromPosix(int(posix)) item.SetDate(broadcastDate.year, broadcastDate.month, broadcastDate.day, broadcastDate.hour, broadcastDate.minute, broadcastDate.second) item.complete = True return item
def CreateVideoItemJson(self, resultSet): """Creates a MediaItem of type 'video' using the resultSet from the regex. Arguments: resultSet : tuple (string) - the resultSet of the self.videoItemRegex Returns: A new MediaItem of type 'video' or 'audio' (despite the method's name) This method creates a new MediaItem from the Regular Expression or Json results <resultSet>. The method should be implemented by derived classes and are specific to the channel. If the item is completely processed an no further data needs to be fetched the self.complete property should be set to True. If not set to True, the self.UpdateVideoItem method is called if the item is focussed or selected for playback. """ Logger.Trace(resultSet) # In some cases the name, posix and description are in the root, in other cases in the # 'episode' node posix = resultSet.get('starts_at', None) image = resultSet.get('image', None) name = resultSet.get('name', None) description = resultSet.get('description', '') # the tips has an extra 'episodes' key if 'episode' in resultSet: Logger.Debug("Found subnode: episodes") # set to episode node data = resultSet['episode'] else: Logger.Warning("No subnode 'episodes' found, trying anyways") data = resultSet # look for better values posix = data.get('broadcasted_at', posix) broadcasted = DateHelper.GetDateFromPosix(posix) description = resultSet.get('description', description) videoId = data.get('whatson_id', None) # try to fetch more name data names = [] name = data.get("name", name) if name: names = [name, ] if "series" in data and "name" in data["series"]: names.insert(0, data["series"]["name"]) # Filter the duplicates title = " - ".join(set(names)) item = mediaitem.MediaItem(title, videoId) item.icon = self.icon item.type = 'video' item.complete = False item.description = description # images = data.get('stills', None) if images: # there were images in the stills item.thumb = images[-1]['url'] elif image: # no stills, or empty, check for image item.thumb = image item.SetDate(broadcasted.year, broadcasted.month, broadcasted.day, broadcasted.hour, broadcasted.minute, broadcasted.second) return item
def LogOn(self): """ Makes sure that we are logged on. """ username = self._GetSetting("username") if not username: Logger.Info("No user name for NPO, not logging in") return False # cookieValue = self._GetSetting("cookie") cookie = UriHandler.GetCookie("isAuthenticatedUser", "www.npo.nl") if cookie: expireDate = DateHelper.GetDateFromPosix(float(cookie.expires)) Logger.Info("Found existing valid NPO token (valid until: %s)", expireDate) return True v = Vault() password = v.GetChannelSetting(self.guid, "password") # get a token (why?), cookies and an xsrf token token = UriHandler.Open("https://www.npo.nl/api/token", proxy=self.proxy, noCache=True, additionalHeaders={"X-Requested-With": "XMLHttpRequest"}) jsonToken = JsonHelper(token) token = jsonToken.GetValue("token") if not token: return False xsrfToken = UriHandler.GetCookie("XSRF-TOKEN", "www.npo.nl").value xsrfToken = HtmlEntityHelper.UrlDecode(xsrfToken) data = "username=%s&password=%s" % (HtmlEntityHelper.UrlEncode(username), HtmlEntityHelper.UrlEncode(password)) UriHandler.Open("https://www.npo.nl/api/login", proxy=self.proxy, noCache=True, additionalHeaders={ "X-Requested-With": "XMLHttpRequest", "X-XSRF-TOKEN": xsrfToken }, params=data) # token = Regexer.DoRegex('name="authenticity_token"[^>]+value="([^"]+)"', tokenData)[0] # # # login: https://mijn.npo.nl/sessions POST # # utf8=%E2%9C%93&authenticity_token=<token>&email=<username>&password=<password>&remember_me=1&commit=Inloggen # postData = { # "token": HtmlEntityHelper.UrlEncode(token), # "email": HtmlEntityHelper.UrlEncode(username), # "password": HtmlEntityHelper.UrlEncode(password) # } # postData = "utf8=%%E2%%9C%%93&authenticity_token=%(token)s&email=%(email)s&" \ # "password=%(password)s&remember_me=1&commit=Inloggen" % postData # data = UriHandler.Open("https://mijn.npo.nl/sessions", noCache=True, proxy=self.proxy, # params=postData) # if not data: # Logger.Error("Error logging in: no response data") # return False # # # extract the cookie and store # authCookie = UriHandler.GetCookie("npo_portal_auth_token", ".mijn.npo.nl") # if not authCookie: # Logger.Error("Error logging in: Cookie not found.") # return False # The cookie should already be in the jar now return True
def CreateVideoItem(self, resultSet): """Creates a MediaItem of type 'video' using the resultSet from the regex. Arguments: resultSet : tuple (string) - the resultSet of the self.videoItemRegex Returns: A new MediaItem of type 'video' or 'audio' (despite the method's name) This method creates a new MediaItem from the Regular Expression or Json results <resultSet>. The method should be implemented by derived classes and are specific to the channel. If the item is completely processed an no further data needs to be fetched the self.complete property should be set to True. If not set to True, the self.UpdateVideoItem method is called if the item is focussed or selected for playback. """ Logger.Trace(resultSet) episodeKey = resultSet["episode_key"] if episodeKey: episodeData = self.episodes.get(episodeKey, None) if not episodeData: Logger.Warning("Could not find episodes data for key: %s", episodeKey) return None Logger.Debug("Found Episode Data: %s", episodeData) else: Logger.Debug("No Episode Data Found") episodeData = None title = resultSet["title"] description = None if episodeData: if title: title = "%s - %s" % (episodeData["name"], title) else: title = episodeData["name"] description = episodeData.get("synopsis", None) # tarifs have datetimes # noinspection PyStatementEffect # """ # "ddr_timeframes": [{ # "start": 1382119200, # "stop": 1382378399, # "tariff": 149 # }, # { # "start": 1382378400, # "tariff": 0 # }], # # """ tariffs = resultSet.get("ddr_timeframes") premiumItem = False if tariffs: Logger.Trace(tariffs) for tariff in tariffs: if tariff["tariff"] > 0: start = tariff.get("start", 0) end = tariff.get("stop", 2147483647) start = DateHelper.GetDateFromPosix(start) end = DateHelper.GetDateFromPosix(end) now = datetime.datetime.now() if start < now < end: premiumItem = True Logger.Debug("Found a tariff for this episode: %s - %s: %s", start, end, tariff["tariff"]) break uuid = resultSet["uuid"] url = "http://www.rtl.nl/system/s4m/xldata/ux/%s?context=rtlxl&d=pc&fmt=adaptive&version=3" % (uuid,) # The JSON urls do not yet work # url = "http://www.rtl.nl/system/s4m/vfd/version=1/d=pc/output=json/fun=abstract/uuid=%s/fmt=smooth" % (uuid,) item = mediaitem.MediaItem(title.title(), url) item.type = "video" item.isPaid = premiumItem item.description = description item.thumb = "%s%s" % (self.posterBase, uuid,) station = resultSet.get("station", None) if station: icon = self.largeIconSet.get(station.lower(), None) if icon: Logger.Trace("Setting icon to: %s", icon) item.icon = icon dateTime = resultSet.get("display_date", None) if dateTime: dateTime = DateHelper.GetDateFromPosix(int(dateTime)) item.SetDate(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second) return item
def CreateCategoryVideo(self, resultSet): """Creates a MediaItem of type 'folder' using the resultSet from the regex. Arguments: resultSet : tuple(strig) - the resultSet of the self.folderItemRegex Returns: A new MediaItem of type 'folder' This method creates a new MediaItem from the Regular Expression or Json results <resultSet>. The method should be implemented by derived classes and are specific to the channel. """ Logger.Trace(resultSet) title = resultSet["title"] if not resultSet['isAvailable']: Logger.Trace("Found unavailable video: %s", title) return None episodeData = resultSet.get("episodeNumberOrDate", None) season = None episode = None if episodeData is not None and ":" in episodeData: episodeData = episodeData.split(":", 1) season = int(episodeData[0]) episode = int(episodeData[1]) title = "%s - %02d:%02d" % (title, season, episode) url = resultSet.get("mediaUrl", None) if url is None: url = resultSet.get("programId", None) if url is None: return None url = "%s/programs/%s" % (self.baseUrl, url) item = mediaitem.MediaItem(title, url) item.description = resultSet.get("description", "") item.icon = self.icon item.type = 'video' item.fanart = self.parentItem.fanart item.HttpHeaders = self.httpHeaders if season is not None and episode is not None: item.SetSeasonInfo(season, episode) imageId = resultSet.get("imageId", None) if imageId is not None: item.thumb = "http://m.nrk.no/img?kaleidoId=%s&width=720" % (imageId, ) fanartId = resultSet.get("seriesImageId", None) if fanartId is not None: item.fanart = "http://m.nrk.no/img?kaleidoId=%s&width=1280" % (fanartId, ) dateSet = False if episodeData is not None and ". " in episodeData: episodeData = episodeData.split(" ", 2) day = episodeData[0].strip(".") monthName = episodeData[1] month = DateHelper.GetMonthFromName(monthName, "no", short=False) year = episodeData[2] item.SetDate(year, month, day) dateSet = True if "usageRights" in resultSet: item.isGeoLocked = resultSet["usageRights"].get("geoblocked", False) if not dateSet and "availableFrom" in resultSet["usageRights"]: timeStamp = int(resultSet["usageRights"]["availableFrom"]) / 1000 if 0 < timeStamp < sys.maxint: date = DateHelper.GetDateFromPosix(timeStamp) item.SetDate(date.year, date.month, date.day, date.hour, date.minute, date.second) return item
def StievieCreateEpgItems(self, epg): Logger.Trace(epg) Logger.Debug("Processing EPG for channel %s", epg["id"]) items = [] summerTime = time.localtime().tm_isdst now = datetime.datetime.now() for resultSet in epg["items"]: # if not resultSet["parentSeriesOID"]: # continue # Does not always work # videoId = resultSet["epgId"].replace("-", "_") # url = "https://vod.medialaan.io/vod/v2/videos/%s_Stievie_free" % (videoId, ) videoId = resultSet["programOID"] url = "https://vod.medialaan.io/vod/v2/videos?episodeIds=%s&limit=10&offset=0&sort=broadcastDate&sortDirection=asc" % ( videoId, ) title = resultSet["title"] if resultSet["episode"] and resultSet["season"]: title = "%s - s%02de%02d" % (title, resultSet["season"], resultSet["episode"]) if "startTime" in resultSet and resultSet["startTime"]: dateTime = resultSet["startTime"] dateValue = DateHelper.GetDateFromString( dateTime, dateFormat="%Y-%m-%dT%H:%M:%S.000Z") # Convert to Belgium posix time stamp dateValue2 = time.mktime(dateValue) + (1 + summerTime) * 60 * 60 # Conver the posix to a time stamp startTime = DateHelper.GetDateFromPosix(dateValue2) title = "%02d:%02d - %s" % (startTime.hour, startTime.minute, title) # Check for items in their black-out period if "blackout" in resultSet and resultSet["blackout"]["enabled"]: blackoutDuration = resultSet["blackout"]["duration"] blackoutStart = startTime + datetime.timedelta( seconds=blackoutDuration) if blackoutStart < now: Logger.Debug( "Found item in Black-out period: %s (started at %s)", title, blackoutStart) continue # else: # startTime = self.parentItem.metaData["airDate"] item = MediaItem(title, url) item.type = "video" item.isGeoLocked = resultSet["geoblock"] item.description = resultSet["shortDescription"] # item.SetDate(startTime.year, startTime.month, startTime.day) if "images" in resultSet and resultSet[ "images"] and "styles" in resultSet["images"][0]: images = resultSet["images"][0]["styles"] # if "1520x855" in images: # item.fanart = images["1520x855"] if "400x225" in images: item.thumb = images["400x225"] items.append(item) return items