fix resolution in photo provider

This commit is contained in:
Luke Pulverenti 2014-02-19 11:24:06 -05:00
parent 950623b95d
commit 411ce21751
9 changed files with 173 additions and 90 deletions

View File

@ -53,6 +53,13 @@ namespace MediaBrowser.Controller.FileOrganization
/// <returns>FileOrganizationResult.</returns>
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>
/// Saves the result.
/// </summary>

View File

@ -19,6 +19,8 @@ namespace MediaBrowser.Controller.Providers
public interface IRemoteSearchProvider<TLookupInfoType>
where TLookupInfoType : ItemLookupInfo
{
string Name { get; }
Task<IEnumerable<SearchResult<TLookupInfoType>>> GetSearchResults(TLookupInfoType searchInfo, CancellationToken cancellationToken);
}
@ -29,4 +31,21 @@ namespace MediaBrowser.Controller.Providers
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; }
}
}

View File

@ -89,6 +89,12 @@ namespace MediaBrowser.Model.FileOrganization
/// <value>The duplicate paths.</value>
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()
{
DuplicatePaths = new List<string>();

View File

@ -106,16 +106,6 @@ namespace MediaBrowser.Providers.Manager
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)
{
var response = await _httpClient.GetResponse(new HttpRequestOptions
@ -130,28 +120,11 @@ namespace MediaBrowser.Providers.Manager
.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)
{
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)
{
var providers = GetRemoteImageProviders(item, query.IncludeDisabledProviders);
@ -327,7 +300,7 @@ namespace MediaBrowser.Providers.Manager
{
return false;
}
if (provider is IRemoteImageProvider)
{
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.
return 100;
}
private int GetDefaultOrder(IMetadataProvider provider)
{
var hasOrder = provider as IHasOrder;
@ -531,7 +504,7 @@ namespace MediaBrowser.Providers.Manager
}
private readonly ConcurrentDictionary<string, SemaphoreSlim> _fileLocks = new ConcurrentDictionary<string, SemaphoreSlim>();
/// <summary>
/// Saves the metadata.
/// </summary>
@ -613,13 +586,44 @@ namespace MediaBrowser.Providers.Manager
}
}
//private IEnumerable<TLookupType> GetRemoteSearchResults<TLookupType>(TLookupType searchInfo,
// CancellationToken cancellationToken)
// where TLookupType : ItemLookupInfo
//{
// var providers = _metadataProviders.OfType<IRemoteSearchProvider<TLookupType>>();
public async Task<IEnumerable<SearchResult<TLookupType>>> GetRemoteSearchResults<TItemType, TLookupType>(RemoteSearchQuery<TLookupType> searchInfo,
CancellationToken cancellationToken)
where TItemType : BaseItem, new()
where TLookupType : ItemLookupInfo
{
// 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>>();
}
}
}

View File

@ -1,4 +1,5 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
@ -13,10 +14,12 @@ namespace MediaBrowser.Providers.Photos
public class PhotoProvider : ICustomMetadataProvider<Photo>, IHasChangeMonitor
{
private readonly ILogger _logger;
private readonly IImageProcessor _imageProcessor;
public PhotoProvider(ILogger logger)
public PhotoProvider(ILogger logger, IImageProcessor imageProcessor)
{
_logger = logger;
_imageProcessor = imageProcessor;
}
public Task<ItemUpdateType> FetchAsync(Photo item, IDirectoryService directoryService, CancellationToken cancellationToken)
@ -37,9 +40,6 @@ namespace MediaBrowser.Providers.Photos
string manufacturer;
string model;
int xResolution;
int yResolution;
reader.GetTagValue(ExifTags.FNumber, out aperture);
reader.GetTagValue(ExifTags.ExposureTime, out shutterSpeed);
reader.GetTagValue(ExifTags.DateTimeOriginal, out dateTaken);
@ -47,9 +47,6 @@ namespace MediaBrowser.Providers.Photos
reader.GetTagValue(ExifTags.Make, out manufacturer);
reader.GetTagValue(ExifTags.Model, out model);
reader.GetTagValue(ExifTags.XResolution, out xResolution);
reader.GetTagValue(ExifTags.YResolution, out yResolution);
if (dateTaken > DateTime.MinValue)
{
item.DateCreated = dateTaken;
@ -61,6 +58,10 @@ namespace MediaBrowser.Providers.Photos
cameraModel += " ";
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" +
(!string.IsNullOrWhiteSpace(cameraModel) ? "With a " + cameraModel : "") +
(aperture > 0 && shutterSpeed > 0 ? " at f" + aperture.ToString(CultureInfo.InvariantCulture) + " and " + PhotoHelper.Dec2Frac(shutterSpeed) + "s" : "") + "\n"

View File

@ -50,7 +50,8 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
Date = DateTime.UtcNow,
OriginalPath = path,
OriginalFileName = Path.GetFileName(path),
Type = FileOrganizerType.Episode
Type = FileOrganizerType.Episode,
FileSize = new FileInfo(path).Length
};
var seriesName = TVUtils.GetSeriesNameFromEpisodeFile(path);
@ -102,6 +103,17 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
_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);
return result;

View File

@ -64,6 +64,18 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
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)
{
var result = _repo.GetResult(resultId);

View File

@ -38,11 +38,10 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
return null;
}
protected static string[] ImageExtensions = { ".tiff", ".jpg", ".png", ".aiff" };
protected static string[] ImageExtensions = { ".tiff", ".jpeg", ".jpg", ".png", ".aiff" };
protected bool IsImageFile(string path)
{
return !path.EndsWith("folder.jpg", StringComparison.OrdinalIgnoreCase)
&& !path.EndsWith("backdrop.jpg", StringComparison.OrdinalIgnoreCase)
&& ImageExtensions.Any(p => path.EndsWith(p, StringComparison.OrdinalIgnoreCase));
}

View File

@ -49,8 +49,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
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 index if not exists idx_OrganizerResults on OrganizerResults(ResultId)",
"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_FileOrganizerResults on FileOrganizerResults(ResultId)",
//pragmas
"pragma temp_store = memory",
@ -68,11 +68,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
private void PrepareStatements()
{
_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, "@OriginalPath");
_saveResultCommand.Parameters.Add(_saveResultCommand, "@TargetPath");
_saveResultCommand.Parameters.Add(_saveResultCommand, "@FileLength");
_saveResultCommand.Parameters.Add(_saveResultCommand, "@OrganizationDate");
_saveResultCommand.Parameters.Add(_saveResultCommand, "@Status");
_saveResultCommand.Parameters.Add(_saveResultCommand, "@OrganizationType");
@ -85,12 +86,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
_saveResultCommand.Parameters.Add(_saveResultCommand, "@DuplicatePaths");
_deleteResultCommand = _connection.CreateCommand();
_deleteResultCommand.CommandText = "delete from OrganizerResults where ResultId = @ResultId";
_deleteResultCommand.CommandText = "delete from FileOrganizerResults where ResultId = @ResultId";
_deleteResultCommand.Parameters.Add(_saveResultCommand, "@ResultId");
_deleteAllCommand = _connection.CreateCommand();
_deleteAllCommand.CommandText = "delete from OrganizerResults";
_deleteAllCommand.CommandText = "delete from FileOrganizerResults";
}
public async Task SaveResult(FileOrganizationResult result, CancellationToken cancellationToken)
@ -110,19 +111,22 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
transaction = _connection.BeginTransaction();
_saveResultCommand.GetParameter(0).Value = new Guid(result.Id);
_saveResultCommand.GetParameter(1).Value = result.OriginalPath;
_saveResultCommand.GetParameter(2).Value = result.TargetPath;
_saveResultCommand.GetParameter(3).Value = result.Date;
_saveResultCommand.GetParameter(4).Value = result.Status.ToString();
_saveResultCommand.GetParameter(5).Value = result.Type.ToString();
_saveResultCommand.GetParameter(6).Value = result.StatusMessage;
_saveResultCommand.GetParameter(7).Value = result.ExtractedName;
_saveResultCommand.GetParameter(8).Value = result.ExtractedYear;
_saveResultCommand.GetParameter(9).Value = result.ExtractedSeasonNumber;
_saveResultCommand.GetParameter(10).Value = result.ExtractedEpisodeNumber;
_saveResultCommand.GetParameter(11).Value = result.ExtractedEndingEpisodeNumber;
_saveResultCommand.GetParameter(12).Value = string.Join("|", result.DuplicatePaths.ToArray());
var index = 0;
_saveResultCommand.GetParameter(index++).Value = new Guid(result.Id);
_saveResultCommand.GetParameter(index++).Value = result.OriginalPath;
_saveResultCommand.GetParameter(index++).Value = result.TargetPath;
_saveResultCommand.GetParameter(index++).Value = result.FileSize;
_saveResultCommand.GetParameter(index++).Value = result.Date;
_saveResultCommand.GetParameter(index++).Value = result.Status.ToString();
_saveResultCommand.GetParameter(index++).Value = result.Type.ToString();
_saveResultCommand.GetParameter(index++).Value = result.StatusMessage;
_saveResultCommand.GetParameter(index++).Value = result.ExtractedName;
_saveResultCommand.GetParameter(index++).Value = result.ExtractedYear;
_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;
@ -271,11 +275,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
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)
{
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));
}
@ -286,7 +290,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
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 count = 0;
@ -323,7 +327,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
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;
@ -341,60 +345,79 @@ namespace MediaBrowser.Server.Implementations.Persistence
public FileOrganizationResult GetResult(IDataReader reader)
{
var index = 0;
var result = new FileOrganizationResult
{
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();
result.Status = (FileSortingStatus)Enum.Parse(typeof(FileSortingStatus), reader.GetString(4), true);
result.Type = (FileOrganizerType)Enum.Parse(typeof(FileOrganizerType), reader.GetString(5), true);
index++;
result.FileSize = reader.GetInt64(index);
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);
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;