|
|
@ -210,6 +210,7 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository |
|
|
|
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); |
|
|
|
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); |
|
|
|
Option<PlexShow> maybeExisting = await dbContext.PlexShows |
|
|
|
Option<PlexShow> maybeExisting = await dbContext.PlexShows |
|
|
|
.AsNoTracking() |
|
|
|
.AsNoTracking() |
|
|
|
|
|
|
|
.Where(ps => ps.LibraryPath.LibraryId == library.Id) |
|
|
|
.Include(i => i.ShowMetadata) |
|
|
|
.Include(i => i.ShowMetadata) |
|
|
|
.ThenInclude(sm => sm.Genres) |
|
|
|
.ThenInclude(sm => sm.Genres) |
|
|
|
.Include(i => i.ShowMetadata) |
|
|
|
.Include(i => i.ShowMetadata) |
|
|
@ -242,6 +243,7 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository |
|
|
|
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); |
|
|
|
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); |
|
|
|
Option<PlexSeason> maybeExisting = await dbContext.PlexSeasons |
|
|
|
Option<PlexSeason> maybeExisting = await dbContext.PlexSeasons |
|
|
|
.AsNoTracking() |
|
|
|
.AsNoTracking() |
|
|
|
|
|
|
|
.Where(ps => ps.LibraryPath.LibraryId == library.Id) |
|
|
|
.Include(i => i.SeasonMetadata) |
|
|
|
.Include(i => i.SeasonMetadata) |
|
|
|
.ThenInclude(sm => sm.Artwork) |
|
|
|
.ThenInclude(sm => sm.Artwork) |
|
|
|
.Include(i => i.SeasonMetadata) |
|
|
|
.Include(i => i.SeasonMetadata) |
|
|
@ -270,6 +272,7 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository |
|
|
|
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); |
|
|
|
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); |
|
|
|
Option<PlexEpisode> maybeExisting = await dbContext.PlexEpisodes |
|
|
|
Option<PlexEpisode> maybeExisting = await dbContext.PlexEpisodes |
|
|
|
.AsNoTracking() |
|
|
|
.AsNoTracking() |
|
|
|
|
|
|
|
.Where(pe => pe.LibraryPath.LibraryId == library.Id) |
|
|
|
.Include(i => i.EpisodeMetadata) |
|
|
|
.Include(i => i.EpisodeMetadata) |
|
|
|
.ThenInclude(mm => mm.Artwork) |
|
|
|
.ThenInclude(mm => mm.Artwork) |
|
|
|
.Include(i => i.EpisodeMetadata) |
|
|
|
.Include(i => i.EpisodeMetadata) |
|
|
@ -448,7 +451,7 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task<PlexShowAddTagResult> AddTag(PlexShow show, PlexTag tag) |
|
|
|
public async Task<PlexShowAddTagResult> AddTag(PlexLibrary library, PlexShow show, PlexTag tag) |
|
|
|
{ |
|
|
|
{ |
|
|
|
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); |
|
|
|
await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); |
|
|
|
|
|
|
|
|
|
|
@ -456,8 +459,10 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository |
|
|
|
@"SELECT PS.Id FROM Tag
|
|
|
|
@"SELECT PS.Id FROM Tag
|
|
|
|
INNER JOIN ShowMetadata SM on SM.Id = Tag.ShowMetadataId |
|
|
|
INNER JOIN ShowMetadata SM on SM.Id = Tag.ShowMetadataId |
|
|
|
INNER JOIN PlexShow PS on PS.Id = SM.ShowId |
|
|
|
INNER JOIN PlexShow PS on PS.Id = SM.ShowId |
|
|
|
|
|
|
|
INNER JOIN MediaItem MI on PS.Id = MI.Id |
|
|
|
|
|
|
|
INNER JOIN LibraryPath LP on MI.LibraryPathId = LP.Id AND LP.LibraryId = @LibraryId |
|
|
|
WHERE PS.Key = @Key AND Tag.Name = @Tag AND Tag.ExternalTypeId = @TagType",
|
|
|
|
WHERE PS.Key = @Key AND Tag.Name = @Tag AND Tag.ExternalTypeId = @TagType",
|
|
|
|
new { show.Key, tag.Tag, tag.TagType }); |
|
|
|
new { show.Key, tag.Tag, tag.TagType, LibraryId = library.Id }); |
|
|
|
|
|
|
|
|
|
|
|
// already exists
|
|
|
|
// already exists
|
|
|
|
if (existingShowId > 0) |
|
|
|
if (existingShowId > 0) |
|
|
@ -565,12 +570,12 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository |
|
|
|
item.LibraryPathId = library.Paths.Head().Id; |
|
|
|
item.LibraryPathId = library.Paths.Head().Id; |
|
|
|
foreach (EpisodeMetadata metadata in item.EpisodeMetadata) |
|
|
|
foreach (EpisodeMetadata metadata in item.EpisodeMetadata) |
|
|
|
{ |
|
|
|
{ |
|
|
|
metadata.Genres ??= new List<Genre>(); |
|
|
|
metadata.Genres ??= []; |
|
|
|
metadata.Tags ??= new List<Tag>(); |
|
|
|
metadata.Tags ??= []; |
|
|
|
metadata.Studios ??= new List<Studio>(); |
|
|
|
metadata.Studios ??= []; |
|
|
|
metadata.Actors ??= new List<Actor>(); |
|
|
|
metadata.Actors ??= []; |
|
|
|
metadata.Directors ??= new List<Director>(); |
|
|
|
metadata.Directors ??= []; |
|
|
|
metadata.Writers ??= new List<Writer>(); |
|
|
|
metadata.Writers ??= []; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await dbContext.PlexEpisodes.AddAsync(item); |
|
|
|
await dbContext.PlexEpisodes.AddAsync(item); |
|
|
|