improve series recording images

This commit is contained in:
Luke Pulverenti 2016-11-17 13:18:19 -05:00
parent 5bcc419857
commit b0c0b77aed
6 changed files with 49 additions and 97 deletions

View File

@ -87,9 +87,6 @@ namespace Emby.Server.Core.Data
private IDbCommand _deleteItemValuesCommand; private IDbCommand _deleteItemValuesCommand;
private IDbCommand _saveItemValuesCommand; private IDbCommand _saveItemValuesCommand;
private IDbCommand _deleteImagesCommand;
private IDbCommand _saveImagesCommand;
private IDbCommand _updateInheritedTagsCommand; private IDbCommand _updateInheritedTagsCommand;
public const int LatestSchemaVersion = 109; public const int LatestSchemaVersion = 109;
@ -162,9 +159,6 @@ namespace Emby.Server.Core.Data
"create table if not exists ItemValues (ItemId GUID, Type INT, Value TEXT, CleanValue TEXT)", "create table if not exists ItemValues (ItemId GUID, Type INT, Value TEXT, CleanValue TEXT)",
"create table if not exists Images (ItemId GUID NOT NULL, Path TEXT NOT NULL, ImageType INT NOT NULL, DateModified DATETIME, IsPlaceHolder BIT NOT NULL, SortOrder INT)",
"create index if not exists idx_Images on Images(ItemId)",
"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)",
"drop index if exists idxPeopleItemId", "drop index if exists idxPeopleItemId",
@ -309,6 +303,8 @@ namespace Emby.Server.Core.Data
"drop table if exists UserDataKeys", "drop table if exists UserDataKeys",
"drop table if exists ProviderIds", "drop table if exists ProviderIds",
"drop index if exists Idx_ProviderIds1", "drop index if exists Idx_ProviderIds1",
"drop table if exists Images",
"drop index if exists idx_Images",
"create index if not exists idx_PathTypedBaseItems on TypedBaseItems(Path)", "create index if not exists idx_PathTypedBaseItems on TypedBaseItems(Path)",
"create index if not exists idx_ParentIdTypedBaseItems on TypedBaseItems(ParentId)", "create index if not exists idx_ParentIdTypedBaseItems on TypedBaseItems(ParentId)",
@ -664,20 +660,6 @@ namespace Emby.Server.Core.Data
_saveItemValuesCommand.Parameters.Add(_saveItemValuesCommand, "@Type"); _saveItemValuesCommand.Parameters.Add(_saveItemValuesCommand, "@Type");
_saveItemValuesCommand.Parameters.Add(_saveItemValuesCommand, "@Value"); _saveItemValuesCommand.Parameters.Add(_saveItemValuesCommand, "@Value");
_saveItemValuesCommand.Parameters.Add(_saveItemValuesCommand, "@CleanValue"); _saveItemValuesCommand.Parameters.Add(_saveItemValuesCommand, "@CleanValue");
// images
_deleteImagesCommand = _connection.CreateCommand();
_deleteImagesCommand.CommandText = "delete from Images where ItemId=@Id";
_deleteImagesCommand.Parameters.Add(_deleteImagesCommand, "@Id");
_saveImagesCommand = _connection.CreateCommand();
_saveImagesCommand.CommandText = "insert into Images (ItemId, ImageType, Path, DateModified, IsPlaceHolder, SortOrder) values (@ItemId, @ImageType, @Path, @DateModified, @IsPlaceHolder, @SortOrder)";
_saveImagesCommand.Parameters.Add(_saveImagesCommand, "@ItemId");
_saveImagesCommand.Parameters.Add(_saveImagesCommand, "@ImageType");
_saveImagesCommand.Parameters.Add(_saveImagesCommand, "@Path");
_saveImagesCommand.Parameters.Add(_saveImagesCommand, "@DateModified");
_saveImagesCommand.Parameters.Add(_saveImagesCommand, "@IsPlaceHolder");
_saveImagesCommand.Parameters.Add(_saveImagesCommand, "@SortOrder");
} }
/// <summary> /// <summary>
@ -1101,7 +1083,6 @@ namespace Emby.Server.Core.Data
UpdateAncestors(item.Id, item.GetAncestorIds().Distinct().ToList(), transaction); UpdateAncestors(item.Id, item.GetAncestorIds().Distinct().ToList(), transaction);
} }
UpdateImages(item.Id, item.ImageInfos, transaction);
UpdateItemValues(item.Id, GetItemValuesToSave(item), transaction); UpdateItemValues(item.Id, GetItemValuesToSave(item), transaction);
} }
@ -3475,14 +3456,9 @@ namespace Emby.Server.Core.Data
if (query.ImageTypes.Length > 0 && _config.Configuration.SchemaVersion >= 87) if (query.ImageTypes.Length > 0 && _config.Configuration.SchemaVersion >= 87)
{ {
var requiredImageIndex = 0;
foreach (var requiredImage in query.ImageTypes) foreach (var requiredImage in query.ImageTypes)
{ {
var paramName = "@RequiredImageType" + requiredImageIndex; whereClauses.Add("Images like '%" + requiredImage + "%'");
whereClauses.Add("(select path from images where ItemId=Guid and ImageType=" + paramName + " limit 1) not null");
cmd.Parameters.Add(cmd, paramName, DbType.Int32).Value = (int)requiredImage;
requiredImageIndex++;
} }
} }
@ -4255,11 +4231,6 @@ namespace Emby.Server.Core.Data
_deleteItemValuesCommand.Transaction = transaction; _deleteItemValuesCommand.Transaction = transaction;
_deleteItemValuesCommand.ExecuteNonQuery(); _deleteItemValuesCommand.ExecuteNonQuery();
// Delete images
_deleteImagesCommand.GetParameter(0).Value = id;
_deleteImagesCommand.Transaction = transaction;
_deleteImagesCommand.ExecuteNonQuery();
// Delete the item // Delete the item
_deleteItemCommand.GetParameter(0).Value = id; _deleteItemCommand.GetParameter(0).Value = id;
_deleteItemCommand.Transaction = transaction; _deleteItemCommand.Transaction = transaction;
@ -4875,58 +4846,6 @@ namespace Emby.Server.Core.Data
return list; return list;
} }
private void UpdateImages(Guid itemId, List<ItemImageInfo> images, IDbTransaction transaction)
{
if (itemId == Guid.Empty)
{
throw new ArgumentNullException("itemId");
}
if (images == null)
{
throw new ArgumentNullException("images");
}
CheckDisposed();
// First delete
_deleteImagesCommand.GetParameter(0).Value = itemId;
_deleteImagesCommand.Transaction = transaction;
_deleteImagesCommand.ExecuteNonQuery();
var index = 0;
foreach (var image in images)
{
if (string.IsNullOrWhiteSpace(image.Path))
{
// Invalid
continue;
}
_saveImagesCommand.GetParameter(0).Value = itemId;
_saveImagesCommand.GetParameter(1).Value = image.Type;
_saveImagesCommand.GetParameter(2).Value = image.Path;
if (image.DateModified == default(DateTime))
{
_saveImagesCommand.GetParameter(3).Value = null;
}
else
{
_saveImagesCommand.GetParameter(3).Value = image.DateModified;
}
_saveImagesCommand.GetParameter(4).Value = image.IsPlaceholder;
_saveImagesCommand.GetParameter(5).Value = index;
_saveImagesCommand.Transaction = transaction;
_saveImagesCommand.ExecuteNonQuery();
index++;
}
}
private void UpdateItemValues(Guid itemId, List<Tuple<int, string>> values, IDbTransaction transaction) private void UpdateItemValues(Guid itemId, List<Tuple<int, string>> values, IDbTransaction transaction)
{ {
if (itemId == Guid.Empty) if (itemId == Guid.Empty)

View File

@ -13,6 +13,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Controller.Entities.TV;
namespace Emby.Server.Implementations.LiveTv namespace Emby.Server.Implementations.LiveTv
{ {
@ -130,6 +131,38 @@ namespace Emby.Server.Implementations.LiveTv
dto.DayPattern = info.Days == null ? null : GetDayPattern(info.Days); dto.DayPattern = info.Days == null ? null : GetDayPattern(info.Days);
FillImages(dto, info);
return dto;
}
private void FillImages(SeriesTimerInfoDto dto, SeriesTimerInfo info)
{
var librarySeries = _libraryManager.GetItemList(new InternalItemsQuery
{
IncludeItemTypes = new string[] { typeof(Series).Name },
Name = info.Name,
Limit = 1,
ImageTypes = new ImageType[] { ImageType.Thumb }
}).FirstOrDefault();
if (librarySeries != null)
{
var image = librarySeries.GetImageInfo(ImageType.Thumb, 0);
if (image != null)
{
try
{
dto.ParentThumbImageTag = _imageProcessor.GetImageCacheTag(librarySeries, image);
dto.ParentThumbItemId = librarySeries.Id.ToString("N");
}
catch (Exception ex)
{
}
}
}
if (!string.IsNullOrWhiteSpace(info.SeriesId)) if (!string.IsNullOrWhiteSpace(info.SeriesId))
{ {
var program = _libraryManager.GetItemList(new InternalItemsQuery var program = _libraryManager.GetItemList(new InternalItemsQuery
@ -157,8 +190,6 @@ namespace Emby.Server.Implementations.LiveTv
} }
} }
} }
return dto;
} }
public DayPattern? GetDayPattern(List<DayOfWeek> days) public DayPattern? GetDayPattern(List<DayOfWeek> days)

View File

@ -227,7 +227,8 @@ namespace MediaBrowser.Api
ImageRefreshMode = ImageRefreshMode.FullRefresh, ImageRefreshMode = ImageRefreshMode.FullRefresh,
ReplaceAllMetadata = true, ReplaceAllMetadata = true,
ReplaceAllImages = request.ReplaceAllImages, ReplaceAllImages = request.ReplaceAllImages,
SearchResult = request SearchResult = request,
ForceEnableInternetMetadata = true
}, CancellationToken.None); }, CancellationToken.None);
Task.WaitAll(task); Task.WaitAll(task);

View File

@ -264,9 +264,9 @@ namespace MediaBrowser.Controller.LiveTv
if (listings != null) if (listings != null)
{ {
if (!string.IsNullOrWhiteSpace(listings.MoviePrefix)) if (!string.IsNullOrWhiteSpace(listings.MoviePrefix) && name.StartsWith(listings.MoviePrefix, StringComparison.OrdinalIgnoreCase))
{ {
name = name.Replace(listings.MoviePrefix, string.Empty, StringComparison.OrdinalIgnoreCase).Trim(); name = name.Substring(listings.MoviePrefix.Length).Trim();
} }
} }

View File

@ -12,6 +12,7 @@ namespace MediaBrowser.Controller.Providers
public List<ImageType> ReplaceImages { get; set; } public List<ImageType> ReplaceImages { get; set; }
public bool IsAutomated { get; set; } public bool IsAutomated { get; set; }
public bool ForceEnableInternetMetadata { get; set; }
public ImageRefreshOptions(IDirectoryService directoryService) public ImageRefreshOptions(IDirectoryService directoryService)
{ {

View File

@ -272,17 +272,17 @@ namespace MediaBrowser.Providers.Manager
{ {
var options = GetMetadataOptions(item); var options = GetMetadataOptions(item);
return GetMetadataProvidersInternal<T>(item, options, false, true); return GetMetadataProvidersInternal<T>(item, options, false, false, true);
} }
private IEnumerable<IMetadataProvider<T>> GetMetadataProvidersInternal<T>(IHasMetadata item, MetadataOptions options, bool includeDisabled, bool checkIsOwnedItem) private IEnumerable<IMetadataProvider<T>> GetMetadataProvidersInternal<T>(IHasMetadata item, MetadataOptions options, bool includeDisabled, bool forceEnableInternetMetadata, bool checkIsOwnedItem)
where T : IHasMetadata where T : IHasMetadata
{ {
// Avoid implicitly captured closure // Avoid implicitly captured closure
var currentOptions = options; var currentOptions = options;
return _metadataProviders.OfType<IMetadataProvider<T>>() return _metadataProviders.OfType<IMetadataProvider<T>>()
.Where(i => CanRefresh(i, item, currentOptions, includeDisabled, checkIsOwnedItem)) .Where(i => CanRefresh(i, item, currentOptions, includeDisabled, forceEnableInternetMetadata, checkIsOwnedItem))
.OrderBy(i => GetConfiguredOrder(i, options)) .OrderBy(i => GetConfiguredOrder(i, options))
.ThenBy(GetDefaultOrder); .ThenBy(GetDefaultOrder);
} }
@ -294,7 +294,7 @@ namespace MediaBrowser.Providers.Manager
return GetImageProviders(item, options, new ImageRefreshOptions(new DirectoryService(_logger, _fileSystem)), includeDisabled).OfType<IRemoteImageProvider>(); return GetImageProviders(item, options, new ImageRefreshOptions(new DirectoryService(_logger, _fileSystem)), includeDisabled).OfType<IRemoteImageProvider>();
} }
private bool CanRefresh(IMetadataProvider provider, IHasMetadata item, MetadataOptions options, bool includeDisabled, bool checkIsOwnedItem) private bool CanRefresh(IMetadataProvider provider, IHasMetadata item, MetadataOptions options, bool includeDisabled, bool forceEnableInternetMetadata, bool checkIsOwnedItem)
{ {
if (!includeDisabled) if (!includeDisabled)
{ {
@ -306,7 +306,7 @@ namespace MediaBrowser.Providers.Manager
if (provider is IRemoteMetadataProvider) if (provider is IRemoteMetadataProvider)
{ {
if (!item.IsInternetMetadataEnabled()) if (!forceEnableInternetMetadata && !item.IsInternetMetadataEnabled())
{ {
return false; return false;
} }
@ -357,7 +357,7 @@ namespace MediaBrowser.Providers.Manager
if (provider is IRemoteImageProvider) if (provider is IRemoteImageProvider)
{ {
if (!item.IsInternetMetadataEnabled()) if (!refreshOptions.ForceEnableInternetMetadata && !item.IsInternetMetadataEnabled())
{ {
return false; return false;
} }
@ -501,7 +501,7 @@ namespace MediaBrowser.Providers.Manager
private void AddMetadataPlugins<T>(List<MetadataPlugin> list, T item, MetadataOptions options) private void AddMetadataPlugins<T>(List<MetadataPlugin> list, T item, MetadataOptions options)
where T : IHasMetadata where T : IHasMetadata
{ {
var providers = GetMetadataProvidersInternal<T>(item, options, true, false).ToList(); var providers = GetMetadataProvidersInternal<T>(item, options, true, false, false).ToList();
// Locals // Locals
list.AddRange(providers.Where(i => (i is ILocalMetadataProvider)).Select(i => new MetadataPlugin list.AddRange(providers.Where(i => (i is ILocalMetadataProvider)).Select(i => new MetadataPlugin
@ -715,7 +715,7 @@ namespace MediaBrowser.Providers.Manager
var options = GetMetadataOptions(dummy); var options = GetMetadataOptions(dummy);
var providers = GetMetadataProvidersInternal<TItemType>(dummy, options, searchInfo.IncludeDisabledProviders, false) var providers = GetMetadataProvidersInternal<TItemType>(dummy, options, searchInfo.IncludeDisabledProviders, false, false)
.OfType<IRemoteSearchProvider<TLookupType>>(); .OfType<IRemoteSearchProvider<TLookupType>>();
if (!string.IsNullOrEmpty(searchInfo.SearchProviderName)) if (!string.IsNullOrEmpty(searchInfo.SearchProviderName))