Browse Source

properly sync updated file paths from plex (#976)

pull/977/head
Jason Dove 4 years ago committed by GitHub
parent
commit
be1125a9ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      ErsatzTV.Infrastructure/Data/Repositories/EmbyTelevisionRepository.cs
  3. 35
      ErsatzTV.Infrastructure/Data/Repositories/PlexMovieRepository.cs
  4. 35
      ErsatzTV.Infrastructure/Data/Repositories/PlexTelevisionRepository.cs
  5. 4306
      ErsatzTV.Infrastructure/Migrations/20221001013541_Reset_PlexLibraryScan.Designer.cs
  6. 19
      ErsatzTV.Infrastructure/Migrations/20221001013541_Reset_PlexLibraryScan.cs
  7. 12
      ErsatzTV.Infrastructure/Plex/PlexEtag.cs

1
CHANGELOG.md

@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Attempt to position watermarks within content (not over added black padding)
- Fix search results for `Other Videos` when NFO metadata is used
- Properly synchronize tags from Emby movies and shows
- Properly sync updated file paths from Plex
### Added
- Add `QSV Device` option to ffmpeg profile on linux

2
ErsatzTV.Infrastructure/Data/Repositories/EmbyTelevisionRepository.cs

@ -576,7 +576,7 @@ public class EmbyTelevisionRepository : IEmbyTelevisionRepository @@ -576,7 +576,7 @@ public class EmbyTelevisionRepository : IEmbyTelevisionRepository
await dbContext.SaveChangesAsync();
}
public async Task UpdateEpisode(TvContext dbContext, EmbyEpisode existing, EmbyEpisode incoming)
private static async Task UpdateEpisode(TvContext dbContext, EmbyEpisode existing, EmbyEpisode incoming)
{
// library path is used for search indexing later
incoming.LibraryPath = existing.LibraryPath;

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

@ -125,7 +125,14 @@ public class PlexMovieRepository : IPlexMovieRepository @@ -125,7 +125,14 @@ public class PlexMovieRepository : IPlexMovieRepository
foreach (PlexMovie plexMovie in maybeExisting)
{
return new MediaItemScanResult<PlexMovie>(plexMovie) { IsAdded = false };
var result = new MediaItemScanResult<PlexMovie>(plexMovie) { IsAdded = false };
if (plexMovie.Etag != item.Etag)
{
await UpdateMoviePath(dbContext, plexMovie, item);
result.IsUpdated = true;
}
return result;
}
return await AddMovie(dbContext, library, item);
@ -167,4 +174,30 @@ public class PlexMovieRepository : IPlexMovieRepository @@ -167,4 +174,30 @@ public class PlexMovieRepository : IPlexMovieRepository
return BaseError.New(ex.ToString());
}
}
private static async Task UpdateMoviePath(TvContext dbContext, PlexMovie existing, PlexMovie incoming)
{
// library path is used for search indexing later
incoming.LibraryPath = existing.LibraryPath;
incoming.Id = existing.Id;
// version
MediaVersion version = existing.MediaVersions.Head();
MediaVersion incomingVersion = incoming.MediaVersions.Head();
version.Name = incomingVersion.Name;
version.DateAdded = incomingVersion.DateAdded;
await dbContext.Connection.ExecuteAsync(
@"UPDATE MediaVersion SET Name = @Name, DateAdded = @DateAdded WHERE Id = @Id",
new { version.Name, version.DateAdded, version.Id });
// media file
MediaFile file = version.MediaFiles.Head();
MediaFile incomingFile = incomingVersion.MediaFiles.Head();
file.Path = incomingFile.Path;
await dbContext.Connection.ExecuteAsync(
@"UPDATE MediaFile SET Path = @Path WHERE Id = @Id",
new { file.Path, file.Id });
}
}

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

@ -218,7 +218,14 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository @@ -218,7 +218,14 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository
foreach (PlexEpisode plexEpisode in maybeExisting)
{
return new MediaItemScanResult<PlexEpisode>(plexEpisode) { IsAdded = false };
var result = new MediaItemScanResult<PlexEpisode>(plexEpisode) { IsAdded = false };
if (plexEpisode.Etag != item.Etag)
{
await UpdateEpisodePath(dbContext, plexEpisode, item);
result.IsUpdated = true;
}
return result;
}
return await AddEpisode(dbContext, library, item);
@ -424,4 +431,30 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository @@ -424,4 +431,30 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository
return BaseError.New(ex.Message);
}
}
private static async Task UpdateEpisodePath(TvContext dbContext, PlexEpisode existing, PlexEpisode incoming)
{
// library path is used for search indexing later
incoming.LibraryPath = existing.LibraryPath;
incoming.Id = existing.Id;
// version
MediaVersion version = existing.MediaVersions.Head();
MediaVersion incomingVersion = incoming.MediaVersions.Head();
version.Name = incomingVersion.Name;
version.DateAdded = incomingVersion.DateAdded;
await dbContext.Connection.ExecuteAsync(
@"UPDATE MediaVersion SET Name = @Name, DateAdded = @DateAdded WHERE Id = @Id",
new { version.Name, version.DateAdded, version.Id });
// media file
MediaFile file = version.MediaFiles.Head();
MediaFile incomingFile = incomingVersion.MediaFiles.Head();
file.Path = incomingFile.Path;
await dbContext.Connection.ExecuteAsync(
@"UPDATE MediaFile SET Path = @Path WHERE Id = @Id",
new { file.Path, file.Id });
}
}

4306
ErsatzTV.Infrastructure/Migrations/20221001013541_Reset_PlexLibraryScan.Designer.cs generated

File diff suppressed because it is too large Load Diff

19
ErsatzTV.Infrastructure/Migrations/20221001013541_Reset_PlexLibraryScan.cs

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ErsatzTV.Infrastructure.Migrations
{
public partial class Reset_PlexLibraryScan : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(
@"UPDATE Library SET LastScan = '0001-01-01 00:00:00' WHERE Id IN (SELECT Id FROM PlexLibrary)");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

12
ErsatzTV.Infrastructure/Plex/PlexEtag.cs

@ -36,6 +36,9 @@ public class PlexEtag @@ -36,6 +36,9 @@ public class PlexEtag
{
bw.Write((byte)FieldKey.PartId);
bw.Write(part.Id);
bw.Write((byte)FieldKey.File);
bw.Write(part.File);
}
}
@ -197,7 +200,10 @@ public class PlexEtag @@ -197,7 +200,10 @@ public class PlexEtag
bw.Write((byte)FieldKey.PartId);
bw.Write(part.Id);
// media part id
bw.Write((byte)FieldKey.File);
bw.Write(part.File);
// stream id
foreach (PlexStreamResponse stream in part.Stream)
{
bw.Write((byte)FieldKey.StreamId);
@ -260,6 +266,8 @@ public class PlexEtag @@ -260,6 +266,8 @@ public class PlexEtag
LabelTag = 15,
Thumb = 20,
Art = 21
Art = 21,
File = 30
}
}

Loading…
Cancel
Save