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/).
## [Unreleased] ## [Unreleased]
### Fixed ### Fixed
- Fix Jellyfin show library paging - Fix Jellyfin show library paging
- Properly locate and identify multiple Plex servers
### Added ### Added
- Add basic music video credits subtitle generation - Add basic music video credits subtitle generation

4
ErsatzTV.Infrastructure/Plex/IPlexServerApi.cs

@ -6,8 +6,8 @@ namespace ErsatzTV.Infrastructure.Plex;
public interface IPlexServerApi public interface IPlexServerApi
{ {
[Get("/")] [Get("/")]
[Headers("Accept: application/json")] [Headers("Accept: text/xml")]
public Task Ping( public Task<PlexXmlMediaContainerPingResponse> Ping(
[Query] [AliasAs("X-Plex-Token")] [Query] [AliasAs("X-Plex-Token")]
string token); string token);

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

@ -24,6 +24,13 @@ public class PlexXmlMediaContainerStatsResponse
public int TotalSize { get; set; } public int TotalSize { get; set; }
} }
[XmlRoot("MediaContainer", Namespace = null)]
public class PlexXmlMediaContainerPingResponse
{
[XmlAttribute("machineIdentifier")]
public string MachineIdentifier { get; set; }
}
[XmlRoot("MediaContainer", Namespace = null)] [XmlRoot("MediaContainer", Namespace = null)]
public class PlexXmlVideoMetadataResponseContainer public class PlexXmlVideoMetadataResponseContainer
{ {

22
ErsatzTV.Infrastructure/Plex/PlexServerApiClient.cs

@ -30,15 +30,9 @@ public class PlexServerApiClient : IPlexServerApiClient
{ {
try try
{ {
IPlexServerApi service = RestService.For<IPlexServerApi>( IPlexServerApi service = XmlServiceFor(connection.Uri, TimeSpan.FromSeconds(5));
new HttpClient PlexXmlMediaContainerPingResponse pingResult = await service.Ping(token.AuthToken);
{ return token.ClientIdentifier == pingResult.MachineIdentifier;
BaseAddress = new Uri(connection.Uri),
Timeout = TimeSpan.FromSeconds(5)
});
await service.Ping(token.AuthToken);
return true;
} }
catch (Exception) catch (Exception)
{ {
@ -362,14 +356,20 @@ public class PlexServerApiClient : IPlexServerApiClient
return result.Values.ToList(); return result.Values.ToList();
} }
private static IPlexServerApi XmlServiceFor(string uri) private static IPlexServerApi XmlServiceFor(string uri, TimeSpan? timeout = null)
{ {
var overrides = new XmlAttributeOverrides(); var overrides = new XmlAttributeOverrides();
var attrs = new XmlAttributes { XmlIgnore = true }; var attrs = new XmlAttributes { XmlIgnore = true };
overrides.Add(typeof(PlexMetadataResponse), "Media", attrs); overrides.Add(typeof(PlexMetadataResponse), "Media", attrs);
TimeSpan httpClientTimeout = timeout ?? TimeSpan.FromSeconds(30);
return RestService.For<IPlexServerApi>( return RestService.For<IPlexServerApi>(
uri, new HttpClient
{
BaseAddress = new Uri(uri),
Timeout = httpClientTimeout
},
new RefitSettings new RefitSettings
{ {
ContentSerializer = new XmlContentSerializer( ContentSerializer = new XmlContentSerializer(

Loading…
Cancel
Save