Merge pull request #2968 from MediaBrowser/dev

Dev
pull/1154/head
Luke 7 years ago committed by GitHub
commit ef00237c72

@ -1137,8 +1137,21 @@ namespace Emby.Dlna.Didl
} }
int? width = null; int? width = imageInfo.Width;
int? height = null; 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 //try
//{ //{

@ -442,19 +442,39 @@ namespace Emby.Drawing
return GetCachePath(ResizedImageCachePath, filename, "." + format.ToString().ToLower()); 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) if (height > 0 && width > 0)
{ {
return GetImageSize(path, false); 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> /// <summary>

@ -163,10 +163,14 @@ namespace Emby.Photos
if (!item.Width.HasValue || !item.Height.HasValue) 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); if (size.Width > 0 && size.Height > 0)
item.Height = Convert.ToInt32(size.Height); {
item.Width = Convert.ToInt32(size.Width);
item.Height = Convert.ToInt32(size.Height);
}
} }
const ItemUpdateType result = ItemUpdateType.ImageUpdate | ItemUpdateType.MetadataImport; const ItemUpdateType result = ItemUpdateType.ImageUpdate | ItemUpdateType.MetadataImport;

@ -49,7 +49,7 @@ namespace Emby.Server.Implementations.Activity
RunDefaultInitialization(connection); RunDefaultInitialization(connection);
string[] queries = { 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)" "create index if not exists idx_ActivityLogEntries on ActivityLogEntries(Id)"
}; };

@ -75,7 +75,7 @@ namespace Emby.Server.Implementations.Data
string[] queries = { 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)" "create unique index if not exists userdisplaypreferencesindex on userdisplaypreferences (id, userId, client)"
}; };

@ -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 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_AncestorIds1 on AncestorIds(AncestorId)",
"create index if not exists idx_AncestorIds5 on AncestorIds(AncestorIdText,ItemId)", "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)", "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 idxPeopleItemId1 on People(ItemId,ListOrder)",
"create index if not exists idxPeopleName on People(Name)", "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, createMediaStreamsTableCommand,
@ -616,6 +616,33 @@ namespace Emby.Server.Implementations.Data
SaveItems(new List<BaseItem> { item }, cancellationToken); 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> /// <summary>
/// Saves the items. /// Saves the items.
/// </summary> /// </summary>
@ -1170,7 +1197,11 @@ namespace Emby.Server.Implementations.Data
delimeter + delimeter +
image.DateModified.Ticks.ToString(CultureInfo.InvariantCulture) + image.DateModified.Ticks.ToString(CultureInfo.InvariantCulture) +
delimeter + delimeter +
image.Type; image.Type +
delimeter +
image.Width.ToString(CultureInfo.InvariantCulture) +
delimeter +
image.Height.ToString(CultureInfo.InvariantCulture);
} }
public ItemImageInfo ItemImageInfoFromValueString(string value) public ItemImageInfo ItemImageInfoFromValueString(string value)
@ -1198,6 +1229,20 @@ namespace Emby.Server.Implementations.Data
image.Type = type; 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; return image;
} }

@ -52,7 +52,7 @@ namespace Emby.Server.Implementations.Data
{ {
string[] queries = { 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)", "create table if not exists DataSettings (IsUserDataImported bit)",

@ -53,9 +53,8 @@ namespace Emby.Server.Implementations.Data
string[] queries = { 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 index if not exists idx_users on users(guid)",
"create table if not exists schema_version (table_name primary key, version)",
"pragma shrink_memory" "pragma shrink_memory"
}; };

@ -60,7 +60,7 @@ namespace Emby.Server.Implementations.Devices
RunDefaultInitialization(connection); RunDefaultInitialization(connection);
string[] queries = { 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)" "create index if not exists idx_id on Devices(Id)"
}; };

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

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

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

@ -34,7 +34,7 @@ namespace Emby.Server.Implementations.Security
string[] queries = { 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)" "create index if not exists idx_AccessTokens on AccessTokens(Id)"
}; };

@ -50,7 +50,7 @@ namespace Emby.Server.Implementations.Social
string[] queries = { 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)", "create index if not exists idx_Shares on Shares(Id)",
"pragma shrink_memory" "pragma shrink_memory"

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

@ -10,6 +10,7 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using MediaBrowser.Controller;
namespace MediaBrowser.Api.Session namespace MediaBrowser.Api.Session
{ {
@ -293,15 +294,9 @@ namespace MediaBrowser.Api.Session
private readonly IAuthenticationRepository _authRepo; private readonly IAuthenticationRepository _authRepo;
private readonly IDeviceManager _deviceManager; private readonly IDeviceManager _deviceManager;
private readonly ISessionContext _sessionContext; private readonly ISessionContext _sessionContext;
private IServerApplicationHost _appHost;
/// <summary> public SessionsService(ISessionManager sessionManager, IServerApplicationHost appHost, IUserManager userManager, IAuthorizationContext authContext, IAuthenticationRepository authRepo, IDeviceManager deviceManager, ISessionContext sessionContext)
/// 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)
{ {
_sessionManager = sessionManager; _sessionManager = sessionManager;
_userManager = userManager; _userManager = userManager;
@ -309,6 +304,7 @@ namespace MediaBrowser.Api.Session
_authRepo = authRepo; _authRepo = authRepo;
_deviceManager = deviceManager; _deviceManager = deviceManager;
_sessionContext = sessionContext; _sessionContext = sessionContext;
_appHost = appHost;
} }
public void Delete(RevokeKey request) public void Delete(RevokeKey request)
@ -324,7 +320,10 @@ namespace MediaBrowser.Api.Session
AppName = request.App, AppName = request.App,
IsActive = true, IsActive = true,
AccessToken = Guid.NewGuid().ToString("N"), AccessToken = Guid.NewGuid().ToString("N"),
DateCreated = DateTime.UtcNow DateCreated = DateTime.UtcNow,
DeviceId = _appHost.SystemId,
DeviceName = _appHost.FriendlyName,
AppVersion = _appHost.ApplicationVersion.ToString()
}, CancellationToken.None); }, CancellationToken.None);
} }

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

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

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

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

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

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

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

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

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

@ -1,3 +1,3 @@
using System.Reflection; using System.Reflection;
[assembly: AssemblyVersion("3.2.33.15")] [assembly: AssemblyVersion("3.2.33.16")]

Loading…
Cancel
Save