예제 #1
0
        private async Task <IEnumerable <(string, string, string)> > GetServers(PlexToken token)
        {
            var request = new HttpRequestMessage(HttpMethod.Get, "https://plex.tv/api/resources");

            request.Headers.Add("includeHttps", "1");
            request.Headers.Add("includeRelay", "1");
            request.Headers.Add("X-Plex-Product", "PlexSSO");
            request.Headers.Add("X-Plex-Version", "Plex OAuth");
            request.Headers.Add("X-Plex-Client-Identifier", "PlexSSOv2");
            request.Headers.Add("X-Plex-Token", token.Value);
            request.Headers.Add("Accept", "application/json");

            var response = await _httpClient.SendAsync(request);

            response.EnsureSuccessStatusCode();

            var xml = await response.Content.ReadAsStringAsync();

            return(XDocument.Parse(xml)
                   .Root
                   .Elements("Device")
                   .Select(x => (
                               x.Attribute("clientIdentifier").Value,
                               x.Attribute("owned")?.Value ?? "0",
                               x.Attribute("home")?.Value ?? "0"
                               )));
        }
예제 #2
0
        public async Task <User> GetUserInfo(PlexToken token)
        {
            var request = new HttpRequestMessage(HttpMethod.Get, "https://plex.tv/users/account");

            request.Headers.Add("X-Plex-Product", "PlexSSO");
            request.Headers.Add("X-Plex-Version", "Plex OAuth");
            request.Headers.Add("X-Plex-Client-Identifier", "PlexSSOv2");
            request.Headers.Add("X-Plex-Token", token.Value);
            request.Headers.Add("Accept", "application/json");

            var response = await _httpClient.SendAsync(request);

            response.EnsureSuccessStatusCode();

            var xml = await response.Content.ReadAsStringAsync();

            var xmlDoc = XDocument.Parse(xml).Root;

            return(new User(
                       xmlDoc.Element("username")?.Value ?? string.Empty,
                       xmlDoc.Element("email")?.Value ?? string.Empty,
                       xmlDoc.Attribute("thumb")?.Value ?? string.Empty
                       ));
        }