diff --git a/CHANGELOG.md b/CHANGELOG.md index 68546ce1b..3432b3060 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Remove FFmpeg Profile `Transcode`, `Normalize Video` and `Normalize Audio` settings - All content will be transcoded and have audio and video normalized - The only exception to this rule is `HLS Direct` streaming mode, which directly copies video and audio streams +- Always try to connect to Plex at `http://localhost:32400` even if that address isn't advertised by the Plex API + - If Plex isn't on the localhost, all other addresses will be checked as with previous releases ## [0.4.4-alpha] - 2022-03-10 ### Fixed diff --git a/ErsatzTV.Application/Plex/Commands/SynchronizePlexMediaSourcesHandler.cs b/ErsatzTV.Application/Plex/Commands/SynchronizePlexMediaSourcesHandler.cs index 4552769ed..952e3a060 100644 --- a/ErsatzTV.Application/Plex/Commands/SynchronizePlexMediaSourcesHandler.cs +++ b/ErsatzTV.Application/Plex/Commands/SynchronizePlexMediaSourcesHandler.cs @@ -9,10 +9,11 @@ using Microsoft.Extensions.Logging; namespace ErsatzTV.Application.Plex; -public class - SynchronizePlexMediaSourcesHandler : IRequestHandler>> +public class SynchronizePlexMediaSourcesHandler : IRequestHandler>> { + private const string LocalhostUri = "http://localhost:32400"; + private readonly ChannelWriter _channel; private readonly IEntityLocker _entityLocker; private readonly ILogger _logger; @@ -72,6 +73,18 @@ public class private async Task SynchronizeServer(List allExisting, PlexMediaSource server) { + if (server.Connections.All(c => c.Uri != LocalhostUri)) + { + var localhost = new PlexConnection + { + PlexMediaSource = server, + PlexMediaSourceId = server.Id, + Uri = LocalhostUri + }; + + server.Connections.Add(localhost); + } + Option maybeExisting = allExisting.Find(s => s.ClientIdentifier == server.ClientIdentifier); @@ -98,7 +111,11 @@ public class private async Task FindConnectionToActivate(PlexMediaSource server) { - var prioritized = server.Connections.OrderBy(pc => pc.IsActive ? 0 : 1).ToList(); + var prioritized = server.Connections + .OrderByDescending(pc => pc.Uri == LocalhostUri) + .ThenByDescending(pc => pc.IsActive) + .ToList(); + foreach (PlexConnection connection in server.Connections) { connection.IsActive = false;