def log_on(self): """ Logs on to a website, using an url. First checks if the channel requires log on. If so and it's not already logged on, it should handle the log on. That part should be implemented by the specific channel. More arguments can be passed on, but must be handled by custom code. After a successful log on the self.loggedOn property is set to True and True is returned. :return: indication if the login was successful. :rtype: bool """ api_key = "3_qhEcPa5JGFROVwu5SWKqJ4mVOIkwlFNMSKwzPDAh8QZOtHqu6L4nD5Q7lk0eXOOG" # Do we still have a valid short living token (1 hour)? If so, we have an active session. short_login_cookie = UriHandler.get_cookie("X-VRT-Token", ".vrt.be") if short_login_cookie is not None: # The old X-VRT-Token expired after 1 year. We don't want that old cookie short_login_cookie_can_live_too_long = \ DateHelper.get_date_from_posix(short_login_cookie.expires) > datetime.datetime.now() + datetime.timedelta(hours=4) if not short_login_cookie_can_live_too_long: Logger.debug("Using existing VRT.be session.") return True # Do we still have a valid long living token? If so, try to extend the session. We need the # original UIDSignature value for that. The 'vrtlogin-rt' and all other related cookies # are valid for a same period (1 year). long_login_cookie = UriHandler.get_cookie("vrtlogin-rt", ".vrt.be") if long_login_cookie is not None: # if we stored a valid user signature, we can use it, together with the 'gmid' and # 'ucid' cookies to extend the session and get new token data data = UriHandler.open("https://token.vrt.be/refreshtoken", proxy=self.proxy, no_cache=True) if "vrtnutoken" in data: Logger.debug("Refreshed the VRT.be session.") return True Logger.warning("Failed to extend the VRT.be session.") username = self._get_setting("username") if not username: Logger.warning("No username configured for VRT.nu") return None v = Vault() password = v.get_channel_setting(self.guid, "password") if not password: Logger.warning("Found empty password for VRT user") # Get a 'gmid' and 'ucid' cookie by logging in. Valid for 10 years Logger.debug("Using: %s / %s", username, "*" * len(password)) url = "https://accounts.vrt.be/accounts.login" data = { "loginID": username, "password": password, "sessionExpiration": "-1", "targetEnv": "jssdk", "include": "profile,data,emails,subscriptions,preferences,", "includeUserInfo": "true", "loginMode": "standard", "lang": "nl-inf", "APIKey": api_key, "source": "showScreenSet", "sdk": "js_latest", "authMode": "cookie", "format": "json" } logon_data = UriHandler.open(url, data=data, proxy=self.proxy, no_cache=True) user_id, signature, signature_time_stamp = self.__extract_session_data( logon_data) if user_id is None or signature is None or signature_time_stamp is None: return False # We need to initialize the token retrieval which will redirect to the actual token UriHandler.open( "https://token.vrt.be/vrtnuinitlogin?provider=site&destination=https://www.vrt.be/vrtnu/", proxy=self.proxy, no_cache=True) # Now get the actual VRT tokens (X-VRT-Token....). Valid for 1 hour. So we call the actual # perform_login url which will redirect and get cookies. token_data = { "UID": user_id, "UIDSignature": signature, "signatureTimestamp": signature_time_stamp, "client_id": "vrtnu-site", "submit": "submit" } UriHandler.open("https://login.vrt.be/perform_login", proxy=self.proxy, data=token_data, no_cache=True) return True
def __init__(self, channel_info): """Initialisation of the class. Arguments: channel_info: ChannelInfo - The channel info object to base this channel on. All class variables should be instantiated here and this method should not be overridden by any derived classes. """ chn_class.Channel.__init__(self, channel_info) # ==== Actual channel setup STARTS here and should be overwritten from derived classes ===== self.mainListUri = "#programs" self.programPageSize = 100 self.videoPageSize = 100 self.swfUrl = "http://player.dplay.se/4.0.6/swf/AkamaiAdvancedFlowplayerProvider_v3.8.swf" self.subtitleKey = "subtitles_{0}_srt".format(self.language) self.channelSlugs = () self.liveUrl = None self.recentUrl = None self.primaryChannelId = None self.baseUrlApi = "disco-api.dplay.{0}".format(self.language) if self.channelCode == "tv5json": self.noImage = "tv5seimage.png" self.baseUrl = "http://www.dplay.se/api/v2/ajax" # No live stream: self.liveUrl = "https://secure.dplay.se/secure/api/v2/user/authorization/stream/132040" self.primaryChannelId = 21 elif self.channelCode == "tv9json": self.noImage = "tv9seimage.png" self.baseUrl = "http://www.dplay.se/api/v2/ajax" # No live stream: self.liveUrl = "https://secure.dplay.se/secure/api/v2/user/authorization/stream/132043" self.primaryChannelId = 26 elif self.channelCode == "tv11json": self.noImage = "dplayimage.png" self.baseUrl = "http://www.dplay.se/api/v2/ajax" # No live stream: self.liveUrl = "https://secure.dplay.se/secure/api/v2/user/authorization/stream/132039" self.primaryChannelId = 22 elif self.channelCode == "dplayse": self.noImage = "dplayimage.png" self.baseUrl = "http://www.dplay.se/api/v2/ajax" elif self.channelCode == "dplayno": self.noImage = "dplayimage.png" self.baseUrl = "http://www.dplay.no/api/v2/ajax" elif self.channelCode == "tlcnorge": self.noImage = "dplayimage.png" self.baseUrl = "http://www.dplay.no/api/v2/ajax" self.primaryChannelId = 15 elif self.channelCode == "tvnorge": self.noImage = "dplayimage.png" self.baseUrl = "http://www.dplay.no/api/v2/ajax" self.primaryChannelId = 28 elif self.channelCode == "femnorge": self.noImage = "dplayimage.png" self.baseUrl = "http://www.dplay.no/api/v2/ajax" self.primaryChannelId = 29 elif self.channelCode == "maxnorge": self.noImage = "dplayimage.png" self.baseUrl = "http://www.dplay.no/api/v2/ajax" self.primaryChannelId = 30 elif self.channelCode == "voxnorge": self.noImage = "dplayimage.png" self.baseUrl = "http://www.dplay.no/api/v2/ajax" self.primaryChannelId = 31 elif self.channelCode == "animalplanetnorge": self.noImage = "dplayimage.png" self.baseUrl = "http://www.dplay.no/api/v2/ajax" self.primaryChannelId = 35 elif self.channelCode == "discoverynorge": self.noImage = "dplayimage.png" self.baseUrl = "http://www.dplay.no/api/v2/ajax" self.primaryChannelId = 45 elif self.channelCode == "discoverysciencenorge": self.noImage = "dplayimage.png" self.baseUrl = "http://www.dplay.no/api/v2/ajax" self.primaryChannelId = 71 elif self.channelCode == "discoveryworldnorge": self.noImage = "dplayimage.png" self.baseUrl = "http://www.dplay.no/api/v2/ajax" self.primaryChannelId = 72 elif self.channelCode == "investigationdiscoverynorge": self.noImage = "dplayimage.png" self.baseUrl = "http://www.dplay.no/api/v2/ajax" self.primaryChannelId = 73 elif self.channelCode == "dplaydk": self.noImage = "dplayimage.png" self.baseUrl = "http://www.dplay.dk/api/v2/ajax" else: raise NotImplementedError("ChannelCode %s is not implemented" % (self.channelCode, )) if self.primaryChannelId: self.recentUrl = "https://{0}/content/videos?decorators=viewingHistory&" \ "include=images%2CprimaryChannel%2Cshow&" \ "filter%5BvideoType%5D=EPISODE&" \ "filter%5BprimaryChannel.id%5D={1}&" \ "page%5Bsize%5D={2}&" \ "sort=-publishStart"\ .format(self.baseUrlApi, self.primaryChannelId, self.videoPageSize) #=========================================================================================== # THIS CHANNEL DOES NOT SEEM TO WORK WITH PROXIES VERY WELL! #=========================================================================================== self._add_data_parser("#programs", preprocessor=self.load_programs) # self._add_data_parser("https://secure.dplay.\w+/secure/api/v2/user/authorization/stream/", # matchType=ParserData.MatchRegex, # updater=self.update_channel_item) # Recent self._add_data_parser( "/content/videos?decorators=viewingHistory&" "include=images%2CprimaryChannel%2Cshow&filter%5BvideoType%5D=EPISODE&" "filter%5BprimaryChannel.id%5D=", name="Recent video items", json=True, preprocessor=self.__get_images_from_meta_data, match_type=ParserData.MatchContains, parser=[ "data", ], creator=self.create_video_item_with_show_title) self._add_data_parser( "/content/videos?decorators=viewingHistory&" "include=images%2CprimaryChannel%2Cshow&filter%5BvideoType%5D=EPISODE&" "filter%5BprimaryChannel.id%5D=", name="Recent more pages", json=True, preprocessor=self.__get_images_from_meta_data, match_type=ParserData.MatchContains, parser=[ "data", ], creator=self.create_video_item) # Search self._add_data_parser(r"http.+content/shows\?.+query=.+", match_type=ParserData.MatchRegex, name="Search shows", json=True, preprocessor=self.__get_images_from_meta_data, parser=[ "data", ], creator=self.create_program_item) self._add_data_parser(r"http.+content/videos\?.+query=.+", match_type=ParserData.MatchRegex, name="Search videos", json=True, preprocessor=self.__get_images_from_meta_data, parser=[ "data", ], creator=self.create_video_item_with_show_title) self._add_data_parser(r"http.+content/videos\?.+query=.+", match_type=ParserData.MatchRegex, name="Search Pages", json=True, parser=[ "meta", ], creator=self.create_page_item) # Others self._add_data_parser("*", json=True, preprocessor=self.__get_images_from_meta_data, parser=[ "data", ], creator=self.create_video_item, updater=self.update_video_item) self._add_data_parser("*", json=True, parser=[ "meta", ], creator=self.create_page_item) #=========================================================================================== # non standard items if not UriHandler.get_cookie("st", self.baseUrlApi): guid = uuid.uuid4() guid = str(guid).replace("-", "") # https://disco-api.dplay.se/token?realm=dplayse&deviceId # =aa9ef0ed760df76d184b262d739299a75ccae7b67eec923fe3fcd861f97bcc7f&shortlived=true url = "https://{0}/token?realm=dplay{1}&deviceId={2}&shortlived=true"\ .format(self.baseUrlApi, self.language, guid) JsonHelper(UriHandler.open(url, proxy=self.proxy)) self.imageLookup = {} self.showLookup = {} #=========================================================================================== # Test cases: # Arga snickaren : Has clips # ====================================== Actual channel setup STOPS here =================== return