Browse Source

fix plex server identification (#833)

pull/834/head
Jason Dove 4 years ago committed by GitHub
parent
commit
9acfd2cd06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 4
      ErsatzTV.Infrastructure/Plex/IPlexServerApi.cs
  3. 7
      ErsatzTV.Infrastructure/Plex/Models/PlexMediaContainerResponse.cs
  4. 22
      ErsatzTV.Infrastructure/Plex/PlexServerApiClient.cs

1
CHANGELOG.md

@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -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

4
ErsatzTV.Infrastructure/Plex/IPlexServerApi.cs

@ -6,8 +6,8 @@ namespace ErsatzTV.Infrastructure.Plex; @@ -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);

7
ErsatzTV.Infrastructure/Plex/Models/PlexMediaContainerResponse.cs

@ -24,6 +24,13 @@ public class PlexXmlMediaContainerStatsResponse @@ -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
{

22
ErsatzTV.Infrastructure/Plex/PlexServerApiClient.cs

@ -30,15 +30,9 @@ public class PlexServerApiClient : IPlexServerApiClient @@ -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 @@ -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(

Loading…
Cancel
Save