示例#1
0
        private PlexKey GetPlexKey()
        {
            if (_key != null)
            {
                if (_key.ExpiresAt > DateTime.Now)
                {
                    return(_key);
                }

                if (_key.ExpiresAt <= DateTime.Now)
                {
                    _key = null;
                }
            }

            var(_, content) = RequestAsync("https://plex.tv/api/v2/pins?strong=true", HttpMethod.Post).Result;
            _key            = JsonConvert.DeserializeObject <PlexKey>(content);
            return(_key);
        }
示例#2
0
        private string GetPlexToken()
        {
            if (!string.IsNullOrEmpty(_user?.PlexToken))
            {
                return(_user.PlexToken);
            }

            if (_key == null)
            {
                GetPlexKey();
            }

            if (_key.AuthToken != null)
            {
                return(_key?.AuthToken);
            }

            var(_, content) = RequestAsync($"https://plex.tv/api/v2/pins/{_key.Id}", HttpMethod.Get).Result;
            try
            {
                _key = JsonConvert.DeserializeObject <PlexKey>(content);
            }
            catch
            {
                Logger.Trace($"Unable to deserialize Plex Key from server. Response was \n{content}");
            }

            if (_key == null)
            {
                return(null);
            }
            _user.PlexToken = _key.AuthToken;

            new ShokoServiceImplementation().SaveUser(_user);
            return(_user.PlexToken);
        }