@@ -16,7 +16,7 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Serilog.Formatting.Compact.Reader" Version="2.0.0" />
|
||||
<PackageReference Include="Winista.MimeDetect" Version="1.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<PackageReference Include="Moq" Version="4.18.4" />
|
||||
<PackageReference Include="NUnit" Version="3.13.3" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.6.0">
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.6.1">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
|
||||
@@ -185,7 +185,7 @@ public class EmbyMovieRepository : IEmbyMovieRepository
|
||||
{
|
||||
try
|
||||
{
|
||||
if (await MediaItemRepository.MediaFileAlreadyExists(movie, dbContext, _logger))
|
||||
if (await MediaItemRepository.MediaFileAlreadyExists(movie, library.Paths.Head().Id, dbContext, _logger))
|
||||
{
|
||||
return new MediaFileAlreadyExists();
|
||||
}
|
||||
|
||||
@@ -809,7 +809,7 @@ public class EmbyTelevisionRepository : IEmbyTelevisionRepository
|
||||
{
|
||||
try
|
||||
{
|
||||
if (await MediaItemRepository.MediaFileAlreadyExists(episode, dbContext, _logger))
|
||||
if (await MediaItemRepository.MediaFileAlreadyExists(episode, library.Paths.Head().Id, dbContext, _logger))
|
||||
{
|
||||
return new MediaFileAlreadyExists();
|
||||
}
|
||||
|
||||
@@ -367,7 +367,7 @@ public class JellyfinMovieRepository : IJellyfinMovieRepository
|
||||
{
|
||||
try
|
||||
{
|
||||
if (await MediaItemRepository.MediaFileAlreadyExists(movie, dbContext, _logger))
|
||||
if (await MediaItemRepository.MediaFileAlreadyExists(movie, library.Paths.Head().Id, dbContext, _logger))
|
||||
{
|
||||
return new MediaFileAlreadyExists();
|
||||
}
|
||||
|
||||
@@ -812,7 +812,7 @@ public class JellyfinTelevisionRepository : IJellyfinTelevisionRepository
|
||||
{
|
||||
try
|
||||
{
|
||||
if (await MediaItemRepository.MediaFileAlreadyExists(episode, dbContext, _logger))
|
||||
if (await MediaItemRepository.MediaFileAlreadyExists(episode, library.Paths.Head().Id, dbContext, _logger))
|
||||
{
|
||||
return new MediaFileAlreadyExists();
|
||||
}
|
||||
|
||||
@@ -124,13 +124,13 @@ public class MediaItemRepository : IMediaItemRepository
|
||||
return Unit.Default;
|
||||
}
|
||||
|
||||
public static async Task<bool> MediaFileAlreadyExists(MediaItem incoming, TvContext dbContext, ILogger logger)
|
||||
public static async Task<bool> MediaFileAlreadyExists(MediaItem incoming, int libraryPathId, TvContext dbContext, ILogger logger)
|
||||
{
|
||||
string path = incoming.GetHeadVersion().MediaFiles.Head().Path;
|
||||
return await MediaFileAlreadyExists(path, dbContext, logger);
|
||||
return await MediaFileAlreadyExists(path, libraryPathId, dbContext, logger);
|
||||
}
|
||||
|
||||
public static async Task<bool> MediaFileAlreadyExists(string path, TvContext dbContext, ILogger logger)
|
||||
public static async Task<bool> MediaFileAlreadyExists(string path, int libraryPathId, TvContext dbContext, ILogger logger)
|
||||
{
|
||||
Option<int> maybeMediaItemId = await dbContext.Connection
|
||||
.QuerySingleOrDefaultAsync<int?>(
|
||||
@@ -151,21 +151,40 @@ public class MediaItemRepository : IMediaItemRepository
|
||||
|
||||
foreach (MediaItem mediaItem in maybeMediaItem)
|
||||
{
|
||||
string libraryType = mediaItem.LibraryPath.Library switch
|
||||
{
|
||||
PlexLibrary => "Plex Library",
|
||||
EmbyLibrary => "Emby Library",
|
||||
JellyfinLibrary => "Jellyfin Library",
|
||||
_ => "Local Library"
|
||||
};
|
||||
Option<Library> maybeIncomingLibrary = await dbContext.Libraries
|
||||
.Filter(l => l.Paths.Any(p => p.Id == libraryPathId))
|
||||
.SingleOrDefaultAsync()
|
||||
.Map(Optional);
|
||||
|
||||
string libraryName = mediaItem.LibraryPath.Library.Name;
|
||||
logger.LogWarning(
|
||||
"Unable to add media item; {LibraryType} '{LibraryName}' already contains path {Path}",
|
||||
libraryType,
|
||||
libraryName,
|
||||
path);
|
||||
return true;
|
||||
foreach (Library incomingLibrary in maybeIncomingLibrary)
|
||||
{
|
||||
string incomingLibraryType = incomingLibrary switch
|
||||
{
|
||||
PlexLibrary => "Plex Library",
|
||||
EmbyLibrary => "Emby Library",
|
||||
JellyfinLibrary => "Jellyfin Library",
|
||||
_ => "Local Library"
|
||||
};
|
||||
|
||||
string existingLibraryType = mediaItem.LibraryPath.Library switch
|
||||
{
|
||||
PlexLibrary => "Plex Library",
|
||||
EmbyLibrary => "Emby Library",
|
||||
JellyfinLibrary => "Jellyfin Library",
|
||||
_ => "Local Library"
|
||||
};
|
||||
|
||||
string libraryName = mediaItem.LibraryPath.Library.Name;
|
||||
logger.LogWarning(
|
||||
"Unable to add media item to {IncomingLibraryType} '{IncomingLibraryName}'; {LibraryType} '{LibraryName}' already contains path {Path}",
|
||||
incomingLibraryType,
|
||||
incomingLibrary.Name,
|
||||
existingLibraryType,
|
||||
libraryName,
|
||||
path);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ public class MovieRepository : IMovieRepository
|
||||
{
|
||||
try
|
||||
{
|
||||
if (await MediaItemRepository.MediaFileAlreadyExists(path, dbContext, _logger))
|
||||
if (await MediaItemRepository.MediaFileAlreadyExists(path, libraryPathId, dbContext, _logger))
|
||||
{
|
||||
return new MediaFileAlreadyExists();
|
||||
}
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
using Dapper;
|
||||
using ErsatzTV.Core;
|
||||
using ErsatzTV.Core.Domain;
|
||||
using ErsatzTV.Core.Errors;
|
||||
using ErsatzTV.Core.Interfaces.Repositories;
|
||||
using ErsatzTV.Core.Metadata;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ErsatzTV.Infrastructure.Data.Repositories;
|
||||
|
||||
public class OtherVideoRepository : IOtherVideoRepository
|
||||
{
|
||||
private readonly IDbContextFactory<TvContext> _dbContextFactory;
|
||||
private readonly ILogger<OtherVideoRepository> _logger;
|
||||
|
||||
public OtherVideoRepository(IDbContextFactory<TvContext> dbContextFactory) => _dbContextFactory = dbContextFactory;
|
||||
public OtherVideoRepository(IDbContextFactory<TvContext> dbContextFactory, ILogger<OtherVideoRepository> logger)
|
||||
{
|
||||
_dbContextFactory = dbContextFactory;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<Either<BaseError, MediaItemScanResult<OtherVideo>>> GetOrAdd(
|
||||
LibraryPath libraryPath,
|
||||
@@ -177,13 +184,18 @@ public class OtherVideoRepository : IOtherVideoRepository
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
private static async Task<Either<BaseError, MediaItemScanResult<OtherVideo>>> AddOtherVideo(
|
||||
private async Task<Either<BaseError, MediaItemScanResult<OtherVideo>>> AddOtherVideo(
|
||||
TvContext dbContext,
|
||||
int libraryPathId,
|
||||
string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (await MediaItemRepository.MediaFileAlreadyExists(path, libraryPathId, dbContext, _logger))
|
||||
{
|
||||
return new MediaFileAlreadyExists();
|
||||
}
|
||||
|
||||
var otherVideo = new OtherVideo
|
||||
{
|
||||
LibraryPathId = libraryPathId,
|
||||
|
||||
@@ -185,7 +185,7 @@ public class PlexMovieRepository : IPlexMovieRepository
|
||||
{
|
||||
try
|
||||
{
|
||||
if (await MediaItemRepository.MediaFileAlreadyExists(item, dbContext, _logger))
|
||||
if (await MediaItemRepository.MediaFileAlreadyExists(item, library.Paths.Head().Id, dbContext, _logger))
|
||||
{
|
||||
return new MediaFileAlreadyExists();
|
||||
}
|
||||
|
||||
@@ -433,7 +433,7 @@ public class PlexTelevisionRepository : IPlexTelevisionRepository
|
||||
{
|
||||
try
|
||||
{
|
||||
if (await MediaItemRepository.MediaFileAlreadyExists(item, dbContext, _logger))
|
||||
if (await MediaItemRepository.MediaFileAlreadyExists(item, library.Paths.Head().Id, dbContext, _logger))
|
||||
{
|
||||
return new MediaFileAlreadyExists();
|
||||
}
|
||||
|
||||
@@ -686,7 +686,7 @@ public class TelevisionRepository : ITelevisionRepository
|
||||
{
|
||||
try
|
||||
{
|
||||
if (await MediaItemRepository.MediaFileAlreadyExists(path, dbContext, _logger))
|
||||
if (await MediaItemRepository.MediaFileAlreadyExists(path, libraryPathId, dbContext, _logger))
|
||||
{
|
||||
return new MediaFileAlreadyExists();
|
||||
}
|
||||
|
||||
@@ -11,16 +11,16 @@
|
||||
<PackageReference Include="Blurhash.ImageSharp" Version="3.0.0" />
|
||||
<PackageReference Include="CliWrap" Version="3.6.0" />
|
||||
<PackageReference Include="Dapper" Version="2.0.123" />
|
||||
<PackageReference Include="Jint" Version="3.0.0-beta-2047" />
|
||||
<PackageReference Include="Jint" Version="3.0.0-beta-2048" />
|
||||
<PackageReference Include="Lucene.Net" Version="4.8.0-beta00016" />
|
||||
<PackageReference Include="Lucene.Net.Analysis.Common" Version="4.8.0-beta00016" />
|
||||
<PackageReference Include="Lucene.Net.QueryParser" Version="4.8.0-beta00016" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.5.22">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<PackageReference Include="Moq" Version="4.18.4" />
|
||||
<PackageReference Include="NUnit" Version="3.13.3" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.6.0">
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.6.1">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
|
||||
@@ -55,16 +55,16 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Bugsnag.AspNet.Core" Version="3.1.0" />
|
||||
<PackageReference Include="FluentValidation" Version="11.5.1" />
|
||||
<PackageReference Include="FluentValidation.AspNetCore" Version="11.2.2" />
|
||||
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
|
||||
<PackageReference Include="HtmlSanitizer" Version="8.0.645" />
|
||||
<PackageReference Include="LanguageExt.Core" Version="4.4.2" />
|
||||
<PackageReference Include="Markdig" Version="0.31.0" />
|
||||
<PackageReference Include="MediatR.Courier.DependencyInjection" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="7.0.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="7.0.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
@@ -72,7 +72,7 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="MudBlazor" Version="6.1.9" />
|
||||
<PackageReference Include="MudBlazor" Version="6.2.0" />
|
||||
<PackageReference Include="NaturalSort.Extension" Version="4.0.0" />
|
||||
<PackageReference Include="PPioli.FluentValidation.Blazor" Version="11.1.0" />
|
||||
<PackageReference Include="Refit.HttpClientFactory" Version="6.3.2" />
|
||||
|
||||
Reference in New Issue
Block a user