Browse Source

properly update plex part keys (#1666)

pull/1667/head
Jason Dove 1 year ago committed by GitHub
parent
commit
b461631be9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      CHANGELOG.md
  2. 19
      ErsatzTV.Infrastructure/Data/Repositories/PlexMovieRepository.cs
  3. 47
      ErsatzTV.Infrastructure/Data/Repositories/PlexTelevisionRepository.cs
  4. 7
      ErsatzTV.Infrastructure/Plex/PlexEtag.cs

3
CHANGELOG.md

@ -18,6 +18,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -18,6 +18,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- This will apply whenever a deco template is missing, or when a deco template item cannot be found for the current time
- Effectively, this sets a default watermark for the entire playout
### Fixed
- Fix some cases of 404s from Plex when files were replaced and scanning the library from ETV didn't help
## [0.8.6-beta] - 2024-04-03
### Added
- Add `show_studio` and `show_content_rating` to search index for seasons and episodes

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

@ -253,12 +253,19 @@ public class PlexMovieRepository : IPlexMovieRepository @@ -253,12 +253,19 @@ public class PlexMovieRepository : IPlexMovieRepository
new { version.Name, version.DateAdded, version.Id });
// media file
MediaFile file = version.MediaFiles.Head();
MediaFile incomingFile = incomingVersion.MediaFiles.Head();
file.Path = incomingFile.Path;
if (version.MediaFiles.Head() is PlexMediaFile file &&
incomingVersion.MediaFiles.Head() is PlexMediaFile incomingFile)
{
file.Path = incomingFile.Path;
file.Key = incomingFile.Key;
await dbContext.Connection.ExecuteAsync(
@"UPDATE MediaFile SET Path = @Path WHERE Id = @Id",
new { file.Path, file.Id });
await dbContext.Connection.ExecuteAsync(
@"UPDATE MediaFile SET Path = @Path WHERE Id = @Id",
new { file.Path, file.Id });
await dbContext.Connection.ExecuteAsync(
@"UPDATE PlexMediaFile SET Key = @Key WHERE Id = @Id",
new { file.Key, file.Id });
}
}
}

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

@ -300,9 +300,7 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository @@ -300,9 +300,7 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository
foreach (PlexEpisode plexEpisode in maybeExisting)
{
var result = new MediaItemScanResult<PlexEpisode>(plexEpisode) { IsAdded = false };
// deepScan isn't needed here since we create our own plex etags
if (plexEpisode.Etag != item.Etag)
if (plexEpisode.Etag != item.Etag || deepScan)
{
foreach (BaseError error in await UpdateEpisodePath(dbContext, plexEpisode, item))
{
@ -537,24 +535,33 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository @@ -537,24 +535,33 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository
version.DateAdded = incomingVersion.DateAdded;
// media file
MediaFile file = version.MediaFiles.Head();
MediaFile incomingFile = incomingVersion.MediaFiles.Head();
_logger.LogDebug(
"Updating plex episode (key {Key}) path from {Existing} to {Incoming}",
existing.Key,
file.Path,
incomingFile.Path);
file.Path = incomingFile.Path;
await dbContext.Connection.ExecuteAsync(
@"UPDATE MediaVersion SET Name = @Name, DateAdded = @DateAdded WHERE Id = @Id",
new { version.Name, version.DateAdded, version.Id });
await dbContext.Connection.ExecuteAsync(
@"UPDATE MediaFile SET Path = @Path WHERE Id = @Id",
new { file.Path, file.Id });
if (version.MediaFiles.Head() is PlexMediaFile file &&
incomingVersion.MediaFiles.Head() is PlexMediaFile incomingFile)
{
_logger.LogDebug(
"Updating plex episode (key {Key}) file key from {FK1} => {FK2}, path from {Existing} to {Incoming}",
existing.Key,
file.Key,
incomingFile.Key,
file.Path,
incomingFile.Path);
file.Path = incomingFile.Path;
file.Key = incomingFile.Key;
await dbContext.Connection.ExecuteAsync(
@"UPDATE MediaVersion SET Name = @Name, DateAdded = @DateAdded WHERE Id = @Id",
new { version.Name, version.DateAdded, version.Id });
await dbContext.Connection.ExecuteAsync(
@"UPDATE MediaFile SET Path = @Path WHERE Id = @Id",
new { file.Path, file.Id });
await dbContext.Connection.ExecuteAsync(
@"UPDATE PlexMediaFile SET Key = @Key WHERE Id = @Id",
new { file.Key, file.Id });
}
return Option<BaseError>.None;
}

7
ErsatzTV.Infrastructure/Plex/PlexEtag.cs

@ -36,6 +36,9 @@ public class PlexEtag @@ -36,6 +36,9 @@ public class PlexEtag
// media part id
foreach (PlexPartResponse part in media.Part)
{
bw.Write((byte)FieldKey.Key);
bw.Write(part.Key);
bw.Write((byte)FieldKey.PartId);
bw.Write(part.Id);
@ -214,6 +217,9 @@ public class PlexEtag @@ -214,6 +217,9 @@ public class PlexEtag
// media part id
foreach (PlexXmlPartResponse part in media.Part)
{
bw.Write((byte)FieldKey.Key);
bw.Write(part.Key);
bw.Write((byte)FieldKey.PartId);
bw.Write(part.Id);
@ -326,6 +332,7 @@ public class PlexEtag @@ -326,6 +332,7 @@ public class PlexEtag
Art = 21,
File = 30,
Key = 31,
ChildCount = 40,
Smart = 41, // smart collection bool

Loading…
Cancel
Save