Browse Source

fix episodes from multiple plex servers (#2314)

pull/2315/head
Jason Dove 2 days ago committed by GitHub
parent
commit
f31a48c429
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 2
      ErsatzTV.Core/Interfaces/Repositories/IPlexTelevisionRepository.cs
  3. 1
      ErsatzTV.Infrastructure/Data/Repositories/PlexMovieRepository.cs
  4. 21
      ErsatzTV.Infrastructure/Data/Repositories/PlexTelevisionRepository.cs
  5. 2
      ErsatzTV.Scanner/Core/Plex/PlexNetworkScanner.cs

1
CHANGELOG.md

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

2
ErsatzTV.Core/Interfaces/Repositories/IPlexTelevisionRepository.cs

@ -7,7 +7,7 @@ public interface IPlexTelevisionRepository : IMediaServerTelevisionRepository<Pl @@ -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);
}

1
ErsatzTV.Infrastructure/Data/Repositories/PlexMovieRepository.cs

@ -152,6 +152,7 @@ public class PlexMovieRepository : IPlexMovieRepository @@ -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)

21
ErsatzTV.Infrastructure/Data/Repositories/PlexTelevisionRepository.cs

@ -210,6 +210,7 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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);

2
ErsatzTV.Scanner/Core/Plex/PlexNetworkScanner.cs

@ -58,7 +58,7 @@ public class PlexNetworkScanner( @@ -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)
{

Loading…
Cancel
Save