コード例 #1
0
        private async Task <Movie> LoadMovieAsync(string tmdbId, int timeout = 30000)
        {
            var response = await _restConnection.MakeRequestAsync <Movie, object>(Method.Get, ResponseType.Json,
                                                                                  PlexResources.TmdbBaseUrl, string.Format(PlexResources.TmdbMovie, tmdbId, _apiKey),
                                                                                  timeout : timeout);

            return(response == null ? null : response.ResponseObject);
        }
コード例 #2
0
        public async Task ConnectAsync(string username, string password)
        {
            await Task.Run(() =>
            {
                lock (_connectSynObj)
                {
                    if (ConnectionStatus != MyPlexConnectionStatus.Connected || _username != username || _password != password)
                    {
                        ConnectionStatus = MyPlexConnectionStatus.Connecting;

                        User      = null;
                        _username = username;
                        _password = password;

                        try
                        {
                            // fix for https://bugzilla.xamarin.com/show_bug.cgi?id=30869
                            // create the authentication headers manually instead of using HttpClient
                            // to fix an issue on iOS
                            var user = AsyncHelper.RunSync(() => _restConnection.MakeRequestAsync <PlexUser, string>(Method.Post,
                                                                                                                     ResponseType.Xml, PlexResources.MyPlexBaseUrl, PlexResources.MyPlexSignIn,
                                                                                                                     headers: PlexHeaders.CreatePlexRequest(userName: _username, password: _password)));

                            if (user.ResponseObject != null)
                            {
                                User             = user.ResponseObject;
                                ConnectionStatus = MyPlexConnectionStatus.Connected;
                            }
                            else
                            {
                                ConnectionStatus = MyPlexConnectionStatus.AuthorizationFailed;
                            }
                        }
                        catch (Exception ex)
                        {
                            ConnectionStatus = MyPlexConnectionStatus.AuthorizationFailed;
                            Debug.WriteLine("Exception connecting to MyPlex" + ex);
                            User = null;
                        }
                    }

                    AsyncHelper.RunSync(RefreshContainerAsync);
                }
            });
        }
コード例 #3
0
        private async Task <RestResponse <T> > MakePlexRequestAsync <T, TData>(string uri, string resource)
            where T : class, new() where TData : class
        {
            if (_needsAuth)
            {
                return(await _restConnection.MakeRequestAsync <T, TData>(Method.Get,
                                                                         ResponseType.Xml, uri, resource, headers : PlexHeaders.CreatePlexRequest(User)));
            }

            var retVal = await _restConnection.MakeRequestAsync <T, TData>(Method.Get,
                                                                           ResponseType.Xml, uri, resource, headers : PlexHeaders.CreatePlexRequest());

            if ((retVal == null || retVal.ResponseObject == null) && User != null)
            {
                _needsAuth = true;
                retVal     = await _restConnection.MakeRequestAsync <T, TData>(Method.Get,
                                                                               ResponseType.Xml, uri, resource, headers : PlexHeaders.CreatePlexRequest(User));
            }

            return(retVal);
        }
コード例 #4
0
        public async Task <Series> GetSeriesAsync(string tvdbId)
        {
            var data = await _restConnection.MakeRequestAsync <Data, object>(Method.Get, ResponseType.Xml,
                                                                             PlexResources.TheTvdbBaseUrl, string.Format(PlexResources.TheTvdbSeries, tvdbId),
                                                                             timeout : 30000);

            if (data == null || data.ResponseObject == null)
            {
                return(null);
            }

            var series = data.ResponseObject.Series;

            series.Episodes = data.ResponseObject.Episodes;

            if (!await GetActorsForSeriesAsync(series))
            {
                return(null);
            }

            return(series);
        }