update image aspect ratio detection

This commit is contained in:
Luke Pulverenti 2017-10-22 02:22:43 -04:00
parent 7e2c52936f
commit 7e5036a587
25 changed files with 155 additions and 75 deletions

View File

@ -1137,8 +1137,21 @@ namespace Emby.Dlna.Didl
}
int? width = null;
int? height = null;
int? width = imageInfo.Width;
int? height = imageInfo.Height;
if (width == 0 || height == 0)
{
//_imageProcessor.GetImageSize(item, imageInfo);
width = null;
height = null;
}
else if (width == -1 || height == -1)
{
width = null;
height = null;
}
//try
//{

View File

@ -442,19 +442,39 @@ namespace Emby.Drawing
return GetCachePath(ResizedImageCachePath, filename, "." + format.ToString().ToLower());
}
public ImageSize GetImageSize(ItemImageInfo info, bool allowSlowMethods)
public ImageSize GetImageSize(BaseItem item, ItemImageInfo info)
{
return GetImageSize(info.Path, allowSlowMethods);
return GetImageSize(item, info, false, true);
}
public ImageSize GetImageSize(ItemImageInfo info)
public ImageSize GetImageSize(BaseItem item, ItemImageInfo info, bool allowSlowMethods, bool updateItem)
{
return GetImageSize(info.Path, false);
}
var width = info.Width;
var height = info.Height;
public ImageSize GetImageSize(string path)
{
return GetImageSize(path, false);
if (height > 0 && width > 0)
{
return new ImageSize
{
Width = width,
Height = height
};
}
var path = item.Path;
_logger.Info("Getting image size for item {0} {1}", item.GetType().Name, path);
var size = GetImageSize(path, allowSlowMethods);
info.Height = Convert.ToInt32(size.Height);
info.Width = Convert.ToInt32(size.Width);
if (updateItem)
{
_libraryManager().UpdateImages(item);
}
return size;
}
/// <summary>

View File

@ -163,10 +163,14 @@ namespace Emby.Photos
if (!item.Width.HasValue || !item.Height.HasValue)
{
var size = _imageProcessor.GetImageSize(item.Path);
var img = item.GetImageInfo(ImageType.Primary, 0);
var size = _imageProcessor.GetImageSize(item, img, false, false);
item.Width = Convert.ToInt32(size.Width);
item.Height = Convert.ToInt32(size.Height);
if (size.Width > 0 && size.Height > 0)
{
item.Width = Convert.ToInt32(size.Width);
item.Height = Convert.ToInt32(size.Height);
}
}
const ItemUpdateType result = ItemUpdateType.ImageUpdate | ItemUpdateType.MetadataImport;

View File

@ -49,7 +49,7 @@ namespace Emby.Server.Implementations.Activity
RunDefaultInitialization(connection);
string[] queries = {
"create table if not exists ActivityLogEntries (Id GUID PRIMARY KEY, Name TEXT, Overview TEXT, ShortOverview TEXT, Type TEXT, ItemId TEXT, UserId TEXT, DateCreated DATETIME, LogSeverity TEXT)",
"create table if not exists ActivityLogEntries (Id GUID PRIMARY KEY NOT NULL, Name TEXT NOT NULL, Overview TEXT, ShortOverview TEXT, Type TEXT NOT NULL, ItemId TEXT, UserId TEXT, DateCreated DATETIME NOT NULL, LogSeverity TEXT NOT NULL)",
"create index if not exists idx_ActivityLogEntries on ActivityLogEntries(Id)"
};

View File

@ -75,7 +75,7 @@ namespace Emby.Server.Implementations.Data
string[] queries = {
"create table if not exists userdisplaypreferences (id GUID, userId GUID, client text, data BLOB)",
"create table if not exists userdisplaypreferences (id GUID NOT NULL, userId GUID NOT NULL, client text NOT NULL, data BLOB NOT NULL)",
"create unique index if not exists userdisplaypreferencesindex on userdisplaypreferences (id, userId, client)"
};

View File

@ -146,11 +146,11 @@ namespace Emby.Server.Implementations.Data
"create table if not exists TypedBaseItems (guid GUID primary key NOT NULL, type TEXT NOT NULL, data BLOB NULL, ParentId GUID NULL, Path TEXT NULL)",
"create table if not exists AncestorIds (ItemId GUID, AncestorId GUID, AncestorIdText TEXT, PRIMARY KEY (ItemId, AncestorId))",
"create table if not exists AncestorIds (ItemId GUID NOT NULL, AncestorId GUID NOT NULL, AncestorIdText TEXT NOT NULL, PRIMARY KEY (ItemId, AncestorId))",
"create index if not exists idx_AncestorIds1 on AncestorIds(AncestorId)",
"create index if not exists idx_AncestorIds5 on AncestorIds(AncestorIdText,ItemId)",
"create table if not exists ItemValues (ItemId GUID, Type INT, Value TEXT, CleanValue TEXT)",
"create table if not exists ItemValues (ItemId GUID NOT NULL, Type INT NOT NULL, Value TEXT NOT NULL, CleanValue TEXT NOT NULL)",
"create table if not exists People (ItemId GUID, Name TEXT NOT NULL, Role TEXT, PersonType TEXT, SortOrder int, ListOrder int)",
@ -158,7 +158,7 @@ namespace Emby.Server.Implementations.Data
"create index if not exists idxPeopleItemId1 on People(ItemId,ListOrder)",
"create index if not exists idxPeopleName on People(Name)",
"create table if not exists "+ChaptersTableName+" (ItemId GUID, ChapterIndex INT, StartPositionTicks BIGINT, Name TEXT, ImagePath TEXT, PRIMARY KEY (ItemId, ChapterIndex))",
"create table if not exists "+ChaptersTableName+" (ItemId GUID, ChapterIndex INT NOT NULL, StartPositionTicks BIGINT NOT NULL, Name TEXT, ImagePath TEXT, PRIMARY KEY (ItemId, ChapterIndex))",
createMediaStreamsTableCommand,
@ -616,6 +616,33 @@ namespace Emby.Server.Implementations.Data
SaveItems(new List<BaseItem> { item }, cancellationToken);
}
public void SaveImages(BaseItem item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
CheckDisposed();
using (WriteLock.Write())
{
using (var connection = CreateConnection())
{
connection.RunInTransaction(db =>
{
using (var saveImagesStatement = PrepareStatement(db, "Update TypedBaseItems set Images=@Images where guid=@Id"))
{
saveImagesStatement.TryBind("@Id", item.Id.ToGuidBlob());
saveImagesStatement.TryBind("@Images", SerializeImages(item));
saveImagesStatement.MoveNext();
}
}, TransactionMode);
}
}
}
/// <summary>
/// Saves the items.
/// </summary>
@ -1170,7 +1197,11 @@ namespace Emby.Server.Implementations.Data
delimeter +
image.DateModified.Ticks.ToString(CultureInfo.InvariantCulture) +
delimeter +
image.Type;
image.Type +
delimeter +
image.Width.ToString(CultureInfo.InvariantCulture) +
delimeter +
image.Height.ToString(CultureInfo.InvariantCulture);
}
public ItemImageInfo ItemImageInfoFromValueString(string value)
@ -1198,6 +1229,20 @@ namespace Emby.Server.Implementations.Data
image.Type = type;
}
if (parts.Length >= 5)
{
int width;
int height;
if (int.TryParse(parts[3], NumberStyles.Integer, CultureInfo.InvariantCulture, out width))
{
if (int.TryParse(parts[4], NumberStyles.Integer, CultureInfo.InvariantCulture, out height))
{
image.Width = width;
image.Height = height;
}
}
}
return image;
}

View File

@ -52,7 +52,7 @@ namespace Emby.Server.Implementations.Data
{
string[] queries = {
"create table if not exists userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)",
"create table if not exists userdata (key nvarchar not null, userId GUID not null, rating float null, played bit not null, playCount int not null, isFavorite bit not null, playbackPositionTicks bigint not null, lastPlayedDate datetime null)",
"create table if not exists DataSettings (IsUserDataImported bit)",

View File

@ -53,9 +53,8 @@ namespace Emby.Server.Implementations.Data
string[] queries = {
"create table if not exists users (guid GUID primary key, data BLOB)",
"create table if not exists users (guid GUID primary key NOT NULL, data BLOB NOT NULL)",
"create index if not exists idx_users on users(guid)",
"create table if not exists schema_version (table_name primary key, version)",
"pragma shrink_memory"
};

View File

@ -60,7 +60,7 @@ namespace Emby.Server.Implementations.Devices
RunDefaultInitialization(connection);
string[] queries = {
"create table if not exists Devices (Id TEXT PRIMARY KEY, Name TEXT, ReportedName TEXT, CustomName TEXT, CameraUploadPath TEXT, LastUserName TEXT, AppName TEXT, AppVersion TEXT, LastUserId TEXT, DateLastModified DATETIME, Capabilities TEXT)",
"create table if not exists Devices (Id TEXT PRIMARY KEY, Name TEXT NOT NULL, ReportedName TEXT NOT NULL, CustomName TEXT, CameraUploadPath TEXT, LastUserName TEXT NOT NULL, AppName TEXT NOT NULL, AppVersion TEXT NOT NULL, LastUserId TEXT NOT NULL, DateLastModified DATETIME NOT NULL, Capabilities TEXT NOT NULL)",
"create index if not exists idx_id on Devices(Id)"
};

View File

@ -1608,12 +1608,12 @@ namespace Emby.Server.Implementations.Dto
/// <param name="dto">The dto.</param>
/// <param name="item">The item.</param>
/// <returns>Task.</returns>
public void AttachPrimaryImageAspectRatio(IItemDto dto, IHasMetadata item)
public void AttachPrimaryImageAspectRatio(IItemDto dto, BaseItem item)
{
dto.PrimaryImageAspectRatio = GetPrimaryImageAspectRatio(item);
}
public double? GetPrimaryImageAspectRatio(IHasMetadata item)
public double? GetPrimaryImageAspectRatio(BaseItem item)
{
var imageInfo = item.GetImageInfo(ImageType.Primary, 0);
@ -1646,12 +1646,14 @@ namespace Emby.Server.Implementations.Dto
return null;
}
return null;
_logger.Info("Getting image size for item type {0}", item.GetType().Name);
try
{
size = _imageProcessor.GetImageSize(imageInfo);
size = _imageProcessor.GetImageSize(item, imageInfo);
if (size.Width <= 0 || size.Height <= 0)
{
return null;
}
}
catch
{

View File

@ -1826,6 +1826,13 @@ namespace Emby.Server.Implementations.Library
}
}
public void UpdateImages(BaseItem item)
{
ItemRepository.SaveImages(item);
RegisterItem(item);
}
/// <summary>
/// Updates the item.
/// </summary>

View File

@ -76,7 +76,6 @@ namespace Emby.Server.Implementations.Notifications
var tasks = users.Select(i => SendNotification(request, service, title, description, i, cancellationToken));
return Task.WhenAll(tasks);
}
private IEnumerable<string> GetUserIds(NotificationRequest request, NotificationOption options)

View File

@ -34,7 +34,7 @@ namespace Emby.Server.Implementations.Security
string[] queries = {
"create table if not exists AccessTokens (Id GUID PRIMARY KEY, AccessToken TEXT NOT NULL, DeviceId TEXT, AppName TEXT, AppVersion TEXT, DeviceName TEXT, UserId TEXT, IsActive BIT, DateCreated DATETIME NOT NULL, DateRevoked DATETIME)",
"create table if not exists AccessTokens (Id GUID PRIMARY KEY NOT NULL, AccessToken TEXT NOT NULL, DeviceId TEXT NOT NULL, AppName TEXT NOT NULL, AppVersion TEXT NOT NULL, DeviceName TEXT NOT NULL, UserId TEXT, IsActive BIT NOT NULL, DateCreated DATETIME NOT NULL, DateRevoked DATETIME)",
"create index if not exists idx_AccessTokens on AccessTokens(Id)"
};

View File

@ -50,7 +50,7 @@ namespace Emby.Server.Implementations.Social
string[] queries = {
"create table if not exists Shares (Id GUID, ItemId TEXT, UserId TEXT, ExpirationDate DateTime, PRIMARY KEY (Id))",
"create table if not exists Shares (Id GUID NOT NULL, ItemId TEXT NOT NULL, UserId TEXT NOT NULL, ExpirationDate DateTime NOT NULL, PRIMARY KEY (Id))",
"create index if not exists idx_Shares on Shares(Id)",
"pragma shrink_memory"

View File

@ -315,7 +315,7 @@ namespace MediaBrowser.Api.Images
return list;
}
private ImageInfo GetImageInfo(IHasMetadata item, ItemImageInfo info, int? imageIndex)
private ImageInfo GetImageInfo(BaseItem item, ItemImageInfo info, int? imageIndex)
{
try
{
@ -330,11 +330,17 @@ namespace MediaBrowser.Api.Images
var fileInfo = _fileSystem.GetFileInfo(info.Path);
length = fileInfo.Length;
var size = _imageProcessor.GetImageSize(info, true);
var size = _imageProcessor.GetImageSize(item, info, true, true);
width = Convert.ToInt32(size.Width);
height = Convert.ToInt32(size.Height);
if (width <= 0 || height <= 0)
{
width = null;
height = null;
}
}
}
catch

View File

@ -10,6 +10,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Services;
using MediaBrowser.Controller;
namespace MediaBrowser.Api.Session
{
@ -293,15 +294,9 @@ namespace MediaBrowser.Api.Session
private readonly IAuthenticationRepository _authRepo;
private readonly IDeviceManager _deviceManager;
private readonly ISessionContext _sessionContext;
private IServerApplicationHost _appHost;
/// <summary>
/// Initializes a new instance of the <see cref="SessionsService" /> class.
/// </summary>
/// <param name="sessionManager">The session manager.</param>
/// <param name="userManager">The user manager.</param>
/// <param name="authContext">The authentication context.</param>
/// <param name="authRepo">The authentication repo.</param>
public SessionsService(ISessionManager sessionManager, IUserManager userManager, IAuthorizationContext authContext, IAuthenticationRepository authRepo, IDeviceManager deviceManager, ISessionContext sessionContext)
public SessionsService(ISessionManager sessionManager, IServerApplicationHost appHost, IUserManager userManager, IAuthorizationContext authContext, IAuthenticationRepository authRepo, IDeviceManager deviceManager, ISessionContext sessionContext)
{
_sessionManager = sessionManager;
_userManager = userManager;
@ -309,6 +304,7 @@ namespace MediaBrowser.Api.Session
_authRepo = authRepo;
_deviceManager = deviceManager;
_sessionContext = sessionContext;
_appHost = appHost;
}
public void Delete(RevokeKey request)
@ -324,7 +320,10 @@ namespace MediaBrowser.Api.Session
AppName = request.App,
IsActive = true,
AccessToken = Guid.NewGuid().ToString("N"),
DateCreated = DateTime.UtcNow
DateCreated = DateTime.UtcNow,
DeviceId = _appHost.SystemId,
DeviceName = _appHost.FriendlyName,
AppVersion = _appHost.ApplicationVersion.ToString()
}, CancellationToken.None);
}

View File

@ -32,14 +32,6 @@ namespace MediaBrowser.Controller.Channels
return base.IsVisible(user);
}
public override double? GetDefaultPrimaryImageAspectRatio()
{
double value = 16;
value /= 9;
return value;
}
[IgnoreDataMember]
public override bool SupportsInheritedParentImages
{

View File

@ -31,16 +31,9 @@ namespace MediaBrowser.Controller.Drawing
/// </summary>
/// <param name="info">The information.</param>
/// <returns>ImageSize.</returns>
ImageSize GetImageSize(ItemImageInfo info);
ImageSize GetImageSize(BaseItem item, ItemImageInfo info);
ImageSize GetImageSize(ItemImageInfo info, bool allowSlowMethods);
/// <summary>
/// Gets the size of the image.
/// </summary>
/// <param name="path">The path.</param>
/// <returns>ImageSize.</returns>
ImageSize GetImageSize(string path);
ImageSize GetImageSize(BaseItem item, ItemImageInfo info, bool allowSlowMethods, bool updateItem);
/// <summary>
/// Adds the parts.

View File

@ -23,14 +23,14 @@ namespace MediaBrowser.Controller.Dto
/// </summary>
/// <param name="dto">The dto.</param>
/// <param name="item">The item.</param>
void AttachPrimaryImageAspectRatio(IItemDto dto, IHasMetadata item);
void AttachPrimaryImageAspectRatio(IItemDto dto, BaseItem item);
/// <summary>
/// Gets the primary image aspect ratio.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>System.Nullable&lt;System.Double&gt;.</returns>
double? GetPrimaryImageAspectRatio(IHasMetadata item);
double? GetPrimaryImageAspectRatio(BaseItem item);
/// <summary>
/// Gets the base item dto.

View File

@ -1952,6 +1952,8 @@ namespace MediaBrowser.Controller.Entities
{
existingImage.Path = image.Path;
existingImage.DateModified = image.DateModified;
existingImage.Width = image.Width;
existingImage.Height = image.Height;
}
else
@ -2268,6 +2270,11 @@ namespace MediaBrowser.Controller.Entities
info1.DateModified = FileSystem.GetLastWriteTimeUtc(info1.Path);
info2.DateModified = FileSystem.GetLastWriteTimeUtc(info2.Path);
info1.Width = 0;
info1.Height = 0;
info2.Width = 0;
info2.Height = 0;
UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
}

View File

@ -24,6 +24,9 @@ namespace MediaBrowser.Controller.Entities
/// <value>The date modified.</value>
public DateTime DateModified { get; set; }
public int Width { get; set; }
public int Height { get; set; }
[IgnoreDataMember]
public bool IsLocalFile
{

View File

@ -30,10 +30,5 @@ namespace MediaBrowser.Controller.Entities
return false;
}
}
public override double? GetDefaultPrimaryImageAspectRatio()
{
return 1;
}
}
}

View File

@ -78,14 +78,6 @@ namespace MediaBrowser.Controller.Entities
}
}
public override double? GetDefaultPrimaryImageAspectRatio()
{
double value = 16;
value /= 9;
return value;
}
public override string CreatePresentationUniqueKey()
{
if (!string.IsNullOrWhiteSpace(PrimaryVersionId))

View File

@ -128,6 +128,8 @@ namespace MediaBrowser.Controller.Library
/// </summary>
void QueueLibraryScan();
void UpdateImages(BaseItem item);
/// <summary>
/// Gets the default view.
/// </summary>

View File

@ -48,6 +48,8 @@ namespace MediaBrowser.Controller.Persistence
/// <param name="cancellationToken">The cancellation token.</param>
void SaveItems(List<BaseItem> items, CancellationToken cancellationToken);
void SaveImages(BaseItem item);
/// <summary>
/// Retrieves the item.
/// </summary>