Browse Source

fix missing movie metadata (#1854)

pull/1857/head
Jason Dove 10 months ago committed by GitHub
parent
commit
55b7a35689
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      CHANGELOG.md
  2. 1
      ErsatzTV.Infrastructure/Health/Checks/EpisodeMetadataHealthCheck.cs
  3. 1
      ErsatzTV.Infrastructure/Health/Checks/MovieMetadataHealthCheck.cs
  4. 40
      ErsatzTV/Services/RunOnce/DatabaseCleanerService.cs

2
CHANGELOG.md

@ -56,6 +56,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix incorrectly removing block items that are hidden from EPG when deco filler is applied - Fix incorrectly removing block items that are hidden from EPG when deco filler is applied
- Fix deco selection when deco is scheduled until midnight - Fix deco selection when deco is scheduled until midnight
- Previously, this deco item would be ignored so watermark and filler would be missing - Previously, this deco item would be ignored so watermark and filler would be missing
- Fix movies with missing medata by generating fallback metadata
- This allows these movies to appear in the Trash where they can be deleted
### Changed ### Changed
- Remove some unnecessary API calls related to media server scanning and paging - Remove some unnecessary API calls related to media server scanning and paging

1
ErsatzTV.Infrastructure/Health/Checks/EpisodeMetadataHealthCheck.cs

@ -20,6 +20,7 @@ public class EpisodeMetadataHealthCheck : BaseHealthCheck, IEpisodeMetadataHealt
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
List<Episode> episodes = await dbContext.Episodes List<Episode> episodes = await dbContext.Episodes
.AsNoTracking()
.Filter(e => e.EpisodeMetadata.Count == 0) .Filter(e => e.EpisodeMetadata.Count == 0)
.Include(e => e.MediaVersions) .Include(e => e.MediaVersions)
.ThenInclude(mv => mv.MediaFiles) .ThenInclude(mv => mv.MediaFiles)

1
ErsatzTV.Infrastructure/Health/Checks/MovieMetadataHealthCheck.cs

@ -20,6 +20,7 @@ public class MovieMetadataHealthCheck : BaseHealthCheck, IMovieMetadataHealthChe
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
List<Movie> movies = await dbContext.Movies List<Movie> movies = await dbContext.Movies
.AsNoTracking()
.Filter(e => e.MovieMetadata.Count == 0) .Filter(e => e.MovieMetadata.Count == 0)
.Include(e => e.MediaVersions) .Include(e => e.MediaVersions)
.ThenInclude(mv => mv.MediaFiles) .ThenInclude(mv => mv.MediaFiles)

40
ErsatzTV/Services/RunOnce/DatabaseCleanerService.cs

@ -1,6 +1,10 @@
using Dapper; using Dapper;
using ErsatzTV.Core; using ErsatzTV.Core;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Metadata;
using ErsatzTV.Core.Metadata;
using ErsatzTV.Infrastructure.Data; using ErsatzTV.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace ErsatzTV.Services.RunOnce; namespace ErsatzTV.Services.RunOnce;
@ -25,6 +29,16 @@ public class DatabaseCleanerService(
using IServiceScope scope = serviceScopeFactory.CreateScope(); using IServiceScope scope = serviceScopeFactory.CreateScope();
await using TvContext dbContext = scope.ServiceProvider.GetRequiredService<TvContext>(); await using TvContext dbContext = scope.ServiceProvider.GetRequiredService<TvContext>();
await DeleteInvalidMediaItems(dbContext);
await GenerateFallbackMetadata(scope, dbContext, stoppingToken);
systemStartup.DatabaseIsCleaned();
logger.LogInformation("Done cleaning database");
}
private static async Task DeleteInvalidMediaItems(TvContext dbContext)
{
// some old version deleted items in a way that MediaItem was left over without // some old version deleted items in a way that MediaItem was left over without
// any corresponding Movie/Show/etc. // any corresponding Movie/Show/etc.
// this cleans out that old invalid data // this cleans out that old invalid data
@ -42,9 +56,31 @@ public class DatabaseCleanerService(
and Id not in (select Id from Artist) and Id not in (select Id from Artist)
and Id not in (select Id from Image) and Id not in (select Id from Image)
"""); """);
}
systemStartup.DatabaseIsCleaned(); private static async Task GenerateFallbackMetadata(
IServiceScope scope,
TvContext dbContext,
CancellationToken cancellationToken)
{
IFallbackMetadataProvider fallbackMetadataProvider =
scope.ServiceProvider.GetRequiredService<IFallbackMetadataProvider>();
logger.LogInformation("Done cleaning database"); List<Movie> movies = await dbContext.Movies
.Filter(m => m.MovieMetadata.Count == 0)
.Include(m => m.MovieMetadata)
.Include(m => m.MediaVersions)
.ThenInclude(mv => mv.MediaFiles)
.ToListAsync(cancellationToken);
foreach (Movie movie in movies)
{
MovieMetadata metadata = fallbackMetadataProvider.GetFallbackMetadata(movie);
metadata.SortTitle = SortTitle.GetSortTitle(metadata.Title);
movie.MovieMetadata ??= [];
movie.MovieMetadata.Add(metadata);
}
await dbContext.SaveChangesAsync(cancellationToken);
} }
} }

Loading…
Cancel
Save