fix episodes from multiple plex servers (#2314)

This commit is contained in:
Jason Dove
2025-08-13 20:56:27 +00:00
committed by GitHub
parent 0841bc400b
commit f31a48c429
5 changed files with 17 additions and 10 deletions
+1
View File
@@ -57,6 +57,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Until these existing items age out, there will be warnings logged after each playout build/extension
- Fix playback of anamorphic content from Jellyfin
- This fix requires a manual deep scan of any affected Jellyfin library
- Fix bug where multiple Plex servers would mix their episodes
### Changed
- Allow multiple watermarks in playback troubleshooting
@@ -7,7 +7,7 @@ public interface IPlexTelevisionRepository : IMediaServerTelevisionRepository<Pl
PlexEpisode, PlexItemEtag>
{
Task<List<int>> RemoveAllTags(PlexLibrary library, PlexTag tag, System.Collections.Generic.HashSet<int> keep);
Task<PlexShowAddTagResult> AddTag(PlexShow show, PlexTag tag);
Task<PlexShowAddTagResult> AddTag(PlexLibrary library, PlexShow show, PlexTag tag);
Task UpdateLastNetworksScan(PlexLibrary library);
}
@@ -152,6 +152,7 @@ public class PlexMovieRepository : IPlexMovieRepository
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync();
Option<PlexMovie> maybeExisting = await dbContext.PlexMovies
.AsNoTracking()
.Where(pm => pm.LibraryPath.LibraryId == library.Id)
.Include(i => i.MovieMetadata)
.ThenInclude(mm => mm.Genres)
.Include(i => i.MovieMetadata)
@@ -210,6 +210,7 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync();
Option<PlexShow> maybeExisting = await dbContext.PlexShows
.AsNoTracking()
.Where(ps => ps.LibraryPath.LibraryId == library.Id)
.Include(i => i.ShowMetadata)
.ThenInclude(sm => sm.Genres)
.Include(i => i.ShowMetadata)
@@ -242,6 +243,7 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync();
Option<PlexSeason> maybeExisting = await dbContext.PlexSeasons
.AsNoTracking()
.Where(ps => ps.LibraryPath.LibraryId == library.Id)
.Include(i => i.SeasonMetadata)
.ThenInclude(sm => sm.Artwork)
.Include(i => i.SeasonMetadata)
@@ -270,6 +272,7 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync();
Option<PlexEpisode> maybeExisting = await dbContext.PlexEpisodes
.AsNoTracking()
.Where(pe => pe.LibraryPath.LibraryId == library.Id)
.Include(i => i.EpisodeMetadata)
.ThenInclude(mm => mm.Artwork)
.Include(i => i.EpisodeMetadata)
@@ -448,7 +451,7 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository
return result;
}
public async Task<PlexShowAddTagResult> AddTag(PlexShow show, PlexTag tag)
public async Task<PlexShowAddTagResult> AddTag(PlexLibrary library, PlexShow show, PlexTag tag)
{
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync();
@@ -456,8 +459,10 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository
@"SELECT PS.Id FROM Tag
INNER JOIN ShowMetadata SM on SM.Id = Tag.ShowMetadataId
INNER JOIN PlexShow PS on PS.Id = SM.ShowId
INNER JOIN MediaItem MI on PS.Id = MI.Id
INNER JOIN LibraryPath LP on MI.LibraryPathId = LP.Id AND LP.LibraryId = @LibraryId
WHERE PS.Key = @Key AND Tag.Name = @Tag AND Tag.ExternalTypeId = @TagType",
new { show.Key, tag.Tag, tag.TagType });
new { show.Key, tag.Tag, tag.TagType, LibraryId = library.Id });
// already exists
if (existingShowId > 0)
@@ -565,12 +570,12 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository
item.LibraryPathId = library.Paths.Head().Id;
foreach (EpisodeMetadata metadata in item.EpisodeMetadata)
{
metadata.Genres ??= new List<Genre>();
metadata.Tags ??= new List<Tag>();
metadata.Studios ??= new List<Studio>();
metadata.Actors ??= new List<Actor>();
metadata.Directors ??= new List<Director>();
metadata.Writers ??= new List<Writer>();
metadata.Genres ??= [];
metadata.Tags ??= [];
metadata.Studios ??= [];
metadata.Actors ??= [];
metadata.Directors ??= [];
metadata.Writers ??= [];
}
await dbContext.PlexEpisodes.AddAsync(item);
@@ -58,7 +58,7 @@ public class PlexNetworkScanner(
var keepIds = new System.Collections.Generic.HashSet<int>();
await foreach ((PlexShow item, int _) in items)
{
PlexShowAddTagResult result = await plexTelevisionRepository.AddTag(item, tag);
PlexShowAddTagResult result = await plexTelevisionRepository.AddTag(library, item, tag);
foreach (int existing in result.Existing)
{