Browse Source

update plex episode metadata during scan (#2795)

pull/2796/head
Jason Dove 6 months ago committed by GitHub
parent
commit
f96be8f99f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 33
      ErsatzTV.Infrastructure/Data/Repositories/PlexTelevisionRepository.cs

1
CHANGELOG.md

@ -44,6 +44,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -44,6 +44,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Use other video artwork in XMLTV template
- Properly update (add or remove) artwork for all local media libraries when files have changed
- Sync Plex library name changes
- Sync Plex episode title, plot, year, date added, release date, episode number changes
- Sync Jellyfin and Emby library name and type changes
- Library type (movies, shows) can only be changed when synchronization is *disabled* for the library in ETV

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

@ -357,7 +357,7 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository @@ -357,7 +357,7 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository
var result = new MediaItemScanResult<PlexEpisode>(plexEpisode) { IsAdded = false };
if (plexEpisode.Etag != item.Etag || deepScan)
{
foreach (BaseError error in await UpdateEpisodePath(dbContext, plexEpisode, item, cancellationToken))
foreach (BaseError error in await UpdateEpisode(dbContext, plexEpisode, item, cancellationToken))
{
return error;
}
@ -720,7 +720,7 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository @@ -720,7 +720,7 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository
}
}
private async Task<Option<BaseError>> UpdateEpisodePath(
private async Task<Option<BaseError>> UpdateEpisode(
TvContext dbContext,
PlexEpisode existing,
PlexEpisode incoming,
@ -739,7 +739,6 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository @@ -739,7 +739,6 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository
version.DateAdded = incomingVersion.DateAdded;
// media file
if (version.MediaFiles.Head() is PlexMediaFile file &&
incomingVersion.MediaFiles.Head() is PlexMediaFile incomingFile)
{
@ -773,6 +772,34 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository @@ -773,6 +772,34 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository
cancellationToken: cancellationToken));
}
// metadata
foreach (EpisodeMetadata metadata in existing.EpisodeMetadata.HeadOrNone())
{
foreach (EpisodeMetadata incomingMetadata in incoming.EpisodeMetadata.HeadOrNone())
{
if (metadata.Title != incomingMetadata.Title ||
metadata.Plot != incomingMetadata.Plot ||
metadata.Year != incomingMetadata.Year ||
metadata.DateAdded != incomingMetadata.DateAdded ||
metadata.ReleaseDate != incomingMetadata.ReleaseDate ||
metadata.EpisodeNumber != incomingMetadata.EpisodeNumber)
{
await dbContext.EpisodeMetadata
.Where(em => em.Id == metadata.Id)
.ExecuteUpdateAsync(
setters => setters
.SetProperty(em => em.Title, incomingMetadata.Title)
.SetProperty(em => em.SortTitle, incomingMetadata.SortTitle)
.SetProperty(em => em.Plot, incomingMetadata.Plot)
.SetProperty(em => em.Year, incomingMetadata.Year)
.SetProperty(em => em.DateAdded, incomingMetadata.DateAdded)
.SetProperty(em => em.ReleaseDate, incomingMetadata.ReleaseDate)
.SetProperty(em => em.EpisodeNumber, incomingMetadata.EpisodeNumber),
cancellationToken);
}
}
}
return Option<BaseError>.None;
}
catch (Exception)

Loading…
Cancel
Save