properly sync updated file paths from plex (#976)

This commit is contained in:
Jason Dove
2022-09-30 20:41:32 -05:00
committed by GitHub
parent d21c985a77
commit be1125a9ab
7 changed files with 4405 additions and 5 deletions
+1
View File
@@ -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
@@ -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;
@@ -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
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 });
}
}
@@ -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
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 });
}
}
File diff suppressed because it is too large Load Diff
@@ -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)
{
}
}
}
+10 -2
View File
@@ -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
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
LabelTag = 15,
Thumb = 20,
Art = 21
Art = 21,
File = 30
}
}