def checkLogin(self):
            if self.finished:
                return not self.expired

            url = Url.append(constants.URL_EMBY_CONNECT_BASE, constants.URL_EMBY_CONNECT_PIN)
            url = Url.addOptions(url, {
                constants.URL_QUERY_DEVICE_ID: self.deviceId,
                constants.URL_QUERY_PIN: self.pin,
            })

            resultObj = Request.GetAsJson(url)
            if not resultObj or \
               constants.PROPERTY_EMBY_CONNECT_PIN_IS_CONFIRMED not in resultObj or \
               constants.PROPERTY_EMBY_CONNECT_PIN_IS_EXPIRED not in resultObj:
                log('failed to check status of PIN {} at {}: {}'.format(self.pin, url, resultObj), xbmc.LOGWARNING)
                self.finished = True
                self.expired = True
                return False

            self.finished = resultObj.get(constants.PROPERTY_EMBY_CONNECT_PIN_IS_CONFIRMED)
            self.expired = resultObj.get(constants.PROPERTY_EMBY_CONNECT_PIN_IS_EXPIRED)
            if self.expired:
                self.finished = True

            return self.finished
    def Exchange(baseUrl, accessKey, userId, deviceId=None):
        if not baseUrl:
            raise ValueError('invalid baseUrl')
        if not accessKey:
            raise ValueError('invalid accessKey')
        if not userId:
            raise ValueError('invalid userId')

        exchangeUrl = server.Server.BuildConnectExchangeUrl(baseUrl, userId)
        headers = Request.PrepareApiCallHeaders(deviceId=deviceId)
        headers.update({
            constants.EMBY_CONNECT_TOKEN_HEADER: accessKey,
        })

        resultObj = Request.GetAsJson(exchangeUrl, headers=headers)
        if not resultObj or \
           constants.PROPERTY_EMBY_CONNECT_EXCHANGE_LOCAL_USER_ID not in resultObj or \
           constants.PROPERTY_EMBY_CONNECT_EXCHANGE_ACCESS_TOKEN not in resultObj:
            log('invalid response from {}: {}'.format(exchangeUrl, resultObj))
            return None

        return EmbyConnect.AuthenticationResult(
            accessToken=resultObj.get(constants.PROPERTY_EMBY_CONNECT_EXCHANGE_ACCESS_TOKEN),
            userId=resultObj.get(constants.PROPERTY_EMBY_CONNECT_EXCHANGE_LOCAL_USER_ID)
        )
示例#3
0
    def GetPublicUsers(baseUrl, deviceId=None):
        users = []

        usersUrl = Url.append(baseUrl, constants.EMBY_PROTOCOL,
                              constants.URL_USERS, constants.URL_USERS_PUBLIC)
        headers = Request.PrepareApiCallHeaders(deviceId=deviceId)
        resultObj = Request.GetAsJson(usersUrl, headers=headers)
        if not resultObj:
            return users

        for userObj in resultObj:
            # make sure the 'Name' and 'Id' properties are available
            if not constants.PROPERTY_USER_NAME in userObj or not constants.PROPERTY_USER_ID in userObj:
                continue

            # make sure the name and id properties are valid
            user = User(userObj[constants.PROPERTY_USER_NAME],
                        userObj[constants.PROPERTY_USER_ID])
            if not user.name or not user.id:
                continue

            # check if the user is disabled
            if constants.PROPERTY_USER_POLICY in userObj and \
               constants.PROPERTY_USER_IS_DISABLED in userObj[constants.PROPERTY_USER_POLICY] and \
               userObj[constants.PROPERTY_USER_POLICY][constants.PROPERTY_USER_IS_DISABLED]:
                continue

            users.append(user)

        return users
示例#4
0
    def GetServers(accessToken, userId):
        if not accessToken:
            raise ValueError('invalid accessToken')
        if not userId:
            raise ValueError('invalid userId')

        url = Url.append(constants.URL_EMBY_CONNECT_BASE,
                         constants.URL_EMBY_CONNECT_SERVERS)
        url = Url.addOptions(url, {
            constants.URL_QUERY_USER_ID: userId,
        })
        headers = EmbyConnect._getApplicationHeader()
        headers.update({
            constants.EMBY_CONNECT_USER_TOKEN_HEADER: accessToken,
        })

        resultObj = Request.GetAsJson(url, headers=headers)
        if not resultObj:
            log('invalid response from {}: {}'.format(url, resultObj))
            return None

        servers = []
        for server in resultObj:
            id = server.get(constants.PROPERTY_EMBY_CONNECT_SERVER_ID, None)
            systemId = server.get(
                constants.PROPERTY_EMBY_CONNECT_SERVER_SYSTEM_ID, None)
            accessKey = server.get(
                constants.PROPERTY_EMBY_CONNECT_SERVER_ACCESS_KEY, None)
            name = server.get(constants.PROPERTY_EMBY_CONNECT_SERVER_NAME,
                              None)
            remoteUrl = server.get(
                constants.PROPERTY_EMBY_CONNECT_SERVER_REMOTE_URL, None)
            localUrl = server.get(
                constants.PROPERTY_EMBY_CONNECT_SERVER_LOCAL_URL, None)

            if None in (id, accessKey, name, remoteUrl, localUrl):
                log('invalid Emby server received from {}: {}'.format(
                    url, server))
                continue

            servers.append(
                EmbyConnect.Server(id=id,
                                   systemId=systemId,
                                   accessKey=accessKey,
                                   name=name,
                                   remoteUrl=remoteUrl,
                                   localUrl=localUrl))

        return servers
示例#5
0
 def ApiGet(self, url):
     return self._request(url, lambda url, headers: Request.GetAsJson(url, headers=headers))
示例#6
0
    def GetInfo(baseUrl):
        publicInfoUrl = server.Server.BuildPublicInfoUrl(baseUrl)
        headers = Request.PrepareApiCallHeaders()
        resultObj = Request.GetAsJson(publicInfoUrl, headers=headers)

        return Server.Info.fromPublicInfo(resultObj)