fix plex server identification (#833)

This commit is contained in:
Jason Dove
2022-06-03 05:53:41 -05:00
committed by GitHub
parent 3242e7ebb8
commit 9acfd2cd06
4 changed files with 21 additions and 13 deletions
+1
View File
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]
### Fixed
- Fix Jellyfin show library paging
- Properly locate and identify multiple Plex servers
### Added
- Add basic music video credits subtitle generation
@@ -6,8 +6,8 @@ namespace ErsatzTV.Infrastructure.Plex;
public interface IPlexServerApi
{
[Get("/")]
[Headers("Accept: application/json")]
public Task Ping(
[Headers("Accept: text/xml")]
public Task<PlexXmlMediaContainerPingResponse> Ping(
[Query] [AliasAs("X-Plex-Token")]
string token);
@@ -24,6 +24,13 @@ public class PlexXmlMediaContainerStatsResponse
public int TotalSize { get; set; }
}
[XmlRoot("MediaContainer", Namespace = null)]
public class PlexXmlMediaContainerPingResponse
{
[XmlAttribute("machineIdentifier")]
public string MachineIdentifier { get; set; }
}
[XmlRoot("MediaContainer", Namespace = null)]
public class PlexXmlVideoMetadataResponseContainer
{
@@ -30,15 +30,9 @@ public class PlexServerApiClient : IPlexServerApiClient
{
try
{
IPlexServerApi service = RestService.For<IPlexServerApi>(
new HttpClient
{
BaseAddress = new Uri(connection.Uri),
Timeout = TimeSpan.FromSeconds(5)
});
await service.Ping(token.AuthToken);
return true;
IPlexServerApi service = XmlServiceFor(connection.Uri, TimeSpan.FromSeconds(5));
PlexXmlMediaContainerPingResponse pingResult = await service.Ping(token.AuthToken);
return token.ClientIdentifier == pingResult.MachineIdentifier;
}
catch (Exception)
{
@@ -362,14 +356,20 @@ public class PlexServerApiClient : IPlexServerApiClient
return result.Values.ToList();
}
private static IPlexServerApi XmlServiceFor(string uri)
private static IPlexServerApi XmlServiceFor(string uri, TimeSpan? timeout = null)
{
var overrides = new XmlAttributeOverrides();
var attrs = new XmlAttributes { XmlIgnore = true };
overrides.Add(typeof(PlexMetadataResponse), "Media", attrs);
TimeSpan httpClientTimeout = timeout ?? TimeSpan.FromSeconds(30);
return RestService.For<IPlexServerApi>(
uri,
new HttpClient
{
BaseAddress = new Uri(uri),
Timeout = httpClientTimeout
},
new RefitSettings
{
ContentSerializer = new XmlContentSerializer(