2014-10-24 06:54:35 +02:00
|
|
|
|
using MediaBrowser.Common;
|
2014-05-17 23:23:48 +02:00
|
|
|
|
using MediaBrowser.Controller.Channels;
|
2014-01-30 06:20:18 +01:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2015-01-24 20:03:55 +01:00
|
|
|
|
using MediaBrowser.Controller.Devices;
|
2013-09-18 20:49:06 +02:00
|
|
|
|
using MediaBrowser.Controller.Drawing;
|
2013-09-04 19:02:19 +02:00
|
|
|
|
using MediaBrowser.Controller.Dto;
|
2013-03-12 23:49:45 +01:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-04-13 20:02:30 +02:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-03-30 18:49:40 +02:00
|
|
|
|
using MediaBrowser.Controller.LiveTv;
|
2013-04-13 20:02:30 +02:00
|
|
|
|
using MediaBrowser.Controller.Persistence;
|
2014-08-03 04:16:37 +02:00
|
|
|
|
using MediaBrowser.Controller.Playlists;
|
2014-02-21 19:48:15 +01:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-07-22 18:36:34 +02:00
|
|
|
|
using MediaBrowser.Controller.Sync;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
using MediaBrowser.Model.Drawing;
|
2013-02-21 18:50:46 +01:00
|
|
|
|
using MediaBrowser.Model.Dto;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-02-21 07:38:23 +01:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-03-12 23:49:45 +01:00
|
|
|
|
using MediaBrowser.Model.Querying;
|
2015-01-24 20:03:55 +01:00
|
|
|
|
using MediaBrowser.Model.Sync;
|
2013-09-04 19:02:19 +02:00
|
|
|
|
using MoreLinq;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2016-03-02 19:42:39 +01:00
|
|
|
|
using System.Threading.Tasks;
|
2015-10-04 06:23:11 +02:00
|
|
|
|
using CommonIO;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
namespace MediaBrowser.Server.Implementations.Dto
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
public class DtoService : IDtoService
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-03-01 22:22:34 +01:00
|
|
|
|
private readonly ILogger _logger;
|
2013-03-12 23:49:45 +01:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2013-10-02 18:08:58 +02:00
|
|
|
|
private readonly IUserDataManager _userDataRepository;
|
2013-06-18 21:16:27 +02:00
|
|
|
|
private readonly IItemRepository _itemRepo;
|
2013-02-22 02:26:35 +01:00
|
|
|
|
|
2013-09-18 20:49:06 +02:00
|
|
|
|
private readonly IImageProcessor _imageProcessor;
|
2014-01-30 06:20:18 +01:00
|
|
|
|
private readonly IServerConfigurationManager _config;
|
2014-02-07 21:30:41 +01:00
|
|
|
|
private readonly IFileSystem _fileSystem;
|
2014-02-21 19:48:15 +01:00
|
|
|
|
private readonly IProviderManager _providerManager;
|
2013-10-02 18:08:58 +02:00
|
|
|
|
|
2014-05-19 21:51:56 +02:00
|
|
|
|
private readonly Func<IChannelManager> _channelManagerFactory;
|
2014-07-22 18:36:34 +02:00
|
|
|
|
private readonly ISyncManager _syncManager;
|
2014-10-24 06:54:35 +02:00
|
|
|
|
private readonly IApplicationHost _appHost;
|
2015-01-24 20:03:55 +01:00
|
|
|
|
private readonly Func<IDeviceManager> _deviceManager;
|
2015-03-07 23:43:53 +01:00
|
|
|
|
private readonly Func<IMediaSourceManager> _mediaSourceManager;
|
2015-05-31 20:22:51 +02:00
|
|
|
|
private readonly Func<ILiveTvManager> _livetvManager;
|
2014-05-19 21:51:56 +02:00
|
|
|
|
|
2015-05-31 20:22:51 +02:00
|
|
|
|
public DtoService(ILogger logger, ILibraryManager libraryManager, IUserDataManager userDataRepository, IItemRepository itemRepo, IImageProcessor imageProcessor, IServerConfigurationManager config, IFileSystem fileSystem, IProviderManager providerManager, Func<IChannelManager> channelManagerFactory, ISyncManager syncManager, IApplicationHost appHost, Func<IDeviceManager> deviceManager, Func<IMediaSourceManager> mediaSourceManager, Func<ILiveTvManager> livetvManager)
|
2013-02-22 02:26:35 +01:00
|
|
|
|
{
|
2013-03-01 22:22:34 +01:00
|
|
|
|
_logger = logger;
|
2013-03-12 23:49:45 +01:00
|
|
|
|
_libraryManager = libraryManager;
|
2013-04-13 20:02:30 +02:00
|
|
|
|
_userDataRepository = userDataRepository;
|
2013-06-18 21:16:27 +02:00
|
|
|
|
_itemRepo = itemRepo;
|
2013-09-18 20:49:06 +02:00
|
|
|
|
_imageProcessor = imageProcessor;
|
2014-01-30 06:20:18 +01:00
|
|
|
|
_config = config;
|
2014-02-07 21:30:41 +01:00
|
|
|
|
_fileSystem = fileSystem;
|
2014-02-21 19:48:15 +01:00
|
|
|
|
_providerManager = providerManager;
|
2014-05-19 21:51:56 +02:00
|
|
|
|
_channelManagerFactory = channelManagerFactory;
|
2014-07-22 18:36:34 +02:00
|
|
|
|
_syncManager = syncManager;
|
2014-10-24 06:54:35 +02:00
|
|
|
|
_appHost = appHost;
|
2015-01-24 20:03:55 +01:00
|
|
|
|
_deviceManager = deviceManager;
|
2015-03-07 23:43:53 +01:00
|
|
|
|
_mediaSourceManager = mediaSourceManager;
|
2015-05-31 20:22:51 +02:00
|
|
|
|
_livetvManager = livetvManager;
|
2013-09-17 04:08:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 02:33:05 +01:00
|
|
|
|
/// <summary>
|
2013-05-15 18:56:38 +02:00
|
|
|
|
/// Converts a BaseItem to a DTOBaseItem
|
2013-02-21 02:33:05 +01:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="fields">The fields.</param>
|
2013-05-15 18:56:38 +02:00
|
|
|
|
/// <param name="user">The user.</param>
|
2013-07-30 16:51:28 +02:00
|
|
|
|
/// <param name="owner">The owner.</param>
|
2013-02-21 02:33:05 +01:00
|
|
|
|
/// <returns>Task{DtoBaseItem}.</returns>
|
|
|
|
|
/// <exception cref="System.ArgumentNullException">item</exception>
|
2013-09-17 04:44:06 +02:00
|
|
|
|
public BaseItemDto GetBaseItemDto(BaseItem item, List<ItemFields> fields, User user = null, BaseItem owner = null)
|
2014-06-28 21:35:30 +02:00
|
|
|
|
{
|
2014-11-30 20:01:33 +01:00
|
|
|
|
var options = new DtoOptions
|
|
|
|
|
{
|
2014-12-21 06:57:06 +01:00
|
|
|
|
Fields = fields
|
2014-11-30 20:01:33 +01:00
|
|
|
|
};
|
2015-01-24 20:03:55 +01:00
|
|
|
|
|
2014-11-30 20:01:33 +01:00
|
|
|
|
return GetBaseItemDto(item, options, user, owner);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-24 20:03:55 +01:00
|
|
|
|
public IEnumerable<BaseItemDto> GetBaseItemDtos(IEnumerable<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null)
|
|
|
|
|
{
|
2015-06-02 19:46:44 +02:00
|
|
|
|
var syncJobItems = GetSyncedItemProgress(options);
|
2015-07-12 21:33:00 +02:00
|
|
|
|
var syncDictionary = GetSyncedItemProgressDictionary(syncJobItems);
|
2015-01-24 20:03:55 +01:00
|
|
|
|
|
|
|
|
|
var list = new List<BaseItemDto>();
|
2016-03-02 19:42:39 +01:00
|
|
|
|
var programTuples = new List<Tuple<BaseItem, BaseItemDto>> { };
|
2016-03-22 07:49:36 +01:00
|
|
|
|
var channelTuples = new List<Tuple<BaseItemDto, LiveTvChannel>> { };
|
2015-01-24 20:03:55 +01:00
|
|
|
|
|
|
|
|
|
foreach (var item in items)
|
|
|
|
|
{
|
2015-06-02 19:46:44 +02:00
|
|
|
|
var dto = GetBaseItemDtoInternal(item, options, syncDictionary, user, owner);
|
2015-01-24 20:03:55 +01:00
|
|
|
|
|
2016-03-22 07:49:36 +01:00
|
|
|
|
var tvChannel = item as LiveTvChannel;
|
|
|
|
|
if (tvChannel != null)
|
|
|
|
|
{
|
|
|
|
|
channelTuples.Add(new Tuple<BaseItemDto, LiveTvChannel>(dto, tvChannel));
|
|
|
|
|
}
|
|
|
|
|
else if (item is LiveTvProgram)
|
2016-03-02 19:42:39 +01:00
|
|
|
|
{
|
|
|
|
|
programTuples.Add(new Tuple<BaseItem, BaseItemDto>(item, dto));
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-24 20:03:55 +01:00
|
|
|
|
var byName = item as IItemByName;
|
|
|
|
|
|
2015-08-31 06:57:12 +02:00
|
|
|
|
if (byName != null)
|
2015-01-24 20:03:55 +01:00
|
|
|
|
{
|
2015-04-04 04:34:53 +02:00
|
|
|
|
if (options.Fields.Contains(ItemFields.ItemCounts))
|
2015-03-26 05:44:24 +01:00
|
|
|
|
{
|
2016-05-11 04:21:28 +02:00
|
|
|
|
var libraryItems = byName.GetTaggedItems(new InternalItemsQuery(user)
|
|
|
|
|
{
|
|
|
|
|
Recursive = true
|
|
|
|
|
});
|
2015-01-24 20:03:55 +01:00
|
|
|
|
|
2015-03-26 05:44:24 +01:00
|
|
|
|
SetItemByNameInfo(item, dto, libraryItems.ToList(), user);
|
|
|
|
|
}
|
2015-01-24 20:03:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-02 19:46:44 +02:00
|
|
|
|
FillSyncInfo(dto, item, syncJobItems, options, user);
|
2015-01-24 20:03:55 +01:00
|
|
|
|
|
|
|
|
|
list.Add(dto);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 19:42:39 +01:00
|
|
|
|
if (programTuples.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var task = _livetvManager().AddInfoToProgramDto(programTuples, options.Fields, user);
|
|
|
|
|
Task.WaitAll(task);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-22 07:49:36 +01:00
|
|
|
|
if (channelTuples.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
_livetvManager().AddChannelInfo(channelTuples, options, user);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-24 20:03:55 +01:00
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-12 21:33:00 +02:00
|
|
|
|
private Dictionary<string, SyncedItemProgress> GetSyncedItemProgressDictionary(IEnumerable<SyncedItemProgress> items)
|
|
|
|
|
{
|
|
|
|
|
var dict = new Dictionary<string, SyncedItemProgress>();
|
|
|
|
|
|
|
|
|
|
foreach (var item in items)
|
|
|
|
|
{
|
|
|
|
|
dict[item.ItemId] = item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dict;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 20:01:33 +01:00
|
|
|
|
public BaseItemDto GetBaseItemDto(BaseItem item, DtoOptions options, User user = null, BaseItem owner = null)
|
|
|
|
|
{
|
2015-06-02 19:46:44 +02:00
|
|
|
|
var syncProgress = GetSyncedItemProgress(options);
|
|
|
|
|
|
2015-07-12 21:33:00 +02:00
|
|
|
|
var dto = GetBaseItemDtoInternal(item, options, GetSyncedItemProgressDictionary(syncProgress), user, owner);
|
2016-03-22 07:49:36 +01:00
|
|
|
|
var tvChannel = item as LiveTvChannel;
|
|
|
|
|
if (tvChannel != null)
|
|
|
|
|
{
|
|
|
|
|
var list = new List<Tuple<BaseItemDto, LiveTvChannel>> { new Tuple<BaseItemDto, LiveTvChannel>(dto, tvChannel) };
|
|
|
|
|
_livetvManager().AddChannelInfo(list, options, user);
|
|
|
|
|
}
|
|
|
|
|
else if (item is LiveTvProgram)
|
2016-03-02 19:42:39 +01:00
|
|
|
|
{
|
|
|
|
|
var list = new List<Tuple<BaseItem, BaseItemDto>> { new Tuple<BaseItem, BaseItemDto>(item, dto) };
|
|
|
|
|
var task = _livetvManager().AddInfoToProgramDto(list, options.Fields, user);
|
|
|
|
|
Task.WaitAll(task);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-28 21:35:30 +02:00
|
|
|
|
var byName = item as IItemByName;
|
|
|
|
|
|
2015-08-31 06:57:12 +02:00
|
|
|
|
if (byName != null)
|
2014-06-28 21:35:30 +02:00
|
|
|
|
{
|
2015-04-04 04:34:53 +02:00
|
|
|
|
if (options.Fields.Contains(ItemFields.ItemCounts))
|
2015-03-26 05:44:24 +01:00
|
|
|
|
{
|
2015-07-08 18:10:34 +02:00
|
|
|
|
SetItemByNameInfo(item, dto, GetTaggedItems(byName, user), user);
|
2015-03-26 05:44:24 +01:00
|
|
|
|
}
|
2014-06-28 21:35:30 +02:00
|
|
|
|
|
2015-06-02 19:46:44 +02:00
|
|
|
|
FillSyncInfo(dto, item, options, user, syncProgress);
|
2014-06-28 21:35:30 +02:00
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-02 19:46:44 +02:00
|
|
|
|
FillSyncInfo(dto, item, options, user, syncProgress);
|
2015-01-24 20:03:55 +01:00
|
|
|
|
|
2014-07-28 00:01:29 +02:00
|
|
|
|
return dto;
|
2014-06-28 21:35:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-08 18:10:34 +02:00
|
|
|
|
private List<BaseItem> GetTaggedItems(IItemByName byName, User user)
|
|
|
|
|
{
|
2016-05-10 21:20:17 +02:00
|
|
|
|
var items = byName.GetTaggedItems(new InternalItemsQuery(user)
|
2015-07-08 18:10:34 +02:00
|
|
|
|
{
|
2016-05-10 21:20:17 +02:00
|
|
|
|
Recursive = true
|
2015-07-08 18:10:34 +02:00
|
|
|
|
|
2016-05-10 21:20:17 +02:00
|
|
|
|
}).ToList();
|
2015-07-08 18:10:34 +02:00
|
|
|
|
|
2016-05-10 21:20:17 +02:00
|
|
|
|
return items;
|
2015-07-08 18:10:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-02 19:46:44 +02:00
|
|
|
|
private SyncedItemProgress[] GetSyncedItemProgress(DtoOptions options)
|
2015-01-24 20:03:55 +01:00
|
|
|
|
{
|
|
|
|
|
if (!options.Fields.Contains(ItemFields.SyncInfo))
|
|
|
|
|
{
|
2015-07-27 07:03:34 +02:00
|
|
|
|
return new SyncedItemProgress[] { };
|
2015-01-24 20:03:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var deviceId = options.DeviceId;
|
|
|
|
|
if (string.IsNullOrWhiteSpace(deviceId))
|
|
|
|
|
{
|
2015-06-02 19:46:44 +02:00
|
|
|
|
return new SyncedItemProgress[] { };
|
2015-01-24 20:03:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var caps = _deviceManager().GetCapabilities(deviceId);
|
|
|
|
|
if (caps == null || !caps.SupportsSync)
|
|
|
|
|
{
|
2015-06-02 19:46:44 +02:00
|
|
|
|
return new SyncedItemProgress[] { };
|
2015-01-24 20:03:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-02 19:46:44 +02:00
|
|
|
|
return _syncManager.GetSyncedItemProgresses(new SyncJobItemQuery
|
2015-01-24 20:03:55 +01:00
|
|
|
|
{
|
2015-01-25 07:34:50 +01:00
|
|
|
|
TargetId = deviceId,
|
2015-04-04 04:16:42 +02:00
|
|
|
|
Statuses = new[]
|
2015-01-25 07:34:50 +01:00
|
|
|
|
{
|
|
|
|
|
SyncJobItemStatus.Converting,
|
|
|
|
|
SyncJobItemStatus.Queued,
|
2015-02-05 04:01:37 +01:00
|
|
|
|
SyncJobItemStatus.Transferring,
|
2015-06-02 19:46:44 +02:00
|
|
|
|
SyncJobItemStatus.ReadyToTransfer,
|
2015-04-04 04:16:42 +02:00
|
|
|
|
SyncJobItemStatus.Synced
|
|
|
|
|
}
|
2015-06-02 19:46:44 +02:00
|
|
|
|
}).Items;
|
2015-01-24 20:03:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-11 19:29:42 +01:00
|
|
|
|
public void FillSyncInfo(IEnumerable<Tuple<BaseItem, BaseItemDto>> tuples, DtoOptions options, User user)
|
2015-04-12 20:58:21 +02:00
|
|
|
|
{
|
|
|
|
|
if (options.Fields.Contains(ItemFields.SyncInfo))
|
|
|
|
|
{
|
2015-06-02 19:46:44 +02:00
|
|
|
|
var syncProgress = GetSyncedItemProgress(options);
|
2015-04-12 20:58:21 +02:00
|
|
|
|
|
2016-02-11 19:29:42 +01:00
|
|
|
|
foreach (var tuple in tuples)
|
2015-04-12 20:58:21 +02:00
|
|
|
|
{
|
2016-02-11 19:29:42 +01:00
|
|
|
|
var item = tuple.Item1;
|
2015-04-12 20:58:21 +02:00
|
|
|
|
|
2016-02-11 19:29:42 +01:00
|
|
|
|
FillSyncInfo(tuple.Item2, item, syncProgress, options, user);
|
2015-04-12 20:58:21 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-02 19:46:44 +02:00
|
|
|
|
private void FillSyncInfo(IHasSyncInfo dto, BaseItem item, DtoOptions options, User user, SyncedItemProgress[] syncProgress)
|
2015-01-24 20:03:55 +01:00
|
|
|
|
{
|
|
|
|
|
if (options.Fields.Contains(ItemFields.SyncInfo))
|
|
|
|
|
{
|
2015-02-11 21:23:07 +01:00
|
|
|
|
var userCanSync = user != null && user.Policy.EnableSync;
|
|
|
|
|
dto.SupportsSync = userCanSync && _syncManager.SupportsSync(item);
|
2015-01-24 20:03:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dto.SupportsSync ?? false)
|
|
|
|
|
{
|
2015-06-02 19:46:44 +02:00
|
|
|
|
dto.HasSyncJob = syncProgress.Any(i => i.Status != SyncJobItemStatus.Synced && string.Equals(i.ItemId, dto.Id, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
dto.IsSynced = syncProgress.Any(i => i.Status == SyncJobItemStatus.Synced && string.Equals(i.ItemId, dto.Id, StringComparison.OrdinalIgnoreCase));
|
2015-04-12 20:58:21 +02:00
|
|
|
|
|
|
|
|
|
if (dto.IsSynced.Value)
|
|
|
|
|
{
|
|
|
|
|
dto.SyncStatus = SyncJobItemStatus.Synced;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (dto.HasSyncJob.Value)
|
|
|
|
|
{
|
2016-04-30 20:22:54 +02:00
|
|
|
|
dto.SyncStatus = syncProgress.Where(i => string.Equals(i.ItemId, dto.Id, StringComparison.OrdinalIgnoreCase)).Select(i => i.Status).Max();
|
2015-04-12 20:58:21 +02:00
|
|
|
|
}
|
2015-01-24 20:03:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-02 19:46:44 +02:00
|
|
|
|
private void FillSyncInfo(IHasSyncInfo dto, BaseItem item, SyncedItemProgress[] syncProgress, DtoOptions options, User user)
|
2015-01-24 20:03:55 +01:00
|
|
|
|
{
|
|
|
|
|
if (options.Fields.Contains(ItemFields.SyncInfo))
|
|
|
|
|
{
|
2015-02-11 21:23:07 +01:00
|
|
|
|
var userCanSync = user != null && user.Policy.EnableSync;
|
|
|
|
|
dto.SupportsSync = userCanSync && _syncManager.SupportsSync(item);
|
2015-01-24 20:03:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dto.SupportsSync ?? false)
|
|
|
|
|
{
|
2015-06-02 19:46:44 +02:00
|
|
|
|
dto.HasSyncJob = syncProgress.Any(i => i.Status != SyncJobItemStatus.Synced && string.Equals(i.ItemId, dto.Id, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
dto.IsSynced = syncProgress.Any(i => i.Status == SyncJobItemStatus.Synced && string.Equals(i.ItemId, dto.Id, StringComparison.OrdinalIgnoreCase));
|
2015-04-12 20:58:21 +02:00
|
|
|
|
|
|
|
|
|
if (dto.IsSynced.Value)
|
|
|
|
|
{
|
|
|
|
|
dto.SyncStatus = SyncJobItemStatus.Synced;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (dto.HasSyncJob.Value)
|
|
|
|
|
{
|
2016-04-30 20:22:54 +02:00
|
|
|
|
dto.SyncStatus = syncProgress.Where(i => string.Equals(i.ItemId, dto.Id, StringComparison.OrdinalIgnoreCase)).Select(i => i.Status).Max();
|
2015-04-12 20:58:21 +02:00
|
|
|
|
}
|
2015-01-24 20:03:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-27 07:03:34 +02:00
|
|
|
|
private BaseItemDto GetBaseItemDtoInternal(BaseItem item, DtoOptions options, Dictionary<string, SyncedItemProgress> syncProgress, User user = null, BaseItem owner = null)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2014-11-30 20:01:33 +01:00
|
|
|
|
var fields = options.Fields;
|
|
|
|
|
|
2013-02-21 02:33:05 +01:00
|
|
|
|
if (item == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("item");
|
|
|
|
|
}
|
2013-05-15 18:56:38 +02:00
|
|
|
|
|
2013-02-21 02:33:05 +01:00
|
|
|
|
if (fields == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("fields");
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 06:54:35 +02:00
|
|
|
|
var dto = new BaseItemDto
|
|
|
|
|
{
|
|
|
|
|
ServerId = _appHost.SystemId
|
|
|
|
|
};
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2016-03-19 20:32:37 +01:00
|
|
|
|
if (item.SourceType == SourceType.Channel)
|
|
|
|
|
{
|
|
|
|
|
dto.SourceType = item.SourceType.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-03 04:59:27 +02:00
|
|
|
|
if (fields.Contains(ItemFields.People))
|
|
|
|
|
{
|
2013-09-17 04:08:18 +02:00
|
|
|
|
AttachPeople(dto, item);
|
2013-04-03 04:59:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.PrimaryImageAspectRatio))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-01-16 06:01:57 +01:00
|
|
|
|
AttachPrimaryImageAspectRatio(dto, item);
|
2013-04-03 04:59:27 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
// Have to use a catch-all unfortunately because some .net image methods throw plain Exceptions
|
|
|
|
|
_logger.ErrorException("Error generating PrimaryImageAspectRatio for {0}", ex, item.Name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-25 19:18:56 +02:00
|
|
|
|
if (fields.Contains(ItemFields.DisplayPreferencesId))
|
|
|
|
|
{
|
|
|
|
|
dto.DisplayPreferencesId = item.DisplayPreferencesId.ToString("N");
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-17 22:35:43 +02:00
|
|
|
|
if (user != null)
|
|
|
|
|
{
|
2015-06-02 19:46:44 +02:00
|
|
|
|
AttachUserSpecificInfo(dto, item, user, fields, syncProgress);
|
2013-06-17 22:35:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-14 20:24:20 +02:00
|
|
|
|
var hasMediaSources = item as IHasMediaSources;
|
|
|
|
|
if (hasMediaSources != null)
|
|
|
|
|
{
|
|
|
|
|
if (fields.Contains(ItemFields.MediaSources))
|
|
|
|
|
{
|
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
2015-03-31 18:24:16 +02:00
|
|
|
|
dto.MediaSources = _mediaSourceManager().GetStaticMediaSources(hasMediaSources, true).ToList();
|
2014-06-14 20:24:20 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-03-07 23:43:53 +01:00
|
|
|
|
dto.MediaSources = _mediaSourceManager().GetStaticMediaSources(hasMediaSources, true, user).ToList();
|
2014-06-14 20:24:20 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-04-04 04:16:42 +02:00
|
|
|
|
|
2013-09-17 04:08:18 +02:00
|
|
|
|
if (fields.Contains(ItemFields.Studios))
|
|
|
|
|
{
|
|
|
|
|
AttachStudios(dto, item);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 20:01:33 +01:00
|
|
|
|
AttachBasicFields(dto, item, owner, options);
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2015-07-29 22:31:15 +02:00
|
|
|
|
var collectionFolder = item as ICollectionFolder;
|
|
|
|
|
if (collectionFolder != null)
|
|
|
|
|
{
|
2015-11-19 06:19:54 +01:00
|
|
|
|
dto.OriginalCollectionType = collectionFolder.CollectionType;
|
|
|
|
|
|
2015-07-29 22:31:15 +02:00
|
|
|
|
dto.CollectionType = user == null ?
|
|
|
|
|
collectionFolder.CollectionType :
|
|
|
|
|
collectionFolder.GetViewType(user);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-06 06:39:07 +01:00
|
|
|
|
if (fields.Contains(ItemFields.CanDelete))
|
|
|
|
|
{
|
|
|
|
|
dto.CanDelete = user == null
|
|
|
|
|
? item.CanDelete()
|
|
|
|
|
: item.CanDelete(user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.CanDownload))
|
|
|
|
|
{
|
|
|
|
|
dto.CanDownload = user == null
|
|
|
|
|
? item.CanDownload()
|
|
|
|
|
: item.CanDownload(user);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-15 17:41:42 +02:00
|
|
|
|
if (fields.Contains(ItemFields.Etag))
|
|
|
|
|
{
|
|
|
|
|
dto.Etag = item.GetEtag(user);
|
|
|
|
|
}
|
2015-04-14 05:45:17 +02:00
|
|
|
|
|
2015-05-31 20:22:51 +02:00
|
|
|
|
if (item is ILiveTvRecording)
|
|
|
|
|
{
|
|
|
|
|
_livetvManager().AddInfoToRecordingDto(item, dto, user);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 02:33:05 +01:00
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-15 05:15:25 +02:00
|
|
|
|
public BaseItemDto GetItemByNameDto(BaseItem item, DtoOptions options, List<BaseItem> taggedItems, User user = null)
|
2013-09-10 20:56:00 +02:00
|
|
|
|
{
|
2015-06-02 19:46:44 +02:00
|
|
|
|
var syncProgress = GetSyncedItemProgress(options);
|
|
|
|
|
|
2015-07-12 21:33:00 +02:00
|
|
|
|
var dto = GetBaseItemDtoInternal(item, options, GetSyncedItemProgressDictionary(syncProgress), user);
|
2014-06-28 21:35:30 +02:00
|
|
|
|
|
2015-04-04 04:34:53 +02:00
|
|
|
|
if (options.Fields.Contains(ItemFields.ItemCounts))
|
2015-03-26 05:44:24 +01:00
|
|
|
|
{
|
|
|
|
|
SetItemByNameInfo(item, dto, taggedItems, user);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-02 19:46:44 +02:00
|
|
|
|
FillSyncInfo(dto, item, options, user, syncProgress);
|
2014-03-09 23:14:44 +01:00
|
|
|
|
|
2014-06-28 21:35:30 +02:00
|
|
|
|
return dto;
|
2014-03-09 23:14:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-28 21:35:30 +02:00
|
|
|
|
private void SetItemByNameInfo(BaseItem item, BaseItemDto dto, List<BaseItem> taggedItems, User user = null)
|
2014-03-09 23:14:44 +01:00
|
|
|
|
{
|
|
|
|
|
if (item is MusicArtist || item is MusicGenre)
|
2013-09-10 20:56:00 +02:00
|
|
|
|
{
|
2014-03-09 23:14:44 +01:00
|
|
|
|
dto.AlbumCount = taggedItems.Count(i => i is MusicAlbum);
|
|
|
|
|
dto.MusicVideoCount = taggedItems.Count(i => i is MusicVideo);
|
|
|
|
|
dto.SongCount = taggedItems.Count(i => i is Audio);
|
|
|
|
|
}
|
|
|
|
|
else if (item is GameGenre)
|
|
|
|
|
{
|
|
|
|
|
dto.GameCount = taggedItems.Count(i => i is Game);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// This populates them all and covers Genre, Person, Studio, Year
|
|
|
|
|
|
|
|
|
|
dto.AlbumCount = taggedItems.Count(i => i is MusicAlbum);
|
|
|
|
|
dto.EpisodeCount = taggedItems.Count(i => i is Episode);
|
|
|
|
|
dto.GameCount = taggedItems.Count(i => i is Game);
|
|
|
|
|
dto.MovieCount = taggedItems.Count(i => i is Movie);
|
2016-03-19 22:55:42 +01:00
|
|
|
|
dto.TrailerCount = taggedItems.Count(i => i is Trailer);
|
2014-03-09 23:14:44 +01:00
|
|
|
|
dto.MusicVideoCount = taggedItems.Count(i => i is MusicVideo);
|
|
|
|
|
dto.SeriesCount = taggedItems.Count(i => i is Series);
|
|
|
|
|
dto.SongCount = taggedItems.Count(i => i is Audio);
|
2013-09-10 20:56:00 +02:00
|
|
|
|
}
|
2013-12-02 22:46:22 +01:00
|
|
|
|
|
2014-03-09 23:14:44 +01:00
|
|
|
|
dto.ChildCount = taggedItems.Count;
|
2013-09-10 20:56:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 02:33:05 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Attaches the user specific info.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dto">The dto.</param>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="user">The user.</param>
|
|
|
|
|
/// <param name="fields">The fields.</param>
|
2015-06-02 19:46:44 +02:00
|
|
|
|
/// <param name="syncProgress">The synchronize progress.</param>
|
|
|
|
|
private void AttachUserSpecificInfo(BaseItemDto dto, BaseItem item, User user, List<ItemFields> fields, Dictionary<string, SyncedItemProgress> syncProgress)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
|
|
|
|
if (item.IsFolder)
|
|
|
|
|
{
|
2016-05-01 00:05:13 +02:00
|
|
|
|
var userData = _userDataRepository.GetUserData(user, item);
|
2014-07-04 04:22:57 +02:00
|
|
|
|
|
|
|
|
|
// Skip the user data manager because we've already looped through the recursive tree and don't want to do it twice
|
|
|
|
|
// TODO: Improve in future
|
|
|
|
|
dto.UserData = GetUserItemDataDto(userData);
|
|
|
|
|
|
2013-09-23 16:26:20 +02:00
|
|
|
|
var folder = (Folder)item;
|
2013-07-25 21:17:44 +02:00
|
|
|
|
|
2016-03-19 05:05:33 +01:00
|
|
|
|
if (item.SourceType == SourceType.Library)
|
2013-09-23 16:26:20 +02:00
|
|
|
|
{
|
2015-11-02 18:25:01 +01:00
|
|
|
|
dto.ChildCount = GetChildCount(folder, user);
|
|
|
|
|
|
2016-05-02 19:35:48 +02:00
|
|
|
|
if (folder.SupportsUserDataFromChildren)
|
2015-11-02 18:25:01 +01:00
|
|
|
|
{
|
|
|
|
|
SetSpecialCounts(folder, user, dto, fields, syncProgress);
|
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
2013-05-08 03:17:41 +02:00
|
|
|
|
|
2016-05-09 05:13:38 +02:00
|
|
|
|
if (fields.Contains(ItemFields.CumulativeRunTimeTicks))
|
|
|
|
|
{
|
2016-05-10 20:13:26 +02:00
|
|
|
|
dto.CumulativeRunTimeTicks = item.RunTimeTicks;
|
2016-05-09 05:13:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.DateLastMediaAdded))
|
|
|
|
|
{
|
|
|
|
|
dto.DateLastMediaAdded = folder.DateLastMediaAdded;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 07:38:13 +02:00
|
|
|
|
dto.UserData.Played = dto.UserData.PlayedPercentage.HasValue && dto.UserData.PlayedPercentage.Value >= 100;
|
2014-07-04 04:22:57 +02:00
|
|
|
|
}
|
2013-05-08 03:17:41 +02:00
|
|
|
|
|
2014-07-04 04:22:57 +02:00
|
|
|
|
else
|
2013-07-16 19:18:32 +02:00
|
|
|
|
{
|
2014-07-04 04:22:57 +02:00
|
|
|
|
dto.UserData = _userDataRepository.GetUserDataDto(item, user);
|
2013-05-08 03:17:41 +02:00
|
|
|
|
}
|
2014-02-21 06:35:56 +01:00
|
|
|
|
|
|
|
|
|
dto.PlayAccess = item.GetPlayAccess(user);
|
2014-12-27 06:08:39 +01:00
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.SeasonUserData))
|
|
|
|
|
{
|
|
|
|
|
var episode = item as Episode;
|
|
|
|
|
|
|
|
|
|
if (episode != null)
|
|
|
|
|
{
|
|
|
|
|
var season = episode.Season;
|
|
|
|
|
|
|
|
|
|
if (season != null)
|
|
|
|
|
{
|
|
|
|
|
dto.SeasonUserData = _userDataRepository.GetUserDataDto(season, user);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-06 07:10:53 +01:00
|
|
|
|
|
|
|
|
|
var userView = item as UserView;
|
|
|
|
|
if (userView != null)
|
|
|
|
|
{
|
|
|
|
|
dto.HasDynamicCategories = userView.ContainsDynamicCategories(user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var collectionFolder = item as ICollectionFolder;
|
|
|
|
|
if (collectionFolder != null)
|
|
|
|
|
{
|
|
|
|
|
dto.HasDynamicCategories = false;
|
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
2013-04-13 20:02:30 +02:00
|
|
|
|
|
2013-12-10 21:42:42 +01:00
|
|
|
|
private int GetChildCount(Folder folder, User user)
|
|
|
|
|
{
|
|
|
|
|
return folder.GetChildren(user, true)
|
|
|
|
|
.Count();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets client-side Id of a server-side BaseItem
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
|
/// <exception cref="System.ArgumentNullException">item</exception>
|
|
|
|
|
public string GetDtoId(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
if (item == null)
|
2013-04-12 16:13:47 +02:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
throw new ArgumentNullException("item");
|
2013-04-12 16:13:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
return item.Id.ToString("N");
|
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Converts a UserItemData to a DTOUserItemData
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="data">The data.</param>
|
|
|
|
|
/// <returns>DtoUserItemData.</returns>
|
|
|
|
|
/// <exception cref="System.ArgumentNullException"></exception>
|
|
|
|
|
public UserItemDataDto GetUserItemDataDto(UserItemData data)
|
|
|
|
|
{
|
|
|
|
|
if (data == null)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
throw new ArgumentNullException("data");
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
return new UserItemDataDto
|
2013-06-12 05:00:23 +02:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
IsFavorite = data.IsFavorite,
|
|
|
|
|
Likes = data.Likes,
|
|
|
|
|
PlaybackPositionTicks = data.PlaybackPositionTicks,
|
|
|
|
|
PlayCount = data.PlayCount,
|
|
|
|
|
Rating = data.Rating,
|
|
|
|
|
Played = data.Played,
|
2013-10-03 20:02:23 +02:00
|
|
|
|
LastPlayedDate = data.LastPlayedDate,
|
|
|
|
|
Key = data.Key
|
2013-09-04 19:02:19 +02:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
private void SetBookProperties(BaseItemDto dto, Book item)
|
|
|
|
|
{
|
|
|
|
|
dto.SeriesName = item.SeriesName;
|
|
|
|
|
}
|
2014-08-29 02:49:25 +02:00
|
|
|
|
private void SetPhotoProperties(BaseItemDto dto, Photo item)
|
|
|
|
|
{
|
|
|
|
|
dto.Width = item.Width;
|
|
|
|
|
dto.Height = item.Height;
|
|
|
|
|
dto.CameraMake = item.CameraMake;
|
|
|
|
|
dto.CameraModel = item.CameraModel;
|
|
|
|
|
dto.Software = item.Software;
|
|
|
|
|
dto.ExposureTime = item.ExposureTime;
|
|
|
|
|
dto.FocalLength = item.FocalLength;
|
|
|
|
|
dto.ImageOrientation = item.Orientation;
|
|
|
|
|
dto.Aperture = item.Aperture;
|
|
|
|
|
dto.ShutterSpeed = item.ShutterSpeed;
|
2014-08-30 16:26:29 +02:00
|
|
|
|
|
|
|
|
|
dto.Latitude = item.Latitude;
|
|
|
|
|
dto.Longitude = item.Longitude;
|
|
|
|
|
dto.Altitude = item.Altitude;
|
|
|
|
|
dto.IsoSpeedRating = item.IsoSpeedRating;
|
2014-10-12 17:18:26 +02:00
|
|
|
|
|
2014-08-30 16:26:29 +02:00
|
|
|
|
var album = item.Album;
|
|
|
|
|
|
|
|
|
|
if (album != null)
|
|
|
|
|
{
|
2014-09-03 04:30:24 +02:00
|
|
|
|
dto.Album = album.Name;
|
|
|
|
|
dto.AlbumId = album.Id.ToString("N");
|
2014-08-30 16:26:29 +02:00
|
|
|
|
}
|
2014-08-29 02:49:25 +02:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
private void SetMusicVideoProperties(BaseItemDto dto, MusicVideo item)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(item.Album))
|
|
|
|
|
{
|
2016-05-11 16:36:28 +02:00
|
|
|
|
var parentAlbum = _libraryManager.GetItemList(new InternalItemsQuery
|
|
|
|
|
{
|
|
|
|
|
IncludeItemTypes = new[] { typeof(MusicAlbum).Name },
|
|
|
|
|
Name = item.Album
|
|
|
|
|
|
|
|
|
|
}).FirstOrDefault();
|
2013-07-06 02:19:44 +02:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
if (parentAlbum != null)
|
2013-07-06 02:19:44 +02:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.AlbumId = GetDtoId(parentAlbum);
|
2013-07-06 02:19:44 +02:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.Album = item.Album;
|
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
private void SetGameProperties(BaseItemDto dto, Game item)
|
|
|
|
|
{
|
|
|
|
|
dto.Players = item.PlayersSupported;
|
|
|
|
|
dto.GameSystem = item.GameSystem;
|
2014-04-27 05:42:05 +02:00
|
|
|
|
dto.MultiPartGameFiles = item.MultiPartGameFiles;
|
2013-09-04 19:02:19 +02:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-10-27 22:40:42 +01:00
|
|
|
|
private void SetGameSystemProperties(BaseItemDto dto, GameSystem item)
|
|
|
|
|
{
|
|
|
|
|
dto.GameSystem = item.GameSystemName;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 20:01:33 +01:00
|
|
|
|
private List<string> GetBackdropImageTags(BaseItem item, int limit)
|
2013-09-04 19:02:19 +02:00
|
|
|
|
{
|
2014-11-30 20:01:33 +01:00
|
|
|
|
return GetCacheTags(item, ImageType.Backdrop, limit).ToList();
|
2013-09-04 19:02:19 +02:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2014-11-30 20:01:33 +01:00
|
|
|
|
private List<string> GetScreenshotImageTags(BaseItem item, int limit)
|
2013-09-04 19:02:19 +02:00
|
|
|
|
{
|
2013-12-05 17:50:21 +01:00
|
|
|
|
var hasScreenshots = item as IHasScreenshots;
|
|
|
|
|
if (hasScreenshots == null)
|
|
|
|
|
{
|
2014-05-08 22:09:53 +02:00
|
|
|
|
return new List<string>();
|
2013-12-05 17:50:21 +01:00
|
|
|
|
}
|
2014-11-30 20:01:33 +01:00
|
|
|
|
return GetCacheTags(item, ImageType.Screenshot, limit).ToList();
|
2014-02-07 21:30:41 +01:00
|
|
|
|
}
|
2013-12-05 17:50:21 +01:00
|
|
|
|
|
2014-11-30 20:01:33 +01:00
|
|
|
|
private IEnumerable<string> GetCacheTags(BaseItem item, ImageType type, int limit)
|
2014-02-07 21:30:41 +01:00
|
|
|
|
{
|
|
|
|
|
return item.GetImages(type)
|
2016-02-21 00:06:57 +01:00
|
|
|
|
// Convert to a list now in case GetImageCacheTag is slow
|
|
|
|
|
.ToList()
|
2014-02-07 21:30:41 +01:00
|
|
|
|
.Select(p => GetImageCacheTag(item, p))
|
2014-05-08 22:09:53 +02:00
|
|
|
|
.Where(i => i != null)
|
2014-11-30 20:01:33 +01:00
|
|
|
|
.Take(limit)
|
2013-09-04 19:02:19 +02:00
|
|
|
|
.ToList();
|
|
|
|
|
}
|
2013-03-13 03:10:43 +01:00
|
|
|
|
|
2014-05-08 22:09:53 +02:00
|
|
|
|
private string GetImageCacheTag(BaseItem item, ImageType type)
|
2014-02-07 21:30:41 +01:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _imageProcessor.GetImageCacheTag(item, type);
|
|
|
|
|
}
|
2014-04-13 19:27:13 +02:00
|
|
|
|
catch (Exception ex)
|
2014-02-07 21:30:41 +01:00
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error getting {0} image info", ex, type);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 22:09:53 +02:00
|
|
|
|
private string GetImageCacheTag(BaseItem item, ItemImageInfo image)
|
2013-09-04 19:02:19 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2014-02-07 21:30:41 +01:00
|
|
|
|
return _imageProcessor.GetImageCacheTag(item, image);
|
2013-03-12 23:49:45 +01:00
|
|
|
|
}
|
2014-04-13 19:27:13 +02:00
|
|
|
|
catch (Exception ex)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2014-02-07 21:30:41 +01:00
|
|
|
|
_logger.ErrorException("Error getting {0} image info for {1}", ex, image.Type, image.Path);
|
2013-09-04 19:02:19 +02:00
|
|
|
|
return null;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
2013-09-17 04:08:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 20:56:00 +02:00
|
|
|
|
/// <summary>
|
2013-09-04 19:02:19 +02:00
|
|
|
|
/// Attaches People DTO's to a DTOBaseItem
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dto">The dto.</param>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
2013-09-17 04:08:18 +02:00
|
|
|
|
private void AttachPeople(BaseItemDto dto, BaseItem item)
|
2013-09-04 19:02:19 +02:00
|
|
|
|
{
|
|
|
|
|
// Ordering by person type to ensure actors and artists are at the front.
|
|
|
|
|
// This is taking advantage of the fact that they both begin with A
|
|
|
|
|
// This should be improved in the future
|
2015-06-21 05:35:22 +02:00
|
|
|
|
var people = _libraryManager.GetPeople(item).OrderBy(i => i.SortOrder ?? int.MaxValue)
|
2014-06-30 15:28:38 +02:00
|
|
|
|
.ThenBy(i =>
|
|
|
|
|
{
|
|
|
|
|
if (i.IsType(PersonType.Actor))
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (i.IsType(PersonType.GuestStar))
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (i.IsType(PersonType.Director))
|
|
|
|
|
{
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
if (i.IsType(PersonType.Writer))
|
|
|
|
|
{
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
if (i.IsType(PersonType.Producer))
|
|
|
|
|
{
|
|
|
|
|
return 4;
|
|
|
|
|
}
|
|
|
|
|
if (i.IsType(PersonType.Composer))
|
|
|
|
|
{
|
|
|
|
|
return 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 10;
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2014-11-21 15:28:30 +01:00
|
|
|
|
var list = new List<BaseItemPerson>();
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-17 04:08:18 +02:00
|
|
|
|
var dictionary = people.Select(p => p.Name)
|
2013-09-04 19:02:19 +02:00
|
|
|
|
.Distinct(StringComparer.OrdinalIgnoreCase).Select(c =>
|
2013-09-17 04:08:18 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _libraryManager.GetPerson(c);
|
|
|
|
|
}
|
2014-08-25 05:54:45 +02:00
|
|
|
|
catch (Exception ex)
|
2013-09-04 19:02:19 +02:00
|
|
|
|
{
|
2013-09-17 04:08:18 +02:00
|
|
|
|
_logger.ErrorException("Error getting person {0}", ex, c);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}).Where(i => i != null)
|
2015-07-01 17:47:41 +02:00
|
|
|
|
.DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
|
2013-09-04 19:02:19 +02:00
|
|
|
|
.ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < people.Count; i++)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
var person = people[i];
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
var baseItemPerson = new BaseItemPerson
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
Name = person.Name,
|
|
|
|
|
Role = person.Role,
|
|
|
|
|
Type = person.Type
|
|
|
|
|
};
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
Person entity;
|
|
|
|
|
|
|
|
|
|
if (dictionary.TryGetValue(person.Name, out entity))
|
|
|
|
|
{
|
2014-02-07 21:30:41 +01:00
|
|
|
|
baseItemPerson.PrimaryImageTag = GetImageCacheTag(entity, ImageType.Primary);
|
2014-05-12 00:38:10 +02:00
|
|
|
|
baseItemPerson.Id = entity.Id.ToString("N");
|
2014-11-21 15:28:30 +01:00
|
|
|
|
list.Add(baseItemPerson);
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-21 15:28:30 +01:00
|
|
|
|
|
|
|
|
|
dto.People = list.ToArray();
|
2013-09-04 19:02:19 +02:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Attaches the studios.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dto">The dto.</param>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
2013-09-17 04:08:18 +02:00
|
|
|
|
private void AttachStudios(BaseItemDto dto, BaseItem item)
|
2013-09-04 19:02:19 +02:00
|
|
|
|
{
|
|
|
|
|
var studios = item.Studios.ToList();
|
|
|
|
|
|
|
|
|
|
dto.Studios = new StudioDto[studios.Count];
|
|
|
|
|
|
2013-09-17 04:08:18 +02:00
|
|
|
|
var dictionary = studios.Distinct(StringComparer.OrdinalIgnoreCase).Select(name =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _libraryManager.GetStudio(name);
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error getting studio {0}", ex, name);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.Where(i => i != null)
|
2015-07-02 07:08:05 +02:00
|
|
|
|
.DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
|
2013-09-17 04:08:18 +02:00
|
|
|
|
.ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);
|
2013-09-04 19:02:19 +02:00
|
|
|
|
|
|
|
|
|
for (var i = 0; i < studios.Count; i++)
|
2013-07-08 21:31:45 +02:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
var studio = studios[i];
|
2013-07-08 21:31:45 +02:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
var studioDto = new StudioDto
|
2013-07-08 21:31:45 +02:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
Name = studio
|
|
|
|
|
};
|
2013-07-08 21:31:45 +02:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
Studio entity;
|
|
|
|
|
|
|
|
|
|
if (dictionary.TryGetValue(studio, out entity))
|
|
|
|
|
{
|
2014-07-01 23:13:32 +02:00
|
|
|
|
studioDto.Id = entity.Id.ToString("N");
|
2014-02-07 21:30:41 +01:00
|
|
|
|
studioDto.PrimaryImageTag = GetImageCacheTag(entity, ImageType.Primary);
|
2013-07-08 21:31:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.Studios[i] = studioDto;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
2013-09-04 19:02:19 +02:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// If an item does not any backdrops, this can be used to find the first parent that does have one
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="owner">The owner.</param>
|
|
|
|
|
/// <returns>BaseItem.</returns>
|
|
|
|
|
private BaseItem GetParentBackdropItem(BaseItem item, BaseItem owner)
|
|
|
|
|
{
|
2015-11-11 15:56:31 +01:00
|
|
|
|
var parent = item.GetParent() ?? owner;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
while (parent != null)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2014-02-07 21:30:41 +01:00
|
|
|
|
if (parent.GetImages(ImageType.Backdrop).Any())
|
2013-09-04 19:02:19 +02:00
|
|
|
|
{
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-11 15:56:31 +01:00
|
|
|
|
parent = parent.GetParent();
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
return null;
|
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// If an item does not have a logo, this can be used to find the first parent that does have one
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="type">The type.</param>
|
|
|
|
|
/// <param name="owner">The owner.</param>
|
|
|
|
|
/// <returns>BaseItem.</returns>
|
|
|
|
|
private BaseItem GetParentImageItem(BaseItem item, ImageType type, BaseItem owner)
|
|
|
|
|
{
|
2015-11-11 15:56:31 +01:00
|
|
|
|
var parent = item.GetParent() ?? owner;
|
2013-09-04 19:02:19 +02:00
|
|
|
|
|
|
|
|
|
while (parent != null)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
if (parent.HasImage(type))
|
|
|
|
|
{
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-11 15:56:31 +01:00
|
|
|
|
parent = parent.GetParent();
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the chapter info dto.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="chapterInfo">The chapter info.</param>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns>ChapterInfoDto.</returns>
|
2014-10-12 17:18:26 +02:00
|
|
|
|
private ChapterInfoDto GetChapterInfoDto(ChapterInfo chapterInfo, BaseItem item)
|
2013-09-04 19:02:19 +02:00
|
|
|
|
{
|
|
|
|
|
var dto = new ChapterInfoDto
|
2013-06-25 03:22:21 +02:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
Name = chapterInfo.Name,
|
|
|
|
|
StartPositionTicks = chapterInfo.StartPositionTicks
|
|
|
|
|
};
|
2013-07-06 02:19:44 +02:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
if (!string.IsNullOrEmpty(chapterInfo.ImagePath))
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2014-02-07 21:30:41 +01:00
|
|
|
|
dto.ImageTag = GetImageCacheTag(item, new ItemImageInfo
|
|
|
|
|
{
|
|
|
|
|
Path = chapterInfo.ImagePath,
|
|
|
|
|
Type = ImageType.Chapter,
|
2015-04-19 21:17:17 +02:00
|
|
|
|
DateModified = _fileSystem.GetLastWriteTimeUtc(chapterInfo.ImagePath)
|
2014-02-07 21:30:41 +01:00
|
|
|
|
});
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-12 17:18:26 +02:00
|
|
|
|
public List<ChapterInfoDto> GetChapterInfoDtos(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
return _itemRepo.GetChapters(item.Id)
|
|
|
|
|
.Select(c => GetChapterInfoDto(c, item))
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets simple property values on a DTOBaseItem
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dto">The dto.</param>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="owner">The owner.</param>
|
2014-11-30 20:01:33 +01:00
|
|
|
|
/// <param name="options">The options.</param>
|
|
|
|
|
private void AttachBasicFields(BaseItemDto dto, BaseItem item, BaseItem owner, DtoOptions options)
|
2013-09-04 19:02:19 +02:00
|
|
|
|
{
|
2014-11-30 20:01:33 +01:00
|
|
|
|
var fields = options.Fields;
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
if (fields.Contains(ItemFields.DateCreated))
|
2013-05-24 06:02:42 +02:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.DateCreated = item.DateCreated;
|
2013-05-24 06:02:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-21 17:55:47 +01:00
|
|
|
|
if (fields.Contains(ItemFields.DisplayMediaType))
|
|
|
|
|
{
|
|
|
|
|
dto.DisplayMediaType = item.DisplayMediaType;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-21 06:57:06 +01:00
|
|
|
|
if (fields.Contains(ItemFields.Settings))
|
2013-09-04 19:02:19 +02:00
|
|
|
|
{
|
|
|
|
|
dto.LockedFields = item.LockedFields;
|
2014-03-22 17:16:43 +01:00
|
|
|
|
dto.LockData = item.IsLocked;
|
2014-03-24 18:54:45 +01:00
|
|
|
|
dto.ForcedSortName = item.ForcedSortName;
|
2013-07-16 18:03:28 +02:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-12-02 17:16:03 +01:00
|
|
|
|
var hasBudget = item as IHasBudget;
|
|
|
|
|
if (hasBudget != null)
|
2013-07-16 18:03:28 +02:00
|
|
|
|
{
|
2013-12-02 17:16:03 +01:00
|
|
|
|
if (fields.Contains(ItemFields.Budget))
|
|
|
|
|
{
|
|
|
|
|
dto.Budget = hasBudget.Budget;
|
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-12-02 17:16:03 +01:00
|
|
|
|
if (fields.Contains(ItemFields.Revenue))
|
|
|
|
|
{
|
|
|
|
|
dto.Revenue = hasBudget.Revenue;
|
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
2013-04-25 00:34:38 +02:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.EndDate = item.EndDate;
|
2013-04-25 00:34:38 +02:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
if (fields.Contains(ItemFields.HomePageUrl))
|
2013-04-25 00:34:38 +02:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.HomePageUrl = item.HomePageUrl;
|
2013-04-25 00:34:38 +02:00
|
|
|
|
}
|
2013-07-12 21:56:40 +02:00
|
|
|
|
|
2014-02-21 19:48:15 +01:00
|
|
|
|
if (fields.Contains(ItemFields.ExternalUrls))
|
|
|
|
|
{
|
|
|
|
|
dto.ExternalUrls = _providerManager.GetExternalUrls(item).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
if (fields.Contains(ItemFields.Tags))
|
|
|
|
|
{
|
2013-12-05 17:50:21 +01:00
|
|
|
|
var hasTags = item as IHasTags;
|
|
|
|
|
if (hasTags != null)
|
|
|
|
|
{
|
|
|
|
|
dto.Tags = hasTags.Tags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dto.Tags == null)
|
|
|
|
|
{
|
|
|
|
|
dto.Tags = new List<string>();
|
|
|
|
|
}
|
2013-09-04 19:02:19 +02:00
|
|
|
|
}
|
2013-07-12 21:56:40 +02:00
|
|
|
|
|
2014-01-14 16:50:39 +01:00
|
|
|
|
if (fields.Contains(ItemFields.Keywords))
|
|
|
|
|
{
|
2014-02-07 21:30:41 +01:00
|
|
|
|
var hasTags = item as IHasKeywords;
|
2014-01-14 16:50:39 +01:00
|
|
|
|
if (hasTags != null)
|
|
|
|
|
{
|
|
|
|
|
dto.Keywords = hasTags.Keywords;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dto.Keywords == null)
|
|
|
|
|
{
|
|
|
|
|
dto.Keywords = new List<string>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
if (fields.Contains(ItemFields.ProductionLocations))
|
2013-07-12 21:56:40 +02:00
|
|
|
|
{
|
2013-12-05 17:50:21 +01:00
|
|
|
|
SetProductionLocations(item, dto);
|
2013-07-12 21:56:40 +02:00
|
|
|
|
}
|
2013-08-31 01:55:17 +02:00
|
|
|
|
|
2013-11-20 04:15:48 +01:00
|
|
|
|
var hasAspectRatio = item as IHasAspectRatio;
|
|
|
|
|
if (hasAspectRatio != null)
|
|
|
|
|
{
|
|
|
|
|
dto.AspectRatio = hasAspectRatio.AspectRatio;
|
|
|
|
|
}
|
2013-08-31 01:55:17 +02:00
|
|
|
|
|
2014-12-20 19:56:32 +01:00
|
|
|
|
if (fields.Contains(ItemFields.Metascore))
|
2014-01-15 06:01:58 +01:00
|
|
|
|
{
|
2014-11-30 20:01:33 +01:00
|
|
|
|
var hasMetascore = item as IHasMetascore;
|
|
|
|
|
if (hasMetascore != null)
|
|
|
|
|
{
|
|
|
|
|
dto.Metascore = hasMetascore.Metascore;
|
|
|
|
|
}
|
2014-01-15 06:01:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.AwardSummary))
|
|
|
|
|
{
|
|
|
|
|
var hasAwards = item as IHasAwards;
|
|
|
|
|
if (hasAwards != null)
|
|
|
|
|
{
|
|
|
|
|
dto.AwardSummary = hasAwards.AwardSummary;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 20:01:33 +01:00
|
|
|
|
var backdropLimit = options.GetImageLimit(ImageType.Backdrop);
|
|
|
|
|
if (backdropLimit > 0)
|
|
|
|
|
{
|
|
|
|
|
dto.BackdropImageTags = GetBackdropImageTags(item, backdropLimit);
|
|
|
|
|
}
|
2013-09-18 04:43:34 +02:00
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.ScreenshotImageTags))
|
|
|
|
|
{
|
2014-11-30 20:01:33 +01:00
|
|
|
|
var screenshotLimit = options.GetImageLimit(ImageType.Screenshot);
|
|
|
|
|
if (screenshotLimit > 0)
|
|
|
|
|
{
|
|
|
|
|
dto.ScreenshotImageTags = GetScreenshotImageTags(item, screenshotLimit);
|
|
|
|
|
}
|
2013-09-18 04:43:34 +02:00
|
|
|
|
}
|
2013-09-04 19:02:19 +02:00
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.Genres))
|
2013-08-31 01:55:17 +02:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.Genres = item.Genres;
|
2013-08-31 01:55:17 +02:00
|
|
|
|
}
|
2013-07-12 21:56:40 +02:00
|
|
|
|
|
2014-05-08 22:09:53 +02:00
|
|
|
|
dto.ImageTags = new Dictionary<ImageType, string>();
|
2013-08-31 03:08:32 +02:00
|
|
|
|
|
2014-02-07 21:30:41 +01:00
|
|
|
|
// Prevent implicitly captured closure
|
|
|
|
|
var currentItem = item;
|
2015-02-21 08:32:49 +01:00
|
|
|
|
foreach (var image in currentItem.ImageInfos.Where(i => !currentItem.AllowsMultipleImages(i.Type))
|
|
|
|
|
.ToList())
|
2013-07-23 02:03:33 +02:00
|
|
|
|
{
|
2014-11-30 20:01:33 +01:00
|
|
|
|
if (options.GetImageLimit(image.Type) > 0)
|
2013-07-23 02:03:33 +02:00
|
|
|
|
{
|
2014-11-30 20:01:33 +01:00
|
|
|
|
var tag = GetImageCacheTag(item, image);
|
|
|
|
|
|
|
|
|
|
if (tag != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ImageTags[image.Type] = tag;
|
|
|
|
|
}
|
2013-07-23 02:03:33 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.Id = GetDtoId(item);
|
|
|
|
|
dto.IndexNumber = item.IndexNumber;
|
|
|
|
|
dto.IsFolder = item.IsFolder;
|
|
|
|
|
dto.MediaType = item.MediaType;
|
|
|
|
|
dto.LocationType = item.LocationType;
|
2015-10-28 20:40:38 +01:00
|
|
|
|
if (item.IsHD.HasValue && item.IsHD.Value)
|
|
|
|
|
{
|
|
|
|
|
dto.IsHD = item.IsHD;
|
|
|
|
|
}
|
|
|
|
|
dto.Audio = item.Audio;
|
2013-09-11 19:54:59 +02:00
|
|
|
|
|
2015-09-29 19:35:23 +02:00
|
|
|
|
dto.PreferredMetadataCountryCode = item.PreferredMetadataCountryCode;
|
|
|
|
|
dto.PreferredMetadataLanguage = item.PreferredMetadataLanguage;
|
2013-12-05 17:50:21 +01:00
|
|
|
|
|
2013-11-06 17:06:16 +01:00
|
|
|
|
var hasCriticRating = item as IHasCriticRating;
|
|
|
|
|
if (hasCriticRating != null)
|
2013-09-04 19:02:19 +02:00
|
|
|
|
{
|
2013-11-06 17:06:16 +01:00
|
|
|
|
dto.CriticRating = hasCriticRating.CriticRating;
|
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.CriticRatingSummary))
|
|
|
|
|
{
|
|
|
|
|
dto.CriticRatingSummary = hasCriticRating.CriticRatingSummary;
|
|
|
|
|
}
|
2013-09-04 19:02:19 +02:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-12-02 17:46:25 +01:00
|
|
|
|
var hasTrailers = item as IHasTrailers;
|
|
|
|
|
if (hasTrailers != null)
|
|
|
|
|
{
|
2014-12-11 07:20:28 +01:00
|
|
|
|
dto.LocalTrailerCount = hasTrailers.GetTrailerIds().Count;
|
2013-12-02 17:46:25 +01:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2014-01-03 21:32:27 +01:00
|
|
|
|
var hasDisplayOrder = item as IHasDisplayOrder;
|
|
|
|
|
if (hasDisplayOrder != null)
|
|
|
|
|
{
|
|
|
|
|
dto.DisplayOrder = hasDisplayOrder.DisplayOrder;
|
|
|
|
|
}
|
2014-01-04 03:35:41 +01:00
|
|
|
|
|
2014-06-05 04:32:40 +02:00
|
|
|
|
var userView = item as UserView;
|
|
|
|
|
if (userView != null)
|
|
|
|
|
{
|
|
|
|
|
dto.CollectionType = userView.ViewType;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-02 17:46:25 +01:00
|
|
|
|
if (fields.Contains(ItemFields.RemoteTrailers))
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-12-02 17:46:25 +01:00
|
|
|
|
dto.RemoteTrailers = hasTrailers != null ?
|
|
|
|
|
hasTrailers.RemoteTrailers :
|
|
|
|
|
new List<MediaUrl>();
|
2013-09-04 19:02:19 +02:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.Name = item.Name;
|
|
|
|
|
dto.OfficialRating = item.OfficialRating;
|
2013-03-09 06:15:51 +01:00
|
|
|
|
|
2014-05-27 16:30:21 +02:00
|
|
|
|
if (fields.Contains(ItemFields.Overview))
|
2013-09-04 19:02:19 +02:00
|
|
|
|
{
|
2014-08-06 01:59:24 +02:00
|
|
|
|
dto.Overview = item.Overview;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-20 07:21:40 +02:00
|
|
|
|
if (fields.Contains(ItemFields.OriginalTitle))
|
|
|
|
|
{
|
|
|
|
|
dto.OriginalTitle = item.OriginalTitle;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 06:18:02 +02:00
|
|
|
|
if (fields.Contains(ItemFields.ShortOverview))
|
|
|
|
|
{
|
|
|
|
|
var hasShortOverview = item as IHasShortOverview;
|
|
|
|
|
if (hasShortOverview != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ShortOverview = hasShortOverview.ShortOverview;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
// If there are no backdrops, indicate what parent has them in case the Ui wants to allow inheritance
|
2014-11-30 20:01:33 +01:00
|
|
|
|
if (backdropLimit > 0 && dto.BackdropImageTags.Count == 0)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
var parentWithBackdrop = GetParentBackdropItem(item, owner);
|
|
|
|
|
|
|
|
|
|
if (parentWithBackdrop != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ParentBackdropItemId = GetDtoId(parentWithBackdrop);
|
2014-11-30 20:01:33 +01:00
|
|
|
|
dto.ParentBackdropImageTags = GetBackdropImageTags(parentWithBackdrop, backdropLimit);
|
2013-09-04 19:02:19 +02:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
2013-07-25 21:17:44 +02:00
|
|
|
|
|
2014-10-24 06:54:35 +02:00
|
|
|
|
if (fields.Contains(ItemFields.ParentId))
|
2013-07-25 21:17:44 +02:00
|
|
|
|
{
|
2016-04-09 06:16:53 +02:00
|
|
|
|
var displayParentId = item.DisplayParentId;
|
|
|
|
|
if (displayParentId.HasValue)
|
2014-10-24 06:54:35 +02:00
|
|
|
|
{
|
2016-04-09 06:16:53 +02:00
|
|
|
|
dto.ParentId = displayParentId.Value.ToString("N");
|
2014-10-24 06:54:35 +02:00
|
|
|
|
}
|
2013-07-25 21:17:44 +02:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.ParentIndexNumber = item.ParentIndexNumber;
|
2013-04-14 22:47:09 +02:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
// If there is no logo, indicate what parent has one in case the Ui wants to allow inheritance
|
2014-11-30 20:01:33 +01:00
|
|
|
|
if (!dto.HasLogo && options.GetImageLimit(ImageType.Logo) > 0)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
var parentWithLogo = GetParentImageItem(item, ImageType.Logo, owner);
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
if (parentWithLogo != null)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.ParentLogoItemId = GetDtoId(parentWithLogo);
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2014-02-07 21:30:41 +01:00
|
|
|
|
dto.ParentLogoImageTag = GetImageCacheTag(parentWithLogo, ImageType.Logo);
|
2013-09-04 19:02:19 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
// If there is no art, indicate what parent has one in case the Ui wants to allow inheritance
|
2014-12-14 06:23:04 +01:00
|
|
|
|
if (!dto.HasArtImage && options.GetImageLimit(ImageType.Art) > 0)
|
2013-09-04 19:02:19 +02:00
|
|
|
|
{
|
|
|
|
|
var parentWithImage = GetParentImageItem(item, ImageType.Art, owner);
|
|
|
|
|
|
|
|
|
|
if (parentWithImage != null)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.ParentArtItemId = GetDtoId(parentWithImage);
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2014-02-07 21:30:41 +01:00
|
|
|
|
dto.ParentArtImageTag = GetImageCacheTag(parentWithImage, ImageType.Art);
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
2013-09-04 19:02:19 +02:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-10-24 19:49:24 +02:00
|
|
|
|
// If there is no thumb, indicate what parent has one in case the Ui wants to allow inheritance
|
2014-11-30 20:01:33 +01:00
|
|
|
|
if (!dto.HasThumb && options.GetImageLimit(ImageType.Thumb) > 0)
|
2013-10-24 19:49:24 +02:00
|
|
|
|
{
|
|
|
|
|
var parentWithImage = GetParentImageItem(item, ImageType.Thumb, owner);
|
|
|
|
|
|
|
|
|
|
if (parentWithImage != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ParentThumbItemId = GetDtoId(parentWithImage);
|
|
|
|
|
|
2014-02-07 21:30:41 +01:00
|
|
|
|
dto.ParentThumbImageTag = GetImageCacheTag(parentWithImage, ImageType.Thumb);
|
2013-10-24 19:49:24 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
if (fields.Contains(ItemFields.Path))
|
|
|
|
|
{
|
2014-06-02 21:32:41 +02:00
|
|
|
|
dto.Path = GetMappedPath(item);
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.PremiereDate = item.PremiereDate;
|
|
|
|
|
dto.ProductionYear = item.ProductionYear;
|
2013-05-04 05:13:28 +02:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
if (fields.Contains(ItemFields.ProviderIds))
|
|
|
|
|
{
|
|
|
|
|
dto.ProviderIds = item.ProviderIds;
|
|
|
|
|
}
|
2013-05-04 05:13:28 +02:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.RunTimeTicks = item.RunTimeTicks;
|
2013-05-04 05:13:28 +02:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
if (fields.Contains(ItemFields.SortName))
|
|
|
|
|
{
|
|
|
|
|
dto.SortName = item.SortName;
|
|
|
|
|
}
|
2013-05-04 05:13:28 +02:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
if (fields.Contains(ItemFields.CustomRating))
|
|
|
|
|
{
|
|
|
|
|
dto.CustomRating = item.CustomRating;
|
|
|
|
|
}
|
2013-05-04 05:13:28 +02:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
if (fields.Contains(ItemFields.Taglines))
|
|
|
|
|
{
|
2013-12-05 17:50:21 +01:00
|
|
|
|
var hasTagline = item as IHasTaglines;
|
|
|
|
|
if (hasTagline != null)
|
|
|
|
|
{
|
|
|
|
|
dto.Taglines = hasTagline.Taglines;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dto.Taglines == null)
|
|
|
|
|
{
|
|
|
|
|
dto.Taglines = new List<string>();
|
|
|
|
|
}
|
2013-09-04 19:02:19 +02:00
|
|
|
|
}
|
2013-05-04 05:13:28 +02:00
|
|
|
|
|
2013-11-21 21:48:26 +01:00
|
|
|
|
dto.Type = item.GetClientTypeName();
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.CommunityRating = item.CommunityRating;
|
2014-11-30 20:01:33 +01:00
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.VoteCount))
|
|
|
|
|
{
|
|
|
|
|
dto.VoteCount = item.VoteCount;
|
|
|
|
|
}
|
2013-05-04 05:13:28 +02:00
|
|
|
|
|
2015-11-11 15:56:31 +01:00
|
|
|
|
//if (item.IsFolder)
|
|
|
|
|
//{
|
|
|
|
|
// var folder = (Folder)item;
|
2013-05-04 05:13:28 +02:00
|
|
|
|
|
2015-11-11 15:56:31 +01:00
|
|
|
|
// if (fields.Contains(ItemFields.IndexOptions))
|
|
|
|
|
// {
|
|
|
|
|
// dto.IndexOptions = folder.IndexByOptionStrings.ToArray();
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2014-03-03 06:11:03 +01:00
|
|
|
|
var supportsPlaceHolders = item as ISupportsPlaceHolders;
|
|
|
|
|
if (supportsPlaceHolders != null)
|
|
|
|
|
{
|
|
|
|
|
dto.IsPlaceHolder = supportsPlaceHolders.IsPlaceHolder;
|
|
|
|
|
}
|
2014-03-22 17:16:43 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
// Add audio info
|
|
|
|
|
var audio = item as Audio;
|
|
|
|
|
if (audio != null)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.Album = audio.Album;
|
2016-03-19 05:22:33 +01:00
|
|
|
|
dto.ExtraType = audio.ExtraType;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2015-05-04 16:35:38 +02:00
|
|
|
|
var albumParent = audio.AlbumEntity;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
if (albumParent != null)
|
|
|
|
|
{
|
|
|
|
|
dto.AlbumId = GetDtoId(albumParent);
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2014-02-07 21:30:41 +01:00
|
|
|
|
dto.AlbumPrimaryImageTag = GetImageCacheTag(albumParent, ImageType.Primary);
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
2014-03-21 04:31:40 +01:00
|
|
|
|
|
2014-12-01 13:43:34 +01:00
|
|
|
|
//if (fields.Contains(ItemFields.MediaSourceCount))
|
|
|
|
|
//{
|
2015-01-24 20:03:55 +01:00
|
|
|
|
// Songs always have one
|
2014-12-01 13:43:34 +01:00
|
|
|
|
//}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-13 18:25:28 +01:00
|
|
|
|
var hasArtist = item as IHasArtist;
|
|
|
|
|
if (hasArtist != null)
|
|
|
|
|
{
|
|
|
|
|
dto.Artists = hasArtist.Artists;
|
|
|
|
|
|
|
|
|
|
dto.ArtistItems = hasArtist
|
|
|
|
|
.Artists
|
|
|
|
|
.Select(i =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var artist = _libraryManager.GetArtist(i);
|
|
|
|
|
return new NameIdPair
|
|
|
|
|
{
|
|
|
|
|
Name = artist.Name,
|
|
|
|
|
Id = artist.Id.ToString("N")
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error getting artist", ex);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
2013-09-06 21:17:15 +02:00
|
|
|
|
|
2015-03-13 18:25:28 +01:00
|
|
|
|
var hasAlbumArtist = item as IHasAlbumArtist;
|
2013-09-06 21:17:15 +02:00
|
|
|
|
if (hasAlbumArtist != null)
|
|
|
|
|
{
|
2014-06-23 18:05:19 +02:00
|
|
|
|
dto.AlbumArtist = hasAlbumArtist.AlbumArtists.FirstOrDefault();
|
2015-03-13 16:54:20 +01:00
|
|
|
|
|
|
|
|
|
dto.AlbumArtists = hasAlbumArtist
|
|
|
|
|
.AlbumArtists
|
|
|
|
|
.Select(i =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var artist = _libraryManager.GetArtist(i);
|
|
|
|
|
return new NameIdPair
|
|
|
|
|
{
|
|
|
|
|
Name = artist.Name,
|
|
|
|
|
Id = artist.Id.ToString("N")
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error getting album artist", ex);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.ToList();
|
2013-09-06 21:17:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
// Add video info
|
|
|
|
|
var video = item as Video;
|
|
|
|
|
if (video != null)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.VideoType = video.VideoType;
|
|
|
|
|
dto.Video3DFormat = video.Video3DFormat;
|
|
|
|
|
dto.IsoType = video.IsoType;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2015-10-24 17:33:22 +02:00
|
|
|
|
if (video.HasSubtitles)
|
|
|
|
|
{
|
|
|
|
|
dto.HasSubtitles = video.HasSubtitles;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 04:13:03 +01:00
|
|
|
|
if (video.AdditionalParts.Count != 0)
|
2014-11-30 20:01:33 +01:00
|
|
|
|
{
|
2014-12-03 04:13:03 +01:00
|
|
|
|
dto.PartCount = video.AdditionalParts.Count + 1;
|
2014-11-30 20:01:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.MediaSourceCount))
|
|
|
|
|
{
|
2016-05-01 22:56:06 +02:00
|
|
|
|
var mediaSourceCount = video.MediaSourceCount;
|
|
|
|
|
if (mediaSourceCount != 1)
|
2014-12-01 13:43:34 +01:00
|
|
|
|
{
|
2016-05-01 22:56:06 +02:00
|
|
|
|
dto.MediaSourceCount = mediaSourceCount;
|
2014-12-01 13:43:34 +01:00
|
|
|
|
}
|
2014-11-30 20:01:33 +01:00
|
|
|
|
}
|
2014-03-16 05:23:58 +01:00
|
|
|
|
|
2014-03-21 04:31:40 +01:00
|
|
|
|
if (fields.Contains(ItemFields.Chapters))
|
2014-03-20 16:55:22 +01:00
|
|
|
|
{
|
2014-10-12 17:18:26 +02:00
|
|
|
|
dto.Chapters = GetChapterInfoDtos(item);
|
2014-03-20 16:55:22 +01:00
|
|
|
|
}
|
2016-03-19 05:22:33 +01:00
|
|
|
|
|
|
|
|
|
dto.ExtraType = video.ExtraType;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
if (fields.Contains(ItemFields.MediaStreams))
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
// Add VideoInfo
|
2014-06-11 21:31:33 +02:00
|
|
|
|
var iHasMediaSources = item as IHasMediaSources;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2014-06-11 21:31:33 +02:00
|
|
|
|
if (iHasMediaSources != null)
|
2013-09-04 19:02:19 +02:00
|
|
|
|
{
|
2014-03-21 04:31:40 +01:00
|
|
|
|
List<MediaStream> mediaStreams;
|
|
|
|
|
|
2014-03-22 17:16:43 +01:00
|
|
|
|
if (dto.MediaSources != null && dto.MediaSources.Count > 0)
|
2013-12-06 04:39:44 +01:00
|
|
|
|
{
|
2014-03-22 17:31:21 +01:00
|
|
|
|
mediaStreams = dto.MediaSources.Where(i => new Guid(i.Id) == item.Id)
|
2014-03-21 04:31:40 +01:00
|
|
|
|
.SelectMany(i => i.MediaStreams)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-03-31 18:24:16 +02:00
|
|
|
|
mediaStreams = _mediaSourceManager().GetStaticMediaSources(iHasMediaSources, true).First().MediaStreams;
|
2014-03-21 04:31:40 +01:00
|
|
|
|
}
|
2013-12-06 04:39:44 +01:00
|
|
|
|
|
2014-03-21 04:31:40 +01:00
|
|
|
|
dto.MediaStreams = mediaStreams;
|
2013-09-04 19:02:19 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-20 17:48:23 +02:00
|
|
|
|
var hasSpecialFeatures = item as IHasSpecialFeatures;
|
|
|
|
|
if (hasSpecialFeatures != null)
|
|
|
|
|
{
|
|
|
|
|
var specialFeatureCount = hasSpecialFeatures.SpecialFeatureIds.Count;
|
|
|
|
|
|
|
|
|
|
if (specialFeatureCount > 0)
|
2014-01-28 19:37:01 +01:00
|
|
|
|
{
|
2014-09-20 17:48:23 +02:00
|
|
|
|
dto.SpecialFeatureCount = specialFeatureCount;
|
2014-01-28 19:37:01 +01:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
// Add EpisodeInfo
|
|
|
|
|
var episode = item as Episode;
|
|
|
|
|
if (episode != null)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.IndexNumberEnd = episode.IndexNumberEnd;
|
2016-05-23 00:37:50 +02:00
|
|
|
|
dto.SeriesName = episode.SeriesName;
|
2013-12-08 21:33:24 +01:00
|
|
|
|
|
2014-12-01 13:43:34 +01:00
|
|
|
|
if (fields.Contains(ItemFields.AlternateEpisodeNumbers))
|
|
|
|
|
{
|
|
|
|
|
dto.DvdSeasonNumber = episode.DvdSeasonNumber;
|
|
|
|
|
dto.DvdEpisodeNumber = episode.DvdEpisodeNumber;
|
|
|
|
|
dto.AbsoluteEpisodeNumber = episode.AbsoluteEpisodeNumber;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-12 06:07:19 +01:00
|
|
|
|
if (fields.Contains(ItemFields.SpecialEpisodeNumbers))
|
2014-12-19 05:20:07 +01:00
|
|
|
|
{
|
|
|
|
|
dto.AirsAfterSeasonNumber = episode.AirsAfterSeasonNumber;
|
|
|
|
|
dto.AirsBeforeEpisodeNumber = episode.AirsBeforeEpisodeNumber;
|
|
|
|
|
dto.AirsBeforeSeasonNumber = episode.AirsBeforeSeasonNumber;
|
|
|
|
|
}
|
2013-12-04 05:18:50 +01:00
|
|
|
|
|
2016-05-23 00:37:50 +02:00
|
|
|
|
var seasonId = episode.SeasonId;
|
|
|
|
|
if (seasonId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
dto.SeasonId = seasonId.Value.ToString("N");
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-17 03:38:50 +02:00
|
|
|
|
var episodeSeason = episode.Season;
|
|
|
|
|
if (episodeSeason != null)
|
2013-12-04 05:18:50 +01:00
|
|
|
|
{
|
2014-12-19 05:20:07 +01:00
|
|
|
|
if (fields.Contains(ItemFields.SeasonName))
|
|
|
|
|
{
|
|
|
|
|
dto.SeasonName = episodeSeason.Name;
|
|
|
|
|
}
|
2013-12-04 05:18:50 +01:00
|
|
|
|
}
|
2014-12-13 04:56:30 +01:00
|
|
|
|
|
2016-05-23 00:37:50 +02:00
|
|
|
|
var episodeSeries = episode.Series;
|
|
|
|
|
|
|
|
|
|
if (episodeSeries != null)
|
2014-12-13 04:56:30 +01:00
|
|
|
|
{
|
2016-05-23 00:37:50 +02:00
|
|
|
|
if (fields.Contains(ItemFields.SeriesGenres))
|
2014-12-13 04:56:30 +01:00
|
|
|
|
{
|
2016-05-23 00:37:50 +02:00
|
|
|
|
dto.SeriesGenres = episodeSeries.Genres.ToList();
|
2014-12-13 04:56:30 +01:00
|
|
|
|
}
|
2014-03-01 05:13:44 +01:00
|
|
|
|
|
2016-05-23 00:37:50 +02:00
|
|
|
|
dto.SeriesId = GetDtoId(episodeSeries);
|
2014-12-19 05:20:07 +01:00
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.AirTime))
|
|
|
|
|
{
|
2016-05-23 00:37:50 +02:00
|
|
|
|
dto.AirTime = episodeSeries.AirTime;
|
2014-12-19 05:20:07 +01:00
|
|
|
|
}
|
2014-12-01 13:43:34 +01:00
|
|
|
|
|
|
|
|
|
if (options.GetImageLimit(ImageType.Thumb) > 0)
|
|
|
|
|
{
|
2016-05-23 00:37:50 +02:00
|
|
|
|
dto.SeriesThumbImageTag = GetImageCacheTag(episodeSeries, ImageType.Thumb);
|
2014-12-01 13:43:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options.GetImageLimit(ImageType.Primary) > 0)
|
|
|
|
|
{
|
2016-05-23 00:37:50 +02:00
|
|
|
|
dto.SeriesPrimaryImageTag = GetImageCacheTag(episodeSeries, ImageType.Primary);
|
2014-12-01 13:43:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.SeriesStudio))
|
|
|
|
|
{
|
2016-05-23 00:37:50 +02:00
|
|
|
|
dto.SeriesStudio = episodeSeries.Studios.FirstOrDefault();
|
2014-12-01 13:43:34 +01:00
|
|
|
|
}
|
2014-07-04 04:22:57 +02:00
|
|
|
|
}
|
2013-03-31 19:39:28 +02:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2016-05-23 00:37:50 +02:00
|
|
|
|
// Add SeriesInfo
|
|
|
|
|
var series = item as Series;
|
|
|
|
|
if (series != null)
|
|
|
|
|
{
|
|
|
|
|
dto.AirDays = series.AirDays;
|
|
|
|
|
dto.AirTime = series.AirTime;
|
|
|
|
|
dto.SeriesStatus = series.Status;
|
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.Settings))
|
|
|
|
|
{
|
|
|
|
|
dto.DisplaySpecialsWithSeasons = series.DisplaySpecialsWithSeasons;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dto.AnimeSeriesIndex = series.AnimeSeriesIndex;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
// Add SeasonInfo
|
|
|
|
|
var season = item as Season;
|
|
|
|
|
if (season != null)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2014-07-04 04:22:57 +02:00
|
|
|
|
series = season.Series;
|
2013-09-04 19:02:19 +02:00
|
|
|
|
|
2014-07-04 04:22:57 +02:00
|
|
|
|
if (series != null)
|
|
|
|
|
{
|
|
|
|
|
dto.SeriesId = GetDtoId(series);
|
|
|
|
|
dto.SeriesName = series.Name;
|
|
|
|
|
dto.AirTime = series.AirTime;
|
|
|
|
|
dto.SeriesStudio = series.Studios.FirstOrDefault();
|
2013-11-09 19:44:09 +01:00
|
|
|
|
|
2014-12-01 13:43:34 +01:00
|
|
|
|
if (options.GetImageLimit(ImageType.Primary) > 0)
|
|
|
|
|
{
|
|
|
|
|
dto.SeriesPrimaryImageTag = GetImageCacheTag(series, ImageType.Primary);
|
|
|
|
|
}
|
2014-07-04 04:22:57 +02:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
var game = item as Game;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
if (game != null)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
SetGameProperties(dto, game);
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-27 22:40:42 +01:00
|
|
|
|
var gameSystem = item as GameSystem;
|
|
|
|
|
|
|
|
|
|
if (gameSystem != null)
|
|
|
|
|
{
|
|
|
|
|
SetGameSystemProperties(dto, gameSystem);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
var musicVideo = item as MusicVideo;
|
|
|
|
|
if (musicVideo != null)
|
|
|
|
|
{
|
|
|
|
|
SetMusicVideoProperties(dto, musicVideo);
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
var book = item as Book;
|
|
|
|
|
if (book != null)
|
|
|
|
|
{
|
|
|
|
|
SetBookProperties(dto, book);
|
|
|
|
|
}
|
2014-03-30 18:49:40 +02:00
|
|
|
|
|
2014-08-29 02:49:25 +02:00
|
|
|
|
var photo = item as Photo;
|
|
|
|
|
if (photo != null)
|
|
|
|
|
{
|
|
|
|
|
SetPhotoProperties(dto, photo);
|
|
|
|
|
}
|
2014-03-30 18:49:40 +02:00
|
|
|
|
|
2015-08-17 06:08:33 +02:00
|
|
|
|
dto.ChannelId = item.ChannelId;
|
2015-10-29 14:28:05 +01:00
|
|
|
|
|
2016-03-19 06:04:38 +01:00
|
|
|
|
if (item.SourceType == SourceType.Channel && !string.IsNullOrWhiteSpace(item.ChannelId))
|
2014-05-17 23:23:48 +02:00
|
|
|
|
{
|
2016-03-19 06:04:38 +01:00
|
|
|
|
var channel = _libraryManager.GetItemById(item.ChannelId);
|
|
|
|
|
if (channel != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ChannelName = channel.Name;
|
|
|
|
|
}
|
2014-05-17 23:23:48 +02:00
|
|
|
|
}
|
2014-03-30 18:49:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-21 04:31:40 +01:00
|
|
|
|
private string GetMappedPath(IHasMetadata item)
|
2014-03-20 16:55:22 +01:00
|
|
|
|
{
|
2014-03-21 04:31:40 +01:00
|
|
|
|
var path = item.Path;
|
2014-03-20 16:55:22 +01:00
|
|
|
|
|
2014-03-21 04:31:40 +01:00
|
|
|
|
var locationType = item.LocationType;
|
2014-03-20 16:55:22 +01:00
|
|
|
|
|
2014-06-02 21:32:41 +02:00
|
|
|
|
if (locationType == LocationType.FileSystem || locationType == LocationType.Offline)
|
2014-03-20 16:55:22 +01:00
|
|
|
|
{
|
2014-06-02 21:32:41 +02:00
|
|
|
|
foreach (var map in _config.Configuration.PathSubstitutions)
|
|
|
|
|
{
|
2015-10-04 05:38:46 +02:00
|
|
|
|
path = _libraryManager.SubstitutePath(path, map.From, map.To);
|
2014-06-02 21:32:41 +02:00
|
|
|
|
}
|
2014-03-20 16:55:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 17:50:21 +01:00
|
|
|
|
private void SetProductionLocations(BaseItem item, BaseItemDto dto)
|
|
|
|
|
{
|
|
|
|
|
var hasProductionLocations = item as IHasProductionLocations;
|
|
|
|
|
|
|
|
|
|
if (hasProductionLocations != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ProductionLocations = hasProductionLocations.ProductionLocations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var person = item as Person;
|
|
|
|
|
if (person != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ProductionLocations = new List<string>();
|
|
|
|
|
if (!string.IsNullOrEmpty(person.PlaceOfBirth))
|
|
|
|
|
{
|
|
|
|
|
dto.ProductionLocations.Add(person.PlaceOfBirth);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dto.ProductionLocations == null)
|
|
|
|
|
{
|
|
|
|
|
dto.ProductionLocations = new List<string>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 02:33:05 +01:00
|
|
|
|
/// <summary>
|
2013-09-04 19:02:19 +02:00
|
|
|
|
/// Since it can be slow to make all of these calculations independently, this method will provide a way to do them all at once
|
2013-02-21 02:33:05 +01:00
|
|
|
|
/// </summary>
|
2013-09-04 19:02:19 +02:00
|
|
|
|
/// <param name="folder">The folder.</param>
|
|
|
|
|
/// <param name="user">The user.</param>
|
|
|
|
|
/// <param name="dto">The dto.</param>
|
2013-09-23 16:26:20 +02:00
|
|
|
|
/// <param name="fields">The fields.</param>
|
2015-06-02 19:46:44 +02:00
|
|
|
|
/// <param name="syncProgress">The synchronize progress.</param>
|
2013-09-04 19:02:19 +02:00
|
|
|
|
/// <returns>Task.</returns>
|
2015-07-27 07:03:34 +02:00
|
|
|
|
private void SetSpecialCounts(Folder folder, User user, BaseItemDto dto, List<ItemFields> fields, Dictionary<string, SyncedItemProgress> syncProgress)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-09-04 19:02:19 +02:00
|
|
|
|
var recursiveItemCount = 0;
|
|
|
|
|
var unplayed = 0;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
double totalPercentPlayed = 0;
|
2015-06-02 19:46:44 +02:00
|
|
|
|
double totalSyncPercent = 0;
|
|
|
|
|
var addSyncInfo = fields.Contains(ItemFields.SyncInfo);
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2015-07-27 07:03:34 +02:00
|
|
|
|
var children = folder.GetItems(new InternalItemsQuery
|
2013-12-10 21:42:42 +01:00
|
|
|
|
{
|
2015-07-27 07:03:34 +02:00
|
|
|
|
IsFolder = false,
|
|
|
|
|
Recursive = true,
|
2016-03-20 07:46:51 +01:00
|
|
|
|
ExcludeLocationTypes = new[] { LocationType.Virtual },
|
2015-08-17 06:56:22 +02:00
|
|
|
|
User = user
|
2015-07-27 07:03:34 +02:00
|
|
|
|
|
|
|
|
|
}).Result.Items;
|
2013-12-10 21:42:42 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
// Loop through each recursive child
|
2013-12-10 21:42:42 +01:00
|
|
|
|
foreach (var child in children)
|
2013-09-04 19:02:19 +02:00
|
|
|
|
{
|
2016-05-01 00:05:13 +02:00
|
|
|
|
var userdata = _userDataRepository.GetUserData(user, child);
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
recursiveItemCount++;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
var isUnplayed = true;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
// Incrememt totalPercentPlayed
|
|
|
|
|
if (userdata != null)
|
|
|
|
|
{
|
|
|
|
|
if (userdata.Played)
|
|
|
|
|
{
|
|
|
|
|
totalPercentPlayed += 100;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
isUnplayed = false;
|
|
|
|
|
}
|
|
|
|
|
else if (userdata.PlaybackPositionTicks > 0 && child.RunTimeTicks.HasValue && child.RunTimeTicks.Value > 0)
|
|
|
|
|
{
|
|
|
|
|
double itemPercent = userdata.PlaybackPositionTicks;
|
|
|
|
|
itemPercent /= child.RunTimeTicks.Value;
|
|
|
|
|
totalPercentPlayed += itemPercent;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
if (isUnplayed)
|
|
|
|
|
{
|
|
|
|
|
unplayed++;
|
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2015-06-02 19:46:44 +02:00
|
|
|
|
if (addSyncInfo)
|
|
|
|
|
{
|
|
|
|
|
double percent = 0;
|
|
|
|
|
SyncedItemProgress syncItemProgress;
|
2015-06-02 19:50:50 +02:00
|
|
|
|
if (syncProgress.TryGetValue(child.Id.ToString("N"), out syncItemProgress))
|
2015-06-02 19:46:44 +02:00
|
|
|
|
{
|
|
|
|
|
switch (syncItemProgress.Status)
|
|
|
|
|
{
|
|
|
|
|
case SyncJobItemStatus.Synced:
|
|
|
|
|
percent = 100;
|
|
|
|
|
break;
|
|
|
|
|
case SyncJobItemStatus.Converting:
|
|
|
|
|
case SyncJobItemStatus.ReadyToTransfer:
|
|
|
|
|
case SyncJobItemStatus.Transferring:
|
|
|
|
|
percent = 50;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
totalSyncPercent += percent;
|
|
|
|
|
}
|
2013-09-04 19:02:19 +02:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
2013-09-04 19:02:19 +02:00
|
|
|
|
dto.RecursiveItemCount = recursiveItemCount;
|
2014-08-17 07:38:13 +02:00
|
|
|
|
dto.UserData.UnplayedItemCount = unplayed;
|
2013-09-04 19:02:19 +02:00
|
|
|
|
|
|
|
|
|
if (recursiveItemCount > 0)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2014-08-17 07:38:13 +02:00
|
|
|
|
dto.UserData.PlayedPercentage = totalPercentPlayed / recursiveItemCount;
|
2015-06-02 19:46:44 +02:00
|
|
|
|
|
|
|
|
|
if (addSyncInfo)
|
|
|
|
|
{
|
2015-06-02 19:50:50 +02:00
|
|
|
|
var pct = totalSyncPercent / recursiveItemCount;
|
|
|
|
|
if (pct > 0)
|
|
|
|
|
{
|
|
|
|
|
dto.SyncPercent = pct;
|
|
|
|
|
}
|
2015-06-02 19:46:44 +02:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2013-09-04 19:02:19 +02:00
|
|
|
|
/// Attaches the primary image aspect ratio.
|
2013-02-21 02:33:05 +01:00
|
|
|
|
/// </summary>
|
2013-09-04 19:02:19 +02:00
|
|
|
|
/// <param name="dto">The dto.</param>
|
2013-02-21 02:33:05 +01:00
|
|
|
|
/// <param name="item">The item.</param>
|
2013-09-04 19:02:19 +02:00
|
|
|
|
/// <returns>Task.</returns>
|
2016-01-16 06:01:57 +01:00
|
|
|
|
public void AttachPrimaryImageAspectRatio(IItemDto dto, IHasImages item)
|
|
|
|
|
{
|
|
|
|
|
dto.PrimaryImageAspectRatio = GetPrimaryImageAspectRatio(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double? GetPrimaryImageAspectRatio(IHasImages item)
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2014-02-07 21:30:41 +01:00
|
|
|
|
var imageInfo = item.GetImageInfo(ImageType.Primary, 0);
|
2013-05-05 06:49:49 +02:00
|
|
|
|
|
2015-10-16 19:06:31 +02:00
|
|
|
|
if (imageInfo == null || !imageInfo.IsLocalFile)
|
2013-09-04 19:02:19 +02:00
|
|
|
|
{
|
2016-01-16 06:01:57 +01:00
|
|
|
|
return null;
|
2013-09-04 19:02:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImageSize size;
|
2013-07-06 02:19:44 +02:00
|
|
|
|
|
2014-10-15 02:05:09 +02:00
|
|
|
|
try
|
2013-05-05 06:49:49 +02:00
|
|
|
|
{
|
2015-02-28 14:42:47 +01:00
|
|
|
|
size = _imageProcessor.GetImageSize(imageInfo);
|
2013-09-04 19:02:19 +02:00
|
|
|
|
}
|
2014-10-15 02:05:09 +02:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2015-08-14 19:24:07 +02:00
|
|
|
|
//_logger.ErrorException("Failed to determine primary image aspect ratio for {0}", ex, path);
|
2016-01-16 06:01:57 +01:00
|
|
|
|
return null;
|
2013-09-04 19:02:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-18 20:49:06 +02:00
|
|
|
|
var supportedEnhancers = _imageProcessor.GetSupportedEnhancers(item, ImageType.Primary).ToList();
|
2013-09-04 19:02:19 +02:00
|
|
|
|
|
|
|
|
|
foreach (var enhancer in supportedEnhancers)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
size = enhancer.GetEnhancedImageSize(item, ImageType.Primary, 0, size);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error in image enhancer: {0}", ex, enhancer.GetType().Name);
|
|
|
|
|
}
|
2013-05-05 06:49:49 +02:00
|
|
|
|
}
|
2013-09-04 19:02:19 +02:00
|
|
|
|
|
2016-01-21 09:23:02 +01:00
|
|
|
|
var width = size.Width;
|
|
|
|
|
var height = size.Height;
|
|
|
|
|
|
|
|
|
|
if (width == 0 || height == 0)
|
2015-01-30 22:17:19 +01:00
|
|
|
|
{
|
2016-01-21 09:23:02 +01:00
|
|
|
|
return null;
|
2015-01-30 22:17:19 +01:00
|
|
|
|
}
|
2016-01-21 09:23:02 +01:00
|
|
|
|
|
|
|
|
|
var photo = item as Photo;
|
|
|
|
|
if (photo != null && photo.Orientation.HasValue)
|
|
|
|
|
{
|
|
|
|
|
switch (photo.Orientation.Value)
|
|
|
|
|
{
|
|
|
|
|
case ImageOrientation.LeftBottom:
|
|
|
|
|
case ImageOrientation.LeftTop:
|
|
|
|
|
case ImageOrientation.RightBottom:
|
|
|
|
|
case ImageOrientation.RightTop:
|
|
|
|
|
var temp = height;
|
|
|
|
|
height = width;
|
|
|
|
|
width = temp;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return width / height;
|
2013-05-05 06:49:49 +02:00
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
}
|