mirror of
https://github.com/jellyfin/jellyfin
synced 2024-10-15 04:02:32 +00:00
fix resolution in photo provider
This commit is contained in:
parent
950623b95d
commit
411ce21751
|
@ -53,6 +53,13 @@ namespace MediaBrowser.Controller.FileOrganization
|
||||||
/// <returns>FileOrganizationResult.</returns>
|
/// <returns>FileOrganizationResult.</returns>
|
||||||
FileOrganizationResult GetResult(string id);
|
FileOrganizationResult GetResult(string id);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the result by source path.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The path.</param>
|
||||||
|
/// <returns>FileOrganizationResult.</returns>
|
||||||
|
FileOrganizationResult GetResultBySourcePath(string path);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves the result.
|
/// Saves the result.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -19,6 +19,8 @@ namespace MediaBrowser.Controller.Providers
|
||||||
public interface IRemoteSearchProvider<TLookupInfoType>
|
public interface IRemoteSearchProvider<TLookupInfoType>
|
||||||
where TLookupInfoType : ItemLookupInfo
|
where TLookupInfoType : ItemLookupInfo
|
||||||
{
|
{
|
||||||
|
string Name { get; }
|
||||||
|
|
||||||
Task<IEnumerable<SearchResult<TLookupInfoType>>> GetSearchResults(TLookupInfoType searchInfo, CancellationToken cancellationToken);
|
Task<IEnumerable<SearchResult<TLookupInfoType>>> GetSearchResults(TLookupInfoType searchInfo, CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,4 +31,21 @@ namespace MediaBrowser.Controller.Providers
|
||||||
|
|
||||||
public string ImageUrl { get; set; }
|
public string ImageUrl { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class RemoteSearchQuery<T>
|
||||||
|
where T : ItemLookupInfo
|
||||||
|
{
|
||||||
|
public T SearchInfo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If set will only search within the given provider
|
||||||
|
/// </summary>
|
||||||
|
public string SearchProviderName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether [include disabled providers].
|
||||||
|
/// </summary>
|
||||||
|
/// <value><c>true</c> if [include disabled providers]; otherwise, <c>false</c>.</value>
|
||||||
|
public bool IncludeDisabledProviders { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,12 @@ namespace MediaBrowser.Model.FileOrganization
|
||||||
/// <value>The duplicate paths.</value>
|
/// <value>The duplicate paths.</value>
|
||||||
public List<string> DuplicatePaths { get; set; }
|
public List<string> DuplicatePaths { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the size of the file.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The size of the file.</value>
|
||||||
|
public long FileSize { get; set; }
|
||||||
|
|
||||||
public FileOrganizationResult()
|
public FileOrganizationResult()
|
||||||
{
|
{
|
||||||
DuplicatePaths = new List<string>();
|
DuplicatePaths = new List<string>();
|
||||||
|
|
|
@ -106,16 +106,6 @@ namespace MediaBrowser.Providers.Manager
|
||||||
return Task.FromResult(true);
|
return Task.FromResult(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Saves the image.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="item">The item.</param>
|
|
||||||
/// <param name="url">The URL.</param>
|
|
||||||
/// <param name="resourcePool">The resource pool.</param>
|
|
||||||
/// <param name="type">The type.</param>
|
|
||||||
/// <param name="imageIndex">Index of the image.</param>
|
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
|
||||||
/// <returns>Task.</returns>
|
|
||||||
public async Task SaveImage(IHasImages item, string url, SemaphoreSlim resourcePool, ImageType type, int? imageIndex, CancellationToken cancellationToken)
|
public async Task SaveImage(IHasImages item, string url, SemaphoreSlim resourcePool, ImageType type, int? imageIndex, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var response = await _httpClient.GetResponse(new HttpRequestOptions
|
var response = await _httpClient.GetResponse(new HttpRequestOptions
|
||||||
|
@ -130,28 +120,11 @@ namespace MediaBrowser.Providers.Manager
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Saves the image.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="item">The item.</param>
|
|
||||||
/// <param name="source">The source.</param>
|
|
||||||
/// <param name="mimeType">Type of the MIME.</param>
|
|
||||||
/// <param name="type">The type.</param>
|
|
||||||
/// <param name="imageIndex">Index of the image.</param>
|
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
|
||||||
/// <returns>Task.</returns>
|
|
||||||
public Task SaveImage(IHasImages item, Stream source, string mimeType, ImageType type, int? imageIndex, CancellationToken cancellationToken)
|
public Task SaveImage(IHasImages item, Stream source, string mimeType, ImageType type, int? imageIndex, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return new ImageSaver(ConfigurationManager, _libraryMonitor, _fileSystem, _logger).SaveImage(item, source, mimeType, type, imageIndex, cancellationToken);
|
return new ImageSaver(ConfigurationManager, _libraryMonitor, _fileSystem, _logger).SaveImage(item, source, mimeType, type, imageIndex, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the available remote images.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="item">The item.</param>
|
|
||||||
/// <param name="query">The query.</param>
|
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
|
||||||
/// <returns>Task{IEnumerable{RemoteImageInfo}}.</returns>
|
|
||||||
public async Task<IEnumerable<RemoteImageInfo>> GetAvailableRemoteImages(IHasImages item, RemoteImageQuery query, CancellationToken cancellationToken)
|
public async Task<IEnumerable<RemoteImageInfo>> GetAvailableRemoteImages(IHasImages item, RemoteImageQuery query, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var providers = GetRemoteImageProviders(item, query.IncludeDisabledProviders);
|
var providers = GetRemoteImageProviders(item, query.IncludeDisabledProviders);
|
||||||
|
@ -327,7 +300,7 @@ namespace MediaBrowser.Providers.Manager
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (provider is IRemoteImageProvider)
|
if (provider is IRemoteImageProvider)
|
||||||
{
|
{
|
||||||
if (Array.IndexOf(options.DisabledImageFetchers, provider.Name) != -1)
|
if (Array.IndexOf(options.DisabledImageFetchers, provider.Name) != -1)
|
||||||
|
@ -397,7 +370,7 @@ namespace MediaBrowser.Providers.Manager
|
||||||
// Not configured. Just return some high number to put it at the end.
|
// Not configured. Just return some high number to put it at the end.
|
||||||
return 100;
|
return 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetDefaultOrder(IMetadataProvider provider)
|
private int GetDefaultOrder(IMetadataProvider provider)
|
||||||
{
|
{
|
||||||
var hasOrder = provider as IHasOrder;
|
var hasOrder = provider as IHasOrder;
|
||||||
|
@ -531,7 +504,7 @@ namespace MediaBrowser.Providers.Manager
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ConcurrentDictionary<string, SemaphoreSlim> _fileLocks = new ConcurrentDictionary<string, SemaphoreSlim>();
|
private readonly ConcurrentDictionary<string, SemaphoreSlim> _fileLocks = new ConcurrentDictionary<string, SemaphoreSlim>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves the metadata.
|
/// Saves the metadata.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -613,13 +586,44 @@ namespace MediaBrowser.Providers.Manager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//private IEnumerable<TLookupType> GetRemoteSearchResults<TLookupType>(TLookupType searchInfo,
|
public async Task<IEnumerable<SearchResult<TLookupType>>> GetRemoteSearchResults<TItemType, TLookupType>(RemoteSearchQuery<TLookupType> searchInfo,
|
||||||
// CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
// where TLookupType : ItemLookupInfo
|
where TItemType : BaseItem, new()
|
||||||
//{
|
where TLookupType : ItemLookupInfo
|
||||||
// var providers = _metadataProviders.OfType<IRemoteSearchProvider<TLookupType>>();
|
{
|
||||||
|
// Give it a dummy path just so that it looks like a file system item
|
||||||
|
var dummy = new TItemType
|
||||||
|
{
|
||||||
|
Path = "C:\\",
|
||||||
|
|
||||||
|
// Dummy this up to fool the local trailer check
|
||||||
|
Parent = new Folder()
|
||||||
|
};
|
||||||
|
|
||||||
//}
|
var options = GetMetadataOptions(dummy);
|
||||||
|
|
||||||
|
var providers = GetMetadataProvidersInternal<TItemType>(dummy, options, searchInfo.IncludeDisabledProviders)
|
||||||
|
.OfType<IRemoteSearchProvider<TLookupType>>();
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(searchInfo.SearchProviderName))
|
||||||
|
{
|
||||||
|
providers = providers.Where(i => string.Equals(i.Name, searchInfo.SearchProviderName, StringComparison.OrdinalIgnoreCase));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var provider in providers)
|
||||||
|
{
|
||||||
|
var results = await provider.GetSearchResults(searchInfo.SearchInfo, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
var list = results.ToList();
|
||||||
|
|
||||||
|
if (list.Count > 0)
|
||||||
|
{
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nothing found
|
||||||
|
return new List<SearchResult<TLookupType>>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Drawing;
|
||||||
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
@ -13,10 +14,12 @@ namespace MediaBrowser.Providers.Photos
|
||||||
public class PhotoProvider : ICustomMetadataProvider<Photo>, IHasChangeMonitor
|
public class PhotoProvider : ICustomMetadataProvider<Photo>, IHasChangeMonitor
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
private readonly IImageProcessor _imageProcessor;
|
||||||
|
|
||||||
public PhotoProvider(ILogger logger)
|
public PhotoProvider(ILogger logger, IImageProcessor imageProcessor)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_imageProcessor = imageProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<ItemUpdateType> FetchAsync(Photo item, IDirectoryService directoryService, CancellationToken cancellationToken)
|
public Task<ItemUpdateType> FetchAsync(Photo item, IDirectoryService directoryService, CancellationToken cancellationToken)
|
||||||
|
@ -37,9 +40,6 @@ namespace MediaBrowser.Providers.Photos
|
||||||
string manufacturer;
|
string manufacturer;
|
||||||
string model;
|
string model;
|
||||||
|
|
||||||
int xResolution;
|
|
||||||
int yResolution;
|
|
||||||
|
|
||||||
reader.GetTagValue(ExifTags.FNumber, out aperture);
|
reader.GetTagValue(ExifTags.FNumber, out aperture);
|
||||||
reader.GetTagValue(ExifTags.ExposureTime, out shutterSpeed);
|
reader.GetTagValue(ExifTags.ExposureTime, out shutterSpeed);
|
||||||
reader.GetTagValue(ExifTags.DateTimeOriginal, out dateTaken);
|
reader.GetTagValue(ExifTags.DateTimeOriginal, out dateTaken);
|
||||||
|
@ -47,9 +47,6 @@ namespace MediaBrowser.Providers.Photos
|
||||||
reader.GetTagValue(ExifTags.Make, out manufacturer);
|
reader.GetTagValue(ExifTags.Make, out manufacturer);
|
||||||
reader.GetTagValue(ExifTags.Model, out model);
|
reader.GetTagValue(ExifTags.Model, out model);
|
||||||
|
|
||||||
reader.GetTagValue(ExifTags.XResolution, out xResolution);
|
|
||||||
reader.GetTagValue(ExifTags.YResolution, out yResolution);
|
|
||||||
|
|
||||||
if (dateTaken > DateTime.MinValue)
|
if (dateTaken > DateTime.MinValue)
|
||||||
{
|
{
|
||||||
item.DateCreated = dateTaken;
|
item.DateCreated = dateTaken;
|
||||||
|
@ -61,6 +58,10 @@ namespace MediaBrowser.Providers.Photos
|
||||||
cameraModel += " ";
|
cameraModel += " ";
|
||||||
cameraModel += model ?? string.Empty;
|
cameraModel += model ?? string.Empty;
|
||||||
|
|
||||||
|
var size = _imageProcessor.GetImageSize(item.Path);
|
||||||
|
var xResolution = size.Width;
|
||||||
|
var yResolution = size.Height;
|
||||||
|
|
||||||
item.Overview = "Taken " + dateTaken.ToString("F") + "\n" +
|
item.Overview = "Taken " + dateTaken.ToString("F") + "\n" +
|
||||||
(!string.IsNullOrWhiteSpace(cameraModel) ? "With a " + cameraModel : "") +
|
(!string.IsNullOrWhiteSpace(cameraModel) ? "With a " + cameraModel : "") +
|
||||||
(aperture > 0 && shutterSpeed > 0 ? " at f" + aperture.ToString(CultureInfo.InvariantCulture) + " and " + PhotoHelper.Dec2Frac(shutterSpeed) + "s" : "") + "\n"
|
(aperture > 0 && shutterSpeed > 0 ? " at f" + aperture.ToString(CultureInfo.InvariantCulture) + " and " + PhotoHelper.Dec2Frac(shutterSpeed) + "s" : "") + "\n"
|
||||||
|
|
|
@ -50,7 +50,8 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||||
Date = DateTime.UtcNow,
|
Date = DateTime.UtcNow,
|
||||||
OriginalPath = path,
|
OriginalPath = path,
|
||||||
OriginalFileName = Path.GetFileName(path),
|
OriginalFileName = Path.GetFileName(path),
|
||||||
Type = FileOrganizerType.Episode
|
Type = FileOrganizerType.Episode,
|
||||||
|
FileSize = new FileInfo(path).Length
|
||||||
};
|
};
|
||||||
|
|
||||||
var seriesName = TVUtils.GetSeriesNameFromEpisodeFile(path);
|
var seriesName = TVUtils.GetSeriesNameFromEpisodeFile(path);
|
||||||
|
@ -102,6 +103,17 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||||
_logger.Warn(msg);
|
_logger.Warn(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var previousResult = _organizationService.GetResultBySourcePath(path);
|
||||||
|
|
||||||
|
if (previousResult != null)
|
||||||
|
{
|
||||||
|
// Don't keep saving the same result over and over if nothing has changed
|
||||||
|
if (previousResult.Status == result.Status && result.Status != FileSortingStatus.Success)
|
||||||
|
{
|
||||||
|
return previousResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await _organizationService.SaveResult(result, CancellationToken.None).ConfigureAwait(false);
|
await _organizationService.SaveResult(result, CancellationToken.None).ConfigureAwait(false);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -64,6 +64,18 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||||
return _repo.GetResult(id);
|
return _repo.GetResult(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FileOrganizationResult GetResultBySourcePath(string path)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(path))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("path");
|
||||||
|
}
|
||||||
|
|
||||||
|
var id = path.GetMD5().ToString("N");
|
||||||
|
|
||||||
|
return GetResult(id);
|
||||||
|
}
|
||||||
|
|
||||||
public Task DeleteOriginalFile(string resultId)
|
public Task DeleteOriginalFile(string resultId)
|
||||||
{
|
{
|
||||||
var result = _repo.GetResult(resultId);
|
var result = _repo.GetResult(resultId);
|
||||||
|
|
|
@ -38,11 +38,10 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static string[] ImageExtensions = { ".tiff", ".jpg", ".png", ".aiff" };
|
protected static string[] ImageExtensions = { ".tiff", ".jpeg", ".jpg", ".png", ".aiff" };
|
||||||
protected bool IsImageFile(string path)
|
protected bool IsImageFile(string path)
|
||||||
{
|
{
|
||||||
return !path.EndsWith("folder.jpg", StringComparison.OrdinalIgnoreCase)
|
return !path.EndsWith("folder.jpg", StringComparison.OrdinalIgnoreCase)
|
||||||
&& !path.EndsWith("backdrop.jpg", StringComparison.OrdinalIgnoreCase)
|
|
||||||
&& ImageExtensions.Any(p => path.EndsWith(p, StringComparison.OrdinalIgnoreCase));
|
&& ImageExtensions.Any(p => path.EndsWith(p, StringComparison.OrdinalIgnoreCase));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
string[] queries = {
|
string[] queries = {
|
||||||
|
|
||||||
"create table if not exists OrganizerResults (ResultId GUID PRIMARY KEY, OriginalPath TEXT, TargetPath TEXT, OrganizationDate datetime, Status TEXT, OrganizationType TEXT, StatusMessage TEXT, ExtractedName TEXT, ExtractedYear int null, ExtractedSeasonNumber int null, ExtractedEpisodeNumber int null, ExtractedEndingEpisodeNumber, DuplicatePaths TEXT int null)",
|
"create table if not exists FileOrganizerResults (ResultId GUID PRIMARY KEY, OriginalPath TEXT, TargetPath TEXT, FileLength INT, OrganizationDate datetime, Status TEXT, OrganizationType TEXT, StatusMessage TEXT, ExtractedName TEXT, ExtractedYear int null, ExtractedSeasonNumber int null, ExtractedEpisodeNumber int null, ExtractedEndingEpisodeNumber, DuplicatePaths TEXT int null)",
|
||||||
"create index if not exists idx_OrganizerResults on OrganizerResults(ResultId)",
|
"create index if not exists idx_FileOrganizerResults on FileOrganizerResults(ResultId)",
|
||||||
|
|
||||||
//pragmas
|
//pragmas
|
||||||
"pragma temp_store = memory",
|
"pragma temp_store = memory",
|
||||||
|
@ -68,11 +68,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
private void PrepareStatements()
|
private void PrepareStatements()
|
||||||
{
|
{
|
||||||
_saveResultCommand = _connection.CreateCommand();
|
_saveResultCommand = _connection.CreateCommand();
|
||||||
_saveResultCommand.CommandText = "replace into OrganizerResults (ResultId, OriginalPath, TargetPath, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths) values (@ResultId, @OriginalPath, @TargetPath, @OrganizationDate, @Status, @OrganizationType, @StatusMessage, @ExtractedName, @ExtractedYear, @ExtractedSeasonNumber, @ExtractedEpisodeNumber, @ExtractedEndingEpisodeNumber, @DuplicatePaths)";
|
_saveResultCommand.CommandText = "replace into FileOrganizerResults (ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths) values (@ResultId, @OriginalPath, @TargetPath, @FileLength, @OrganizationDate, @Status, @OrganizationType, @StatusMessage, @ExtractedName, @ExtractedYear, @ExtractedSeasonNumber, @ExtractedEpisodeNumber, @ExtractedEndingEpisodeNumber, @DuplicatePaths)";
|
||||||
|
|
||||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@ResultId");
|
_saveResultCommand.Parameters.Add(_saveResultCommand, "@ResultId");
|
||||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@OriginalPath");
|
_saveResultCommand.Parameters.Add(_saveResultCommand, "@OriginalPath");
|
||||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@TargetPath");
|
_saveResultCommand.Parameters.Add(_saveResultCommand, "@TargetPath");
|
||||||
|
_saveResultCommand.Parameters.Add(_saveResultCommand, "@FileLength");
|
||||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@OrganizationDate");
|
_saveResultCommand.Parameters.Add(_saveResultCommand, "@OrganizationDate");
|
||||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@Status");
|
_saveResultCommand.Parameters.Add(_saveResultCommand, "@Status");
|
||||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@OrganizationType");
|
_saveResultCommand.Parameters.Add(_saveResultCommand, "@OrganizationType");
|
||||||
|
@ -85,12 +86,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
_saveResultCommand.Parameters.Add(_saveResultCommand, "@DuplicatePaths");
|
_saveResultCommand.Parameters.Add(_saveResultCommand, "@DuplicatePaths");
|
||||||
|
|
||||||
_deleteResultCommand = _connection.CreateCommand();
|
_deleteResultCommand = _connection.CreateCommand();
|
||||||
_deleteResultCommand.CommandText = "delete from OrganizerResults where ResultId = @ResultId";
|
_deleteResultCommand.CommandText = "delete from FileOrganizerResults where ResultId = @ResultId";
|
||||||
|
|
||||||
_deleteResultCommand.Parameters.Add(_saveResultCommand, "@ResultId");
|
_deleteResultCommand.Parameters.Add(_saveResultCommand, "@ResultId");
|
||||||
|
|
||||||
_deleteAllCommand = _connection.CreateCommand();
|
_deleteAllCommand = _connection.CreateCommand();
|
||||||
_deleteAllCommand.CommandText = "delete from OrganizerResults";
|
_deleteAllCommand.CommandText = "delete from FileOrganizerResults";
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SaveResult(FileOrganizationResult result, CancellationToken cancellationToken)
|
public async Task SaveResult(FileOrganizationResult result, CancellationToken cancellationToken)
|
||||||
|
@ -110,19 +111,22 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
{
|
{
|
||||||
transaction = _connection.BeginTransaction();
|
transaction = _connection.BeginTransaction();
|
||||||
|
|
||||||
_saveResultCommand.GetParameter(0).Value = new Guid(result.Id);
|
var index = 0;
|
||||||
_saveResultCommand.GetParameter(1).Value = result.OriginalPath;
|
|
||||||
_saveResultCommand.GetParameter(2).Value = result.TargetPath;
|
_saveResultCommand.GetParameter(index++).Value = new Guid(result.Id);
|
||||||
_saveResultCommand.GetParameter(3).Value = result.Date;
|
_saveResultCommand.GetParameter(index++).Value = result.OriginalPath;
|
||||||
_saveResultCommand.GetParameter(4).Value = result.Status.ToString();
|
_saveResultCommand.GetParameter(index++).Value = result.TargetPath;
|
||||||
_saveResultCommand.GetParameter(5).Value = result.Type.ToString();
|
_saveResultCommand.GetParameter(index++).Value = result.FileSize;
|
||||||
_saveResultCommand.GetParameter(6).Value = result.StatusMessage;
|
_saveResultCommand.GetParameter(index++).Value = result.Date;
|
||||||
_saveResultCommand.GetParameter(7).Value = result.ExtractedName;
|
_saveResultCommand.GetParameter(index++).Value = result.Status.ToString();
|
||||||
_saveResultCommand.GetParameter(8).Value = result.ExtractedYear;
|
_saveResultCommand.GetParameter(index++).Value = result.Type.ToString();
|
||||||
_saveResultCommand.GetParameter(9).Value = result.ExtractedSeasonNumber;
|
_saveResultCommand.GetParameter(index++).Value = result.StatusMessage;
|
||||||
_saveResultCommand.GetParameter(10).Value = result.ExtractedEpisodeNumber;
|
_saveResultCommand.GetParameter(index++).Value = result.ExtractedName;
|
||||||
_saveResultCommand.GetParameter(11).Value = result.ExtractedEndingEpisodeNumber;
|
_saveResultCommand.GetParameter(index++).Value = result.ExtractedYear;
|
||||||
_saveResultCommand.GetParameter(12).Value = string.Join("|", result.DuplicatePaths.ToArray());
|
_saveResultCommand.GetParameter(index++).Value = result.ExtractedSeasonNumber;
|
||||||
|
_saveResultCommand.GetParameter(index++).Value = result.ExtractedEpisodeNumber;
|
||||||
|
_saveResultCommand.GetParameter(index++).Value = result.ExtractedEndingEpisodeNumber;
|
||||||
|
_saveResultCommand.GetParameter(index).Value = string.Join("|", result.DuplicatePaths.ToArray());
|
||||||
|
|
||||||
_saveResultCommand.Transaction = transaction;
|
_saveResultCommand.Transaction = transaction;
|
||||||
|
|
||||||
|
@ -271,11 +275,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
using (var cmd = _connection.CreateCommand())
|
using (var cmd = _connection.CreateCommand())
|
||||||
{
|
{
|
||||||
cmd.CommandText = "SELECT ResultId, OriginalPath, TargetPath, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths from OrganizerResults";
|
cmd.CommandText = "SELECT ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths from FileOrganizerResults";
|
||||||
|
|
||||||
if (query.StartIndex.HasValue && query.StartIndex.Value > 0)
|
if (query.StartIndex.HasValue && query.StartIndex.Value > 0)
|
||||||
{
|
{
|
||||||
cmd.CommandText += string.Format(" WHERE ResultId NOT IN (SELECT ResultId FROM OrganizerResults ORDER BY OrganizationDate desc LIMIT {0})",
|
cmd.CommandText += string.Format(" WHERE ResultId NOT IN (SELECT ResultId FROM FileOrganizerResults ORDER BY OrganizationDate desc LIMIT {0})",
|
||||||
query.StartIndex.Value.ToString(_usCulture));
|
query.StartIndex.Value.ToString(_usCulture));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,7 +290,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(_usCulture);
|
cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(_usCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.CommandText += "; select count (ResultId) from OrganizerResults";
|
cmd.CommandText += "; select count (ResultId) from FileOrganizerResults";
|
||||||
|
|
||||||
var list = new List<FileOrganizationResult>();
|
var list = new List<FileOrganizationResult>();
|
||||||
var count = 0;
|
var count = 0;
|
||||||
|
@ -323,7 +327,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
using (var cmd = _connection.CreateCommand())
|
using (var cmd = _connection.CreateCommand())
|
||||||
{
|
{
|
||||||
cmd.CommandText = "select ResultId, OriginalPath, TargetPath, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths from OrganizerResults where ResultId=@Id";
|
cmd.CommandText = "select ResultId, OriginalPath, TargetPath, FileLength, OrganizationDate, Status, OrganizationType, StatusMessage, ExtractedName, ExtractedYear, ExtractedSeasonNumber, ExtractedEpisodeNumber, ExtractedEndingEpisodeNumber, DuplicatePaths from FileOrganizerResults where ResultId=@Id";
|
||||||
|
|
||||||
cmd.Parameters.Add(cmd, "@Id", DbType.Guid).Value = guid;
|
cmd.Parameters.Add(cmd, "@Id", DbType.Guid).Value = guid;
|
||||||
|
|
||||||
|
@ -341,60 +345,79 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||||
|
|
||||||
public FileOrganizationResult GetResult(IDataReader reader)
|
public FileOrganizationResult GetResult(IDataReader reader)
|
||||||
{
|
{
|
||||||
|
var index = 0;
|
||||||
|
|
||||||
var result = new FileOrganizationResult
|
var result = new FileOrganizationResult
|
||||||
{
|
{
|
||||||
Id = reader.GetGuid(0).ToString("N")
|
Id = reader.GetGuid(0).ToString("N")
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!reader.IsDBNull(1))
|
index++;
|
||||||
|
if (!reader.IsDBNull(index))
|
||||||
{
|
{
|
||||||
result.OriginalPath = reader.GetString(1);
|
result.OriginalPath = reader.GetString(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reader.IsDBNull(2))
|
index++;
|
||||||
|
if (!reader.IsDBNull(index))
|
||||||
{
|
{
|
||||||
result.TargetPath = reader.GetString(2);
|
result.TargetPath = reader.GetString(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Date = reader.GetDateTime(3).ToUniversalTime();
|
index++;
|
||||||
result.Status = (FileSortingStatus)Enum.Parse(typeof(FileSortingStatus), reader.GetString(4), true);
|
result.FileSize = reader.GetInt64(index);
|
||||||
result.Type = (FileOrganizerType)Enum.Parse(typeof(FileOrganizerType), reader.GetString(5), true);
|
|
||||||
|
|
||||||
if (!reader.IsDBNull(6))
|
index++;
|
||||||
|
result.Date = reader.GetDateTime(index).ToUniversalTime();
|
||||||
|
|
||||||
|
index++;
|
||||||
|
result.Status = (FileSortingStatus)Enum.Parse(typeof(FileSortingStatus), reader.GetString(index), true);
|
||||||
|
|
||||||
|
index++;
|
||||||
|
result.Type = (FileOrganizerType)Enum.Parse(typeof(FileOrganizerType), reader.GetString(index), true);
|
||||||
|
|
||||||
|
index++;
|
||||||
|
if (!reader.IsDBNull(index))
|
||||||
{
|
{
|
||||||
result.StatusMessage = reader.GetString(6);
|
result.StatusMessage = reader.GetString(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.OriginalFileName = Path.GetFileName(result.OriginalPath);
|
result.OriginalFileName = Path.GetFileName(result.OriginalPath);
|
||||||
|
|
||||||
if (!reader.IsDBNull(7))
|
index++;
|
||||||
|
if (!reader.IsDBNull(index))
|
||||||
{
|
{
|
||||||
result.ExtractedName = reader.GetString(7);
|
result.ExtractedName = reader.GetString(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reader.IsDBNull(8))
|
index++;
|
||||||
|
if (!reader.IsDBNull(index))
|
||||||
{
|
{
|
||||||
result.ExtractedYear = reader.GetInt32(8);
|
result.ExtractedYear = reader.GetInt32(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reader.IsDBNull(9))
|
index++;
|
||||||
|
if (!reader.IsDBNull(index))
|
||||||
{
|
{
|
||||||
result.ExtractedSeasonNumber = reader.GetInt32(9);
|
result.ExtractedSeasonNumber = reader.GetInt32(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reader.IsDBNull(10))
|
index++;
|
||||||
|
if (!reader.IsDBNull(index))
|
||||||
{
|
{
|
||||||
result.ExtractedEpisodeNumber = reader.GetInt32(10);
|
result.ExtractedEpisodeNumber = reader.GetInt32(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reader.IsDBNull(11))
|
index++;
|
||||||
|
if (!reader.IsDBNull(index))
|
||||||
{
|
{
|
||||||
result.ExtractedEndingEpisodeNumber = reader.GetInt32(11);
|
result.ExtractedEndingEpisodeNumber = reader.GetInt32(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reader.IsDBNull(12))
|
index++;
|
||||||
|
if (!reader.IsDBNull(index))
|
||||||
{
|
{
|
||||||
result.DuplicatePaths = reader.GetString(12).Split('|').Where(i => !string.IsNullOrEmpty(i)).ToList();
|
result.DuplicatePaths = reader.GetString(index).Split('|').Where(i => !string.IsNullOrEmpty(i)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in a new issue