|
|
|
@ -124,13 +124,13 @@ public class MediaItemRepository : IMediaItemRepository |
|
|
|
return Unit.Default; |
|
|
|
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; |
|
|
|
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 |
|
|
|
Option<int> maybeMediaItemId = await dbContext.Connection |
|
|
|
.QuerySingleOrDefaultAsync<int?>( |
|
|
|
.QuerySingleOrDefaultAsync<int?>( |
|
|
|
@ -151,21 +151,40 @@ public class MediaItemRepository : IMediaItemRepository |
|
|
|
|
|
|
|
|
|
|
|
foreach (MediaItem mediaItem in maybeMediaItem) |
|
|
|
foreach (MediaItem mediaItem in maybeMediaItem) |
|
|
|
{ |
|
|
|
{ |
|
|
|
string libraryType = mediaItem.LibraryPath.Library switch |
|
|
|
Option<Library> maybeIncomingLibrary = await dbContext.Libraries |
|
|
|
|
|
|
|
.Filter(l => l.Paths.Any(p => p.Id == libraryPathId)) |
|
|
|
|
|
|
|
.SingleOrDefaultAsync() |
|
|
|
|
|
|
|
.Map(Optional); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (Library incomingLibrary in maybeIncomingLibrary) |
|
|
|
{ |
|
|
|
{ |
|
|
|
PlexLibrary => "Plex Library", |
|
|
|
string incomingLibraryType = incomingLibrary switch |
|
|
|
EmbyLibrary => "Emby Library", |
|
|
|
{ |
|
|
|
JellyfinLibrary => "Jellyfin Library", |
|
|
|
PlexLibrary => "Plex Library", |
|
|
|
_ => "Local Library" |
|
|
|
EmbyLibrary => "Emby Library", |
|
|
|
}; |
|
|
|
JellyfinLibrary => "Jellyfin Library", |
|
|
|
|
|
|
|
_ => "Local Library" |
|
|
|
string libraryName = mediaItem.LibraryPath.Library.Name; |
|
|
|
}; |
|
|
|
logger.LogWarning( |
|
|
|
|
|
|
|
"Unable to add media item; {LibraryType} '{LibraryName}' already contains path {Path}", |
|
|
|
string existingLibraryType = mediaItem.LibraryPath.Library switch |
|
|
|
libraryType, |
|
|
|
{ |
|
|
|
libraryName, |
|
|
|
PlexLibrary => "Plex Library", |
|
|
|
path); |
|
|
|
EmbyLibrary => "Emby Library", |
|
|
|
return true; |
|
|
|
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; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|