improve series recording images

pull/702/head
Luke Pulverenti 8 years ago
parent 5bcc419857
commit b0c0b77aed

@ -87,9 +87,6 @@ namespace Emby.Server.Core.Data
private IDbCommand _deleteItemValuesCommand;
private IDbCommand _saveItemValuesCommand;
private IDbCommand _deleteImagesCommand;
private IDbCommand _saveImagesCommand;
private IDbCommand _updateInheritedTagsCommand;
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 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)",
"drop index if exists idxPeopleItemId",
@ -309,6 +303,8 @@ namespace Emby.Server.Core.Data
"drop table if exists UserDataKeys",
"drop table if exists ProviderIds",
"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_ParentIdTypedBaseItems on TypedBaseItems(ParentId)",
@ -664,20 +660,6 @@ namespace Emby.Server.Core.Data
_saveItemValuesCommand.Parameters.Add(_saveItemValuesCommand, "@Type");
_saveItemValuesCommand.Parameters.Add(_saveItemValuesCommand, "@Value");
_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>
@ -1101,7 +1083,6 @@ namespace Emby.Server.Core.Data
UpdateAncestors(item.Id, item.GetAncestorIds().Distinct().ToList(), transaction);
}
UpdateImages(item.Id, item.ImageInfos, 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)
{
var requiredImageIndex = 0;
foreach (var requiredImage in query.ImageTypes)
{
var paramName = "@RequiredImageType" + requiredImageIndex;
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++;
whereClauses.Add("Images like '%" + requiredImage + "%'");
}
}
@ -4255,11 +4231,6 @@ namespace Emby.Server.Core.Data
_deleteItemValuesCommand.Transaction = transaction;
_deleteItemValuesCommand.ExecuteNonQuery();
// Delete images
_deleteImagesCommand.GetParameter(0).Value = id;
_deleteImagesCommand.Transaction = transaction;
_deleteImagesCommand.ExecuteNonQuery();
// Delete the item
_deleteItemCommand.GetParameter(0).Value = id;
_deleteItemCommand.Transaction = transaction;
@ -4875,58 +4846,6 @@ namespace Emby.Server.Core.Data
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)
{
if (itemId == Guid.Empty)

@ -13,6 +13,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller.Entities.TV;
namespace Emby.Server.Implementations.LiveTv
{
@ -130,6 +131,38 @@ namespace Emby.Server.Implementations.LiveTv
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))
{
var program = _libraryManager.GetItemList(new InternalItemsQuery
@ -157,8 +190,6 @@ namespace Emby.Server.Implementations.LiveTv
}
}
}
return dto;
}
public DayPattern? GetDayPattern(List<DayOfWeek> days)

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

@ -264,9 +264,9 @@ namespace MediaBrowser.Controller.LiveTv
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();
}
}

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

@ -272,17 +272,17 @@ namespace MediaBrowser.Providers.Manager
{
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
{
// Avoid implicitly captured closure
var currentOptions = options;
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))
.ThenBy(GetDefaultOrder);
}
@ -294,7 +294,7 @@ namespace MediaBrowser.Providers.Manager
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)
{
@ -306,7 +306,7 @@ namespace MediaBrowser.Providers.Manager
if (provider is IRemoteMetadataProvider)
{
if (!item.IsInternetMetadataEnabled())
if (!forceEnableInternetMetadata && !item.IsInternetMetadataEnabled())
{
return false;
}
@ -357,7 +357,7 @@ namespace MediaBrowser.Providers.Manager
if (provider is IRemoteImageProvider)
{
if (!item.IsInternetMetadataEnabled())
if (!refreshOptions.ForceEnableInternetMetadata && !item.IsInternetMetadataEnabled())
{
return false;
}
@ -501,7 +501,7 @@ namespace MediaBrowser.Providers.Manager
private void AddMetadataPlugins<T>(List<MetadataPlugin> list, T item, MetadataOptions options)
where T : IHasMetadata
{
var providers = GetMetadataProvidersInternal<T>(item, options, true, false).ToList();
var providers = GetMetadataProvidersInternal<T>(item, options, true, false, false).ToList();
// Locals
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 providers = GetMetadataProvidersInternal<TItemType>(dummy, options, searchInfo.IncludeDisabledProviders, false)
var providers = GetMetadataProvidersInternal<TItemType>(dummy, options, searchInfo.IncludeDisabledProviders, false, false)
.OfType<IRemoteSearchProvider<TLookupType>>();
if (!string.IsNullOrEmpty(searchInfo.SearchProviderName))

Loading…
Cancel
Save