示例#1
0
    def LogOn(self):
        tokenCookie = UriHandler.GetCookie("X-VRT-Token", ".vrt.be")
        if tokenCookie is not None:
            return True

        username = self._GetSetting("username")
        if not username:
            return None

        v = Vault()
        password = v.GetChannelSetting(self.guid, "password")
        if not password:
            Logger.Warning("Found empty password for VRT user")

        Logger.Debug("Using: %s / %s", username, "*" * len(password))
        url = "https://accounts.eu1.gigya.com/accounts.login"
        data = "loginID=%s" \
               "&password=%s" \
               "&targetEnv=jssdk" \
               "&APIKey=3_qhEcPa5JGFROVwu5SWKqJ4mVOIkwlFNMSKwzPDAh8QZOtHqu6L4nD5Q7lk0eXOOG" \
               "&includeSSOToken=true" \
               "&authMode=cookie" % \
               (HtmlEntityHelper.UrlEncode(username), HtmlEntityHelper.UrlEncode(password))

        logonData = UriHandler.Open(url, params=data, proxy=self.proxy, noCache=True)
        sig, uid, timestamp = self.__ExtractSessionData(logonData)
        if sig is None and uid is None and timestamp is None:
            return False

        url = "https://token.vrt.be/"
        tokenData = '{"uid": "%s", ' \
                    '"uidsig": "%s", ' \
                    '"ts": "%s", ' \
                    '"fn": "VRT", "ln": "NU", ' \
                    '"email": "%s"}' % (uid, sig, timestamp, username)

        headers = {"Content-Type": "application/json", "Referer": "https://www.vrt.be/vrtnu/"}
        UriHandler.Open(url, params=tokenData, proxy=self.proxy, additionalHeaders=headers)
        return True
示例#2
0
    def __init__(self, channelInfo):
        """Initialisation of the class.

        Arguments:
        channelInfo: 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, channelInfo)

        # ==== 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_se_srt"
        self.channelSlugs = ()
        self.liveUrl = None
        self.recentUrl = None
        self.primaryChannelId = None

        if self.channelCode == "tv5json":
            self.noImage = "tv5seimage.png"
            self.baseUrl = "http://www.dplay.se/api/v2/ajax"
            # 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"
            # self.liveUrl = "https://secure.dplay.se/secure/api/v2/user/authorization/stream/132043"
            self.primaryChannelId = 26

        elif self.channelCode == "tv11json":
            self.noImage = "tv11seimage.jpg"
            self.baseUrl = "http://www.dplay.se/api/v2/ajax"
            # self.liveUrl = "https://secure.dplay.se/secure/api/v2/user/authorization/stream/132039"
            self.primaryChannelId = 22

        elif self.channelCode == "dplayse":
            self.noImage = "tv11seimage.jpg"
            self.baseUrl = "http://www.dplay.se/api/v2/ajax"

        else:
            raise NotImplementedError("ChannelCode %s is not implemented" %
                                      (self.channelCode, ))

        if self.primaryChannelId:
            self.recentUrl = "https://disco-api.dplay.se/content/videos?decorators=viewingHistory&" \
                             "include=images%2CprimaryChannel%2Cshow&" \
                             "filter%5BvideoType%5D=EPISODE&" \
                             "filter%5BprimaryChannel.id%5D={0}&" \
                             "page%5Bsize%5D={1}&" \
                             "sort=-publishStart".format(self.primaryChannelId, self.videoPageSize)

        #===========================================================================================
        # THIS CHANNEL DOES NOT SEEM TO WORK WITH PROXIES VERY WELL!
        #===========================================================================================
        self._AddDataParser("#programs", preprocessor=self.LoadPrograms)
        # self._AddDataParser("https://secure.dplay.\w+/secure/api/v2/user/authorization/stream/",
        #                     matchType=ParserData.MatchRegex,
        #                     updater=self.UpdateChannelItem)

        # Recent
        self._AddDataParser(
            "https://disco-api.dplay.se/content/videos?decorators=viewingHistory&"
            "include=images%2CprimaryChannel%2Cshow&filter%5BvideoType%5D=EPISODE&"
            "filter%5BprimaryChannel.id%5D=",
            name="Recent video items",
            json=True,
            preprocessor=self.__GetImagesFromMetaData,
            parser=("data", ),
            creator=self.CreateVideoItemWithShowTitle)

        self._AddDataParser(
            "https://disco-api.dplay.se/content/videos?decorators=viewingHistory&"
            "include=images%2CprimaryChannel%2Cshow&filter%5BvideoType%5D=EPISODE&"
            "filter%5BprimaryChannel.id%5D=",
            name="Recent more pages",
            json=True,
            preprocessor=self.__GetImagesFromMetaData,
            parser=("data", ),
            creator=self.CreateVideoItem)

        # Search
        self._AddDataParser("http.+content/shows\?.+query=.+",
                            matchType=ParserData.MatchRegex,
                            name="Search shows",
                            json=True,
                            preprocessor=self.__GetImagesFromMetaData,
                            parser=("data", ),
                            creator=self.CreateProgramItem)

        self._AddDataParser("http.+content/videos\?.+query=.+",
                            matchType=ParserData.MatchRegex,
                            name="Search videos",
                            json=True,
                            preprocessor=self.__GetImagesFromMetaData,
                            parser=("data", ),
                            creator=self.CreateVideoItemWithShowTitle)

        self._AddDataParser("http.+content/videos\?.+query=.+",
                            matchType=ParserData.MatchRegex,
                            name="Search Pages",
                            json=True,
                            parser=("meta", ),
                            creator=self.CreatePageItem)

        # Others
        self._AddDataParser("*",
                            json=True,
                            preprocessor=self.__GetImagesFromMetaData,
                            parser=("data", ),
                            creator=self.CreateVideoItem,
                            updater=self.UpdateVideoItem)

        self._AddDataParser("*",
                            json=True,
                            parser=("meta", ),
                            creator=self.CreatePageItem)

        #===========================================================================================
        # non standard items
        if not UriHandler.GetCookie("st", "disco-api.dplay.se"):
            guid = uuid.uuid4()
            guid = str(guid).replace("-", "")
            # https://disco-api.dplay.se/token?realm=dplayse&deviceId
            # =aa9ef0ed760df76d184b262d739299a75ccae7b67eec923fe3fcd861f97bcc7f&shortlived=true
            url = "https://disco-api.dplay.se/token?realm=dplayse&deviceId={0}&shortlived=true".format(
                guid)
            JsonHelper(UriHandler.Open(url, proxy=self.proxy))

        self.imageLookup = {}
        self.showLookup = {}

        #===========================================================================================
        # Test cases:
        #  Arga snickaren : Has clips

        # ====================================== Actual channel setup STOPS here ===================
        return
    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