2014-10-24 04:54:35 +00:00
|
|
|
|
using MediaBrowser.Common;
|
2014-05-17 21:23:48 +00:00
|
|
|
|
using MediaBrowser.Controller.Channels;
|
2014-01-30 05:20:18 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2015-01-24 19:03:55 +00:00
|
|
|
|
using MediaBrowser.Controller.Devices;
|
2013-09-18 18:49:06 +00:00
|
|
|
|
using MediaBrowser.Controller.Drawing;
|
2013-09-04 17:02:19 +00:00
|
|
|
|
using MediaBrowser.Controller.Dto;
|
2013-03-12 22:49:45 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-04-13 18:02:30 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-03-30 16:49:40 +00:00
|
|
|
|
using MediaBrowser.Controller.LiveTv;
|
2013-04-13 18:02:30 +00:00
|
|
|
|
using MediaBrowser.Controller.Persistence;
|
2014-02-21 18:48:15 +00:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-07-22 16:36:34 +00:00
|
|
|
|
using MediaBrowser.Controller.Sync;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Model.Drawing;
|
2013-02-21 17:50:46 +00:00
|
|
|
|
using MediaBrowser.Model.Dto;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-02-21 06:38:23 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-03-12 22:49:45 +00:00
|
|
|
|
using MediaBrowser.Model.Querying;
|
2015-01-24 19:03:55 +00:00
|
|
|
|
using MediaBrowser.Model.Sync;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2016-03-02 18:42:39 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2017-05-26 06:48:54 +00:00
|
|
|
|
|
2016-10-25 19:02:04 +00:00
|
|
|
|
using MediaBrowser.Controller.IO;
|
|
|
|
|
using MediaBrowser.Model.IO;
|
2016-10-22 02:08:34 +00:00
|
|
|
|
using MediaBrowser.Model.Extensions;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2016-11-03 06:37:52 +00:00
|
|
|
|
namespace Emby.Server.Implementations.Dto
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-09-04 17:02:19 +00:00
|
|
|
|
public class DtoService : IDtoService
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-03-01 21:22:34 +00:00
|
|
|
|
private readonly ILogger _logger;
|
2013-03-12 22:49:45 +00:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2013-10-02 16:08:58 +00:00
|
|
|
|
private readonly IUserDataManager _userDataRepository;
|
2013-06-18 19:16:27 +00:00
|
|
|
|
private readonly IItemRepository _itemRepo;
|
2013-02-22 01:26:35 +00:00
|
|
|
|
|
2013-09-18 18:49:06 +00:00
|
|
|
|
private readonly IImageProcessor _imageProcessor;
|
2014-01-30 05:20:18 +00:00
|
|
|
|
private readonly IServerConfigurationManager _config;
|
2014-02-07 20:30:41 +00:00
|
|
|
|
private readonly IFileSystem _fileSystem;
|
2014-02-21 18:48:15 +00:00
|
|
|
|
private readonly IProviderManager _providerManager;
|
2013-10-02 16:08:58 +00:00
|
|
|
|
|
2014-05-19 19:51:56 +00:00
|
|
|
|
private readonly Func<IChannelManager> _channelManagerFactory;
|
2014-07-22 16:36:34 +00:00
|
|
|
|
private readonly ISyncManager _syncManager;
|
2014-10-24 04:54:35 +00:00
|
|
|
|
private readonly IApplicationHost _appHost;
|
2015-01-24 19:03:55 +00:00
|
|
|
|
private readonly Func<IDeviceManager> _deviceManager;
|
2015-03-07 22:43:53 +00:00
|
|
|
|
private readonly Func<IMediaSourceManager> _mediaSourceManager;
|
2015-05-31 18:22:51 +00:00
|
|
|
|
private readonly Func<ILiveTvManager> _livetvManager;
|
2014-05-19 19:51:56 +00:00
|
|
|
|
|
2015-05-31 18:22:51 +00: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 01:26:35 +00:00
|
|
|
|
{
|
2013-03-01 21:22:34 +00:00
|
|
|
|
_logger = logger;
|
2013-03-12 22:49:45 +00:00
|
|
|
|
_libraryManager = libraryManager;
|
2013-04-13 18:02:30 +00:00
|
|
|
|
_userDataRepository = userDataRepository;
|
2013-06-18 19:16:27 +00:00
|
|
|
|
_itemRepo = itemRepo;
|
2013-09-18 18:49:06 +00:00
|
|
|
|
_imageProcessor = imageProcessor;
|
2014-01-30 05:20:18 +00:00
|
|
|
|
_config = config;
|
2014-02-07 20:30:41 +00:00
|
|
|
|
_fileSystem = fileSystem;
|
2014-02-21 18:48:15 +00:00
|
|
|
|
_providerManager = providerManager;
|
2014-05-19 19:51:56 +00:00
|
|
|
|
_channelManagerFactory = channelManagerFactory;
|
2014-07-22 16:36:34 +00:00
|
|
|
|
_syncManager = syncManager;
|
2014-10-24 04:54:35 +00:00
|
|
|
|
_appHost = appHost;
|
2015-01-24 19:03:55 +00:00
|
|
|
|
_deviceManager = deviceManager;
|
2015-03-07 22:43:53 +00:00
|
|
|
|
_mediaSourceManager = mediaSourceManager;
|
2015-05-31 18:22:51 +00:00
|
|
|
|
_livetvManager = livetvManager;
|
2013-09-17 02:08:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
2013-05-15 16:56:38 +00:00
|
|
|
|
/// Converts a BaseItem to a DTOBaseItem
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="fields">The fields.</param>
|
2013-05-15 16:56:38 +00:00
|
|
|
|
/// <param name="user">The user.</param>
|
2013-07-30 14:51:28 +00:00
|
|
|
|
/// <param name="owner">The owner.</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <returns>Task{DtoBaseItem}.</returns>
|
|
|
|
|
/// <exception cref="System.ArgumentNullException">item</exception>
|
2017-08-19 19:43:35 +00:00
|
|
|
|
public BaseItemDto GetBaseItemDto(BaseItem item, ItemFields[] fields, User user = null, BaseItem owner = null)
|
2014-06-28 19:35:30 +00:00
|
|
|
|
{
|
2014-11-30 19:01:33 +00:00
|
|
|
|
var options = new DtoOptions
|
|
|
|
|
{
|
2014-12-21 05:57:06 +00:00
|
|
|
|
Fields = fields
|
2014-11-30 19:01:33 +00:00
|
|
|
|
};
|
2015-01-24 19:03:55 +00:00
|
|
|
|
|
2014-11-30 19:01:33 +00:00
|
|
|
|
return GetBaseItemDto(item, options, user, owner);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-28 00:33:05 +00:00
|
|
|
|
public BaseItemDto[] GetBaseItemDtos(List<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null)
|
2017-08-19 19:43:35 +00:00
|
|
|
|
{
|
|
|
|
|
return GetBaseItemDtos(items, items.Count, options, user, owner);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-28 00:33:05 +00:00
|
|
|
|
public BaseItemDto[] GetBaseItemDtos(BaseItem[] items, DtoOptions options, User user = null, BaseItem owner = null)
|
2017-08-19 19:43:35 +00:00
|
|
|
|
{
|
|
|
|
|
return GetBaseItemDtos(items, items.Length, options, user, owner);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-28 00:33:05 +00:00
|
|
|
|
public BaseItemDto[] GetBaseItemDtos(IEnumerable<BaseItem> items, int itemCount, DtoOptions options, User user = null, BaseItem owner = null)
|
2015-01-24 19:03:55 +00:00
|
|
|
|
{
|
2016-06-26 20:35:03 +00:00
|
|
|
|
if (items == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("items");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("options");
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 06:38:19 +00:00
|
|
|
|
var syncDictionary = GetSyncedItemProgress(options);
|
2015-01-24 19:03:55 +00:00
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
|
var returnItems = new BaseItemDto[itemCount];
|
2016-07-29 19:18:03 +00:00
|
|
|
|
var programTuples = new List<Tuple<BaseItem, BaseItemDto>>();
|
|
|
|
|
var channelTuples = new List<Tuple<BaseItemDto, LiveTvChannel>>();
|
2015-01-24 19:03:55 +00:00
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
|
var index = 0;
|
2017-10-16 06:10:55 +00:00
|
|
|
|
var allCollectionFolders = _libraryManager.GetUserRootFolder().Children.OfType<Folder>().ToList();
|
|
|
|
|
|
2015-01-24 19:03:55 +00:00
|
|
|
|
foreach (var item in items)
|
|
|
|
|
{
|
2017-10-16 06:10:55 +00:00
|
|
|
|
var dto = GetBaseItemDtoInternal(item, options, allCollectionFolders, user, owner);
|
2015-01-24 19:03:55 +00:00
|
|
|
|
|
2016-03-22 06:49:36 +00: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 18:42:39 +00:00
|
|
|
|
{
|
|
|
|
|
programTuples.Add(new Tuple<BaseItem, BaseItemDto>(item, dto));
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-24 19:03:55 +00:00
|
|
|
|
var byName = item as IItemByName;
|
|
|
|
|
|
2015-08-31 04:57:12 +00:00
|
|
|
|
if (byName != null)
|
2015-01-24 19:03:55 +00:00
|
|
|
|
{
|
2015-04-04 02:34:53 +00:00
|
|
|
|
if (options.Fields.Contains(ItemFields.ItemCounts))
|
2015-03-26 04:44:24 +00:00
|
|
|
|
{
|
2016-05-11 02:21:28 +00:00
|
|
|
|
var libraryItems = byName.GetTaggedItems(new InternalItemsQuery(user)
|
|
|
|
|
{
|
2017-05-21 07:25:49 +00:00
|
|
|
|
Recursive = true,
|
|
|
|
|
DtoOptions = new DtoOptions(false)
|
|
|
|
|
{
|
|
|
|
|
EnableImages = false
|
|
|
|
|
}
|
2016-05-11 02:21:28 +00:00
|
|
|
|
});
|
2015-01-24 19:03:55 +00:00
|
|
|
|
|
2015-03-26 04:44:24 +00:00
|
|
|
|
SetItemByNameInfo(item, dto, libraryItems.ToList(), user);
|
|
|
|
|
}
|
2015-01-24 19:03:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 06:38:19 +00:00
|
|
|
|
FillSyncInfo(dto, item, options, user, syncDictionary);
|
2015-01-24 19:03:55 +00:00
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
|
returnItems[index] = dto;
|
|
|
|
|
index++;
|
2015-01-24 19:03:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 18:42:39 +00:00
|
|
|
|
if (programTuples.Count > 0)
|
|
|
|
|
{
|
2017-08-28 00:33:05 +00:00
|
|
|
|
var task = _livetvManager().AddInfoToProgramDto(programTuples, options.Fields, user);
|
|
|
|
|
Task.WaitAll(task);
|
2016-03-02 18:42:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-22 06:49:36 +00:00
|
|
|
|
if (channelTuples.Count > 0)
|
|
|
|
|
{
|
2017-08-28 00:33:05 +00:00
|
|
|
|
_livetvManager().AddChannelInfo(channelTuples, options, user);
|
2016-03-22 06:49:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-19 19:43:35 +00:00
|
|
|
|
return returnItems;
|
2015-01-24 19:03:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 19:01:33 +00:00
|
|
|
|
public BaseItemDto GetBaseItemDto(BaseItem item, DtoOptions options, User user = null, BaseItem owner = null)
|
|
|
|
|
{
|
2016-08-03 06:38:19 +00:00
|
|
|
|
var syncDictionary = GetSyncedItemProgress(options);
|
2015-06-02 17:46:44 +00:00
|
|
|
|
|
2017-10-16 06:10:55 +00:00
|
|
|
|
var allCollectionFolders = _libraryManager.GetUserRootFolder().Children.OfType<Folder>().ToList();
|
|
|
|
|
var dto = GetBaseItemDtoInternal(item, options, allCollectionFolders, user, owner);
|
2016-03-22 06:49:36 +00:00
|
|
|
|
var tvChannel = item as LiveTvChannel;
|
|
|
|
|
if (tvChannel != null)
|
|
|
|
|
{
|
|
|
|
|
var list = new List<Tuple<BaseItemDto, LiveTvChannel>> { new Tuple<BaseItemDto, LiveTvChannel>(dto, tvChannel) };
|
2017-08-28 00:33:05 +00:00
|
|
|
|
_livetvManager().AddChannelInfo(list, options, user);
|
2016-03-22 06:49:36 +00:00
|
|
|
|
}
|
|
|
|
|
else if (item is LiveTvProgram)
|
2016-03-02 18:42:39 +00: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 19:35:30 +00:00
|
|
|
|
var byName = item as IItemByName;
|
|
|
|
|
|
2015-08-31 04:57:12 +00:00
|
|
|
|
if (byName != null)
|
2014-06-28 19:35:30 +00:00
|
|
|
|
{
|
2015-04-04 02:34:53 +00:00
|
|
|
|
if (options.Fields.Contains(ItemFields.ItemCounts))
|
2015-03-26 04:44:24 +00:00
|
|
|
|
{
|
2017-05-21 07:25:49 +00:00
|
|
|
|
SetItemByNameInfo(item, dto, GetTaggedItems(byName, user, new DtoOptions(false)
|
|
|
|
|
{
|
|
|
|
|
EnableImages = false
|
|
|
|
|
|
|
|
|
|
}), user);
|
2015-03-26 04:44:24 +00:00
|
|
|
|
}
|
2014-06-28 19:35:30 +00:00
|
|
|
|
|
2016-08-03 06:38:19 +00:00
|
|
|
|
FillSyncInfo(dto, item, options, user, syncDictionary);
|
2014-06-28 19:35:30 +00:00
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 06:38:19 +00:00
|
|
|
|
FillSyncInfo(dto, item, options, user, syncDictionary);
|
2015-01-24 19:03:55 +00:00
|
|
|
|
|
2014-07-27 22:01:29 +00:00
|
|
|
|
return dto;
|
2014-06-28 19:35:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-21 07:25:49 +00:00
|
|
|
|
private List<BaseItem> GetTaggedItems(IItemByName byName, User user, DtoOptions options)
|
2015-07-08 16:10:34 +00:00
|
|
|
|
{
|
2016-05-10 19:20:17 +00:00
|
|
|
|
var items = byName.GetTaggedItems(new InternalItemsQuery(user)
|
2015-07-08 16:10:34 +00:00
|
|
|
|
{
|
2017-05-21 07:25:49 +00:00
|
|
|
|
Recursive = true,
|
|
|
|
|
DtoOptions = options
|
2015-07-08 16:10:34 +00:00
|
|
|
|
|
2016-05-10 19:20:17 +00:00
|
|
|
|
}).ToList();
|
2015-07-08 16:10:34 +00:00
|
|
|
|
|
2016-05-10 19:20:17 +00:00
|
|
|
|
return items;
|
2015-07-08 16:10:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 06:38:19 +00:00
|
|
|
|
public Dictionary<string, SyncedItemProgress> GetSyncedItemProgress(DtoOptions options)
|
2015-01-24 19:03:55 +00:00
|
|
|
|
{
|
2016-08-03 06:38:19 +00:00
|
|
|
|
if (!options.Fields.Contains(ItemFields.BasicSyncInfo) &&
|
|
|
|
|
!options.Fields.Contains(ItemFields.SyncInfo))
|
2015-01-24 19:03:55 +00:00
|
|
|
|
{
|
2016-08-03 06:38:19 +00:00
|
|
|
|
return new Dictionary<string, SyncedItemProgress>();
|
2015-01-24 19:03:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var deviceId = options.DeviceId;
|
|
|
|
|
if (string.IsNullOrWhiteSpace(deviceId))
|
|
|
|
|
{
|
2016-08-03 06:38:19 +00:00
|
|
|
|
return new Dictionary<string, SyncedItemProgress>();
|
2015-01-24 19:03:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var caps = _deviceManager().GetCapabilities(deviceId);
|
|
|
|
|
if (caps == null || !caps.SupportsSync)
|
|
|
|
|
{
|
2016-08-03 06:38:19 +00:00
|
|
|
|
return new Dictionary<string, SyncedItemProgress>();
|
2015-01-24 19:03:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-02 17:46:44 +00:00
|
|
|
|
return _syncManager.GetSyncedItemProgresses(new SyncJobItemQuery
|
2015-01-24 19:03:55 +00:00
|
|
|
|
{
|
2015-01-25 06:34:50 +00:00
|
|
|
|
TargetId = deviceId,
|
2015-04-04 02:16:42 +00:00
|
|
|
|
Statuses = new[]
|
2015-01-25 06:34:50 +00:00
|
|
|
|
{
|
|
|
|
|
SyncJobItemStatus.Converting,
|
|
|
|
|
SyncJobItemStatus.Queued,
|
2015-02-05 03:01:37 +00:00
|
|
|
|
SyncJobItemStatus.Transferring,
|
2015-06-02 17:46:44 +00:00
|
|
|
|
SyncJobItemStatus.ReadyToTransfer,
|
2015-04-04 02:16:42 +00:00
|
|
|
|
SyncJobItemStatus.Synced
|
|
|
|
|
}
|
2016-08-03 06:38:19 +00:00
|
|
|
|
});
|
2015-01-24 19:03:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-11 18:29:42 +00:00
|
|
|
|
public void FillSyncInfo(IEnumerable<Tuple<BaseItem, BaseItemDto>> tuples, DtoOptions options, User user)
|
2015-04-12 18:58:21 +00:00
|
|
|
|
{
|
2016-08-03 06:38:19 +00:00
|
|
|
|
if (options.Fields.Contains(ItemFields.BasicSyncInfo) ||
|
|
|
|
|
options.Fields.Contains(ItemFields.SyncInfo))
|
2015-04-12 18:58:21 +00:00
|
|
|
|
{
|
2015-06-02 17:46:44 +00:00
|
|
|
|
var syncProgress = GetSyncedItemProgress(options);
|
2015-04-12 18:58:21 +00:00
|
|
|
|
|
2016-02-11 18:29:42 +00:00
|
|
|
|
foreach (var tuple in tuples)
|
2015-04-12 18:58:21 +00:00
|
|
|
|
{
|
2016-02-11 18:29:42 +00:00
|
|
|
|
var item = tuple.Item1;
|
2015-04-12 18:58:21 +00:00
|
|
|
|
|
2016-08-02 05:55:52 +00:00
|
|
|
|
FillSyncInfo(tuple.Item2, item, options, user, syncProgress);
|
2015-04-12 18:58:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 06:38:19 +00:00
|
|
|
|
private void FillSyncInfo(IHasSyncInfo dto, BaseItem item, DtoOptions options, User user, Dictionary<string, SyncedItemProgress> syncProgress)
|
2015-01-24 19:03:55 +00:00
|
|
|
|
{
|
2016-08-02 05:55:52 +00:00
|
|
|
|
var hasFullSyncInfo = options.Fields.Contains(ItemFields.SyncInfo);
|
2015-04-12 18:58:21 +00:00
|
|
|
|
|
2017-09-07 18:17:18 +00:00
|
|
|
|
if (!hasFullSyncInfo && !options.Fields.Contains(ItemFields.BasicSyncInfo))
|
2015-01-24 19:03:55 +00:00
|
|
|
|
{
|
2016-08-03 06:38:19 +00:00
|
|
|
|
return;
|
2015-01-24 19:03:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dto.SupportsSync ?? false)
|
|
|
|
|
{
|
2016-08-03 06:38:19 +00:00
|
|
|
|
SyncedItemProgress syncStatus;
|
|
|
|
|
if (syncProgress.TryGetValue(dto.Id, out syncStatus))
|
2015-04-12 18:58:21 +00:00
|
|
|
|
{
|
2016-08-03 06:38:19 +00:00
|
|
|
|
if (syncStatus.Status == SyncJobItemStatus.Synced)
|
2016-08-02 05:55:52 +00:00
|
|
|
|
{
|
2016-08-03 06:38:19 +00:00
|
|
|
|
dto.SyncPercent = 100;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dto.SyncPercent = syncStatus.Progress;
|
2016-08-02 05:55:52 +00:00
|
|
|
|
}
|
2015-04-12 18:58:21 +00:00
|
|
|
|
|
2016-08-03 06:38:19 +00:00
|
|
|
|
if (hasFullSyncInfo)
|
2016-08-02 05:55:52 +00:00
|
|
|
|
{
|
2016-08-03 06:38:19 +00:00
|
|
|
|
dto.HasSyncJob = true;
|
|
|
|
|
dto.SyncStatus = syncStatus.Status;
|
2016-08-02 05:55:52 +00:00
|
|
|
|
}
|
2015-04-12 18:58:21 +00:00
|
|
|
|
}
|
2015-01-24 19:03:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-16 06:10:55 +00:00
|
|
|
|
private BaseItemDto GetBaseItemDtoInternal(BaseItem item, DtoOptions options, List<Folder> allCollectionFolders, User user = null, BaseItem owner = null)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2014-11-30 19:01:33 +00:00
|
|
|
|
var fields = options.Fields;
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
if (item == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("item");
|
|
|
|
|
}
|
2013-05-15 16:56:38 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
if (fields == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("fields");
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 04:54:35 +00:00
|
|
|
|
var dto = new BaseItemDto
|
|
|
|
|
{
|
|
|
|
|
ServerId = _appHost.SystemId
|
|
|
|
|
};
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2016-03-19 19:32:37 +00:00
|
|
|
|
if (item.SourceType == SourceType.Channel)
|
|
|
|
|
{
|
|
|
|
|
dto.SourceType = item.SourceType.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-03 02:59:27 +00:00
|
|
|
|
if (fields.Contains(ItemFields.People))
|
|
|
|
|
{
|
2013-09-17 02:08:18 +00:00
|
|
|
|
AttachPeople(dto, item);
|
2013-04-03 02:59:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.PrimaryImageAspectRatio))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-01-16 05:01:57 +00:00
|
|
|
|
AttachPrimaryImageAspectRatio(dto, item);
|
2013-04-03 02:59:27 +00: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 17:18:56 +00:00
|
|
|
|
if (fields.Contains(ItemFields.DisplayPreferencesId))
|
|
|
|
|
{
|
|
|
|
|
dto.DisplayPreferencesId = item.DisplayPreferencesId.ToString("N");
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-17 20:35:43 +00:00
|
|
|
|
if (user != null)
|
|
|
|
|
{
|
2017-05-26 06:48:54 +00:00
|
|
|
|
AttachUserSpecificInfo(dto, item, user, options);
|
2013-06-17 20:35:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-14 18:24:20 +00:00
|
|
|
|
var hasMediaSources = item as IHasMediaSources;
|
|
|
|
|
if (hasMediaSources != null)
|
|
|
|
|
{
|
|
|
|
|
if (fields.Contains(ItemFields.MediaSources))
|
|
|
|
|
{
|
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
2017-08-05 19:02:33 +00:00
|
|
|
|
dto.MediaSources = _mediaSourceManager().GetStaticMediaSources(hasMediaSources, true);
|
2014-06-14 18:24:20 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-08-05 19:02:33 +00:00
|
|
|
|
dto.MediaSources = _mediaSourceManager().GetStaticMediaSources(hasMediaSources, true, user);
|
2014-06-14 18:24:20 +00:00
|
|
|
|
}
|
2017-08-23 17:27:53 +00:00
|
|
|
|
|
|
|
|
|
NormalizeMediaSourceContainers(dto);
|
2014-06-14 18:24:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-04-04 02:16:42 +00:00
|
|
|
|
|
2013-09-17 02:08:18 +00:00
|
|
|
|
if (fields.Contains(ItemFields.Studios))
|
|
|
|
|
{
|
|
|
|
|
AttachStudios(dto, item);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 19:01:33 +00:00
|
|
|
|
AttachBasicFields(dto, item, owner, options);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2015-07-29 20:31:15 +00:00
|
|
|
|
var collectionFolder = item as ICollectionFolder;
|
|
|
|
|
if (collectionFolder != null)
|
|
|
|
|
{
|
2017-01-11 17:56:26 +00:00
|
|
|
|
dto.CollectionType = collectionFolder.CollectionType;
|
2015-07-29 20:31:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-06 05:39:07 +00: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 15:41:42 +00:00
|
|
|
|
if (fields.Contains(ItemFields.Etag))
|
|
|
|
|
{
|
|
|
|
|
dto.Etag = item.GetEtag(user);
|
|
|
|
|
}
|
2015-04-14 03:45:17 +00:00
|
|
|
|
|
2017-08-23 17:08:17 +00:00
|
|
|
|
var liveTvManager = _livetvManager();
|
2015-05-31 18:22:51 +00:00
|
|
|
|
if (item is ILiveTvRecording)
|
2017-06-23 16:07:32 +00:00
|
|
|
|
{
|
2017-08-23 17:08:17 +00:00
|
|
|
|
liveTvManager.AddInfoToRecordingDto(item, dto, user);
|
2017-06-23 16:07:32 +00:00
|
|
|
|
}
|
2017-08-23 19:45:52 +00:00
|
|
|
|
else
|
2015-05-31 18:22:51 +00:00
|
|
|
|
{
|
2017-08-23 19:45:52 +00:00
|
|
|
|
var activeRecording = liveTvManager.GetActiveRecordingInfo(item.Path);
|
|
|
|
|
if (activeRecording != null)
|
|
|
|
|
{
|
|
|
|
|
dto.Type = "Recording";
|
|
|
|
|
dto.CanDownload = false;
|
2017-08-30 18:06:54 +00:00
|
|
|
|
dto.RunTimeTicks = null;
|
|
|
|
|
|
2017-08-23 19:45:52 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(dto.SeriesName))
|
|
|
|
|
{
|
|
|
|
|
dto.EpisodeTitle = dto.Name;
|
|
|
|
|
dto.Name = dto.SeriesName;
|
|
|
|
|
}
|
|
|
|
|
liveTvManager.AddInfoToRecordingDto(item, dto, activeRecording, user);
|
|
|
|
|
}
|
2015-05-31 18:22:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-23 17:27:53 +00:00
|
|
|
|
private void NormalizeMediaSourceContainers(BaseItemDto dto)
|
|
|
|
|
{
|
|
|
|
|
foreach (var mediaSource in dto.MediaSources)
|
|
|
|
|
{
|
|
|
|
|
var container = mediaSource.Container;
|
|
|
|
|
if (string.IsNullOrWhiteSpace(container))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
var containers = container.Split(new[] { ',' });
|
|
|
|
|
if (containers.Length < 2)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var path = mediaSource.Path;
|
|
|
|
|
string fileExtensionContainer = null;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(path))
|
|
|
|
|
{
|
|
|
|
|
path = Path.GetExtension(path);
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(path))
|
|
|
|
|
{
|
|
|
|
|
path = Path.GetExtension(path);
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(path))
|
|
|
|
|
{
|
|
|
|
|
path = path.TrimStart('.');
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(path) && containers.Contains(path, StringComparer.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
fileExtensionContainer = path;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mediaSource.Container = fileExtensionContainer ?? containers[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-03 06:38:19 +00:00
|
|
|
|
public BaseItemDto GetItemByNameDto(BaseItem item, DtoOptions options, List<BaseItem> taggedItems, Dictionary<string, SyncedItemProgress> syncProgress, User user = null)
|
2013-09-10 18:56:00 +00:00
|
|
|
|
{
|
2017-10-16 06:10:55 +00:00
|
|
|
|
var allCollectionFolders = _libraryManager.GetUserRootFolder().Children.OfType<Folder>().ToList();
|
|
|
|
|
var dto = GetBaseItemDtoInternal(item, options, allCollectionFolders, user);
|
2014-06-28 19:35:30 +00:00
|
|
|
|
|
2016-06-17 13:06:13 +00:00
|
|
|
|
if (taggedItems != null && options.Fields.Contains(ItemFields.ItemCounts))
|
2015-03-26 04:44:24 +00:00
|
|
|
|
{
|
|
|
|
|
SetItemByNameInfo(item, dto, taggedItems, user);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-02 17:46:44 +00:00
|
|
|
|
FillSyncInfo(dto, item, options, user, syncProgress);
|
2014-03-09 22:14:44 +00:00
|
|
|
|
|
2014-06-28 19:35:30 +00:00
|
|
|
|
return dto;
|
2014-03-09 22:14:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-28 19:35:30 +00:00
|
|
|
|
private void SetItemByNameInfo(BaseItem item, BaseItemDto dto, List<BaseItem> taggedItems, User user = null)
|
2014-03-09 22:14:44 +00:00
|
|
|
|
{
|
2016-08-13 20:54:29 +00:00
|
|
|
|
if (item is MusicArtist)
|
2013-09-10 18:56:00 +00:00
|
|
|
|
{
|
2014-03-09 22:14:44 +00: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);
|
|
|
|
|
}
|
2016-08-13 20:54:29 +00:00
|
|
|
|
else if (item is MusicGenre)
|
|
|
|
|
{
|
|
|
|
|
dto.ArtistCount = taggedItems.Count(i => i is MusicArtist);
|
|
|
|
|
dto.AlbumCount = taggedItems.Count(i => i is MusicAlbum);
|
|
|
|
|
dto.MusicVideoCount = taggedItems.Count(i => i is MusicVideo);
|
|
|
|
|
dto.SongCount = taggedItems.Count(i => i is Audio);
|
|
|
|
|
}
|
2014-03-09 22:14:44 +00:00
|
|
|
|
else if (item is GameGenre)
|
|
|
|
|
{
|
|
|
|
|
dto.GameCount = taggedItems.Count(i => i is Game);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// This populates them all and covers Genre, Person, Studio, Year
|
|
|
|
|
|
2016-08-13 20:54:29 +00:00
|
|
|
|
dto.ArtistCount = taggedItems.Count(i => i is MusicArtist);
|
2014-03-09 22:14:44 +00:00
|
|
|
|
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 21:55:42 +00:00
|
|
|
|
dto.TrailerCount = taggedItems.Count(i => i is Trailer);
|
2014-03-09 22:14:44 +00:00
|
|
|
|
dto.MusicVideoCount = taggedItems.Count(i => i is MusicVideo);
|
|
|
|
|
dto.SeriesCount = taggedItems.Count(i => i is Series);
|
2016-09-14 16:21:33 +00:00
|
|
|
|
dto.ProgramCount = taggedItems.Count(i => i is LiveTvProgram);
|
2014-03-09 22:14:44 +00:00
|
|
|
|
dto.SongCount = taggedItems.Count(i => i is Audio);
|
2013-09-10 18:56:00 +00:00
|
|
|
|
}
|
2013-12-02 21:46:22 +00:00
|
|
|
|
|
2014-03-09 22:14:44 +00:00
|
|
|
|
dto.ChildCount = taggedItems.Count;
|
2013-09-10 18:56:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Attaches the user specific info.
|
|
|
|
|
/// </summary>
|
2017-05-26 06:48:54 +00:00
|
|
|
|
private void AttachUserSpecificInfo(BaseItemDto dto, BaseItem item, User user, DtoOptions dtoOptions)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2016-08-17 19:28:43 +00:00
|
|
|
|
var fields = dtoOptions.Fields;
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
if (item.IsFolder)
|
|
|
|
|
{
|
2013-09-23 14:26:20 +00:00
|
|
|
|
var folder = (Folder)item;
|
2013-07-25 19:17:44 +00:00
|
|
|
|
|
2016-08-17 19:28:43 +00:00
|
|
|
|
if (dtoOptions.EnableUserData)
|
|
|
|
|
{
|
2017-05-26 06:48:54 +00:00
|
|
|
|
dto.UserData = _userDataRepository.GetUserDataDto(item, dto, user, dtoOptions.Fields);
|
2016-08-17 19:28:43 +00:00
|
|
|
|
}
|
2016-06-15 18:56:37 +00:00
|
|
|
|
|
2016-08-16 17:08:37 +00:00
|
|
|
|
if (!dto.ChildCount.HasValue && item.SourceType == SourceType.Library)
|
2016-06-15 18:56:37 +00:00
|
|
|
|
{
|
2016-12-13 07:36:30 +00:00
|
|
|
|
// For these types we can try to optimize and assume these values will be equal
|
|
|
|
|
if (item is MusicAlbum || item is Season)
|
|
|
|
|
{
|
|
|
|
|
dto.ChildCount = dto.RecursiveItemCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dtoOptions.Fields.Contains(ItemFields.ChildCount))
|
|
|
|
|
{
|
|
|
|
|
dto.ChildCount = dto.ChildCount ?? GetChildCount(folder, user);
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2013-05-08 01:17:41 +00:00
|
|
|
|
|
2016-05-09 03:13:38 +00:00
|
|
|
|
if (fields.Contains(ItemFields.CumulativeRunTimeTicks))
|
|
|
|
|
{
|
2016-05-10 18:13:26 +00:00
|
|
|
|
dto.CumulativeRunTimeTicks = item.RunTimeTicks;
|
2016-05-09 03:13:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.DateLastMediaAdded))
|
|
|
|
|
{
|
|
|
|
|
dto.DateLastMediaAdded = folder.DateLastMediaAdded;
|
|
|
|
|
}
|
2014-07-04 02:22:57 +00:00
|
|
|
|
}
|
2013-05-08 01:17:41 +00:00
|
|
|
|
|
2014-07-04 02:22:57 +00:00
|
|
|
|
else
|
2013-07-16 17:18:32 +00:00
|
|
|
|
{
|
2016-08-17 19:28:43 +00:00
|
|
|
|
if (dtoOptions.EnableUserData)
|
|
|
|
|
{
|
2017-05-26 06:48:54 +00:00
|
|
|
|
dto.UserData = _userDataRepository.GetUserDataDto(item, user);
|
2016-08-17 19:28:43 +00:00
|
|
|
|
}
|
2013-05-08 01:17:41 +00:00
|
|
|
|
}
|
2014-02-21 05:35:56 +00:00
|
|
|
|
|
2017-09-21 21:36:19 +00:00
|
|
|
|
if (/*!(item is LiveTvProgram) ||*/ fields.Contains(ItemFields.PlayAccess))
|
2017-02-18 08:32:17 +00:00
|
|
|
|
{
|
|
|
|
|
dto.PlayAccess = item.GetPlayAccess(user);
|
|
|
|
|
}
|
2014-12-27 05:08:39 +00:00
|
|
|
|
|
2016-08-03 06:38:19 +00:00
|
|
|
|
if (fields.Contains(ItemFields.BasicSyncInfo) || fields.Contains(ItemFields.SyncInfo))
|
|
|
|
|
{
|
2017-04-25 18:23:20 +00:00
|
|
|
|
var userCanSync = user != null && user.Policy.EnableContentDownloading;
|
2016-08-17 19:28:43 +00:00
|
|
|
|
if (userCanSync && _syncManager.SupportsSync(item))
|
|
|
|
|
{
|
|
|
|
|
dto.SupportsSync = true;
|
|
|
|
|
}
|
2016-08-03 06:38:19 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2013-04-13 18:02:30 +00:00
|
|
|
|
|
2013-12-10 20:42:42 +00:00
|
|
|
|
private int GetChildCount(Folder folder, User user)
|
|
|
|
|
{
|
2016-06-18 17:26:42 +00:00
|
|
|
|
// Right now this is too slow to calculate for top level folders on a per-user basis
|
|
|
|
|
// Just return something so that apps that are expecting a value won't think the folders are empty
|
|
|
|
|
if (folder is ICollectionFolder || folder is UserView)
|
|
|
|
|
{
|
|
|
|
|
return new Random().Next(1, 10);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-16 13:24:12 +00:00
|
|
|
|
return folder.GetChildCount(user);
|
2013-12-10 20:42:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:02:19 +00: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 14:13:47 +00:00
|
|
|
|
{
|
2013-09-04 17:02:19 +00:00
|
|
|
|
throw new ArgumentNullException("item");
|
2013-04-12 14:13:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
return item.Id.ToString("N");
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00: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 01:33:05 +00:00
|
|
|
|
{
|
2013-09-04 17:02:19 +00:00
|
|
|
|
throw new ArgumentNullException("data");
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
return new UserItemDataDto
|
2013-06-12 03:00:23 +00:00
|
|
|
|
{
|
2013-09-04 17:02:19 +00:00
|
|
|
|
IsFavorite = data.IsFavorite,
|
|
|
|
|
Likes = data.Likes,
|
|
|
|
|
PlaybackPositionTicks = data.PlaybackPositionTicks,
|
|
|
|
|
PlayCount = data.PlayCount,
|
|
|
|
|
Rating = data.Rating,
|
|
|
|
|
Played = data.Played,
|
2013-10-03 18:02:23 +00:00
|
|
|
|
LastPlayedDate = data.LastPlayedDate,
|
|
|
|
|
Key = data.Key
|
2013-09-04 17:02:19 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
private void SetBookProperties(BaseItemDto dto, Book item)
|
|
|
|
|
{
|
|
|
|
|
dto.SeriesName = item.SeriesName;
|
|
|
|
|
}
|
2014-08-29 00:49:25 +00: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 14:26:29 +00:00
|
|
|
|
|
|
|
|
|
dto.Latitude = item.Latitude;
|
|
|
|
|
dto.Longitude = item.Longitude;
|
|
|
|
|
dto.Altitude = item.Altitude;
|
|
|
|
|
dto.IsoSpeedRating = item.IsoSpeedRating;
|
2014-10-12 15:18:26 +00:00
|
|
|
|
|
2016-10-11 06:46:59 +00:00
|
|
|
|
var album = item.AlbumEntity;
|
2014-08-30 14:26:29 +00:00
|
|
|
|
|
|
|
|
|
if (album != null)
|
|
|
|
|
{
|
2014-09-03 02:30:24 +00:00
|
|
|
|
dto.Album = album.Name;
|
|
|
|
|
dto.AlbumId = album.Id.ToString("N");
|
2014-08-30 14:26:29 +00:00
|
|
|
|
}
|
2014-08-29 00:49:25 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
private void SetMusicVideoProperties(BaseItemDto dto, MusicVideo item)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(item.Album))
|
|
|
|
|
{
|
2017-05-21 07:25:49 +00:00
|
|
|
|
var parentAlbumIds = _libraryManager.GetItemIds(new InternalItemsQuery
|
2016-05-11 14:36:28 +00:00
|
|
|
|
{
|
|
|
|
|
IncludeItemTypes = new[] { typeof(MusicAlbum).Name },
|
2017-05-21 07:25:49 +00:00
|
|
|
|
Name = item.Album,
|
|
|
|
|
Limit = 1
|
2016-05-11 14:36:28 +00:00
|
|
|
|
|
2017-05-21 07:25:49 +00:00
|
|
|
|
});
|
2013-07-06 00:19:44 +00:00
|
|
|
|
|
2017-05-21 07:25:49 +00:00
|
|
|
|
if (parentAlbumIds.Count > 0)
|
2013-07-06 00:19:44 +00:00
|
|
|
|
{
|
2017-05-21 07:25:49 +00:00
|
|
|
|
dto.AlbumId = parentAlbumIds[0].ToString("N");
|
2013-07-06 00:19:44 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
dto.Album = item.Album;
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
private void SetGameProperties(BaseItemDto dto, Game item)
|
|
|
|
|
{
|
|
|
|
|
dto.GameSystem = item.GameSystem;
|
2014-04-27 03:42:05 +00:00
|
|
|
|
dto.MultiPartGameFiles = item.MultiPartGameFiles;
|
2013-09-04 17:02:19 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-10-27 21:40:42 +00:00
|
|
|
|
private void SetGameSystemProperties(BaseItemDto dto, GameSystem item)
|
|
|
|
|
{
|
|
|
|
|
dto.GameSystem = item.GameSystemName;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-09 19:56:38 +00:00
|
|
|
|
private string[] GetImageTags(BaseItem item, List<ItemImageInfo> images)
|
2013-09-04 17:02:19 +00:00
|
|
|
|
{
|
2016-07-05 05:40:18 +00:00
|
|
|
|
return images
|
|
|
|
|
.Select(p => GetImageCacheTag(item, p))
|
|
|
|
|
.Where(i => i != null)
|
2017-08-09 19:56:38 +00:00
|
|
|
|
.ToArray();
|
2014-02-07 20:30:41 +00:00
|
|
|
|
}
|
2013-12-05 16:50:21 +00:00
|
|
|
|
|
2014-05-08 20:09:53 +00:00
|
|
|
|
private string GetImageCacheTag(BaseItem item, ImageType type)
|
2014-02-07 20:30:41 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _imageProcessor.GetImageCacheTag(item, type);
|
|
|
|
|
}
|
2014-04-13 17:27:13 +00:00
|
|
|
|
catch (Exception ex)
|
2014-02-07 20:30:41 +00:00
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error getting {0} image info", ex, type);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 20:09:53 +00:00
|
|
|
|
private string GetImageCacheTag(BaseItem item, ItemImageInfo image)
|
2013-09-04 17:02:19 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2014-02-07 20:30:41 +00:00
|
|
|
|
return _imageProcessor.GetImageCacheTag(item, image);
|
2013-03-12 22:49:45 +00:00
|
|
|
|
}
|
2014-04-13 17:27:13 +00:00
|
|
|
|
catch (Exception ex)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2014-02-07 20:30:41 +00:00
|
|
|
|
_logger.ErrorException("Error getting {0} image info for {1}", ex, image.Type, image.Path);
|
2013-09-04 17:02:19 +00:00
|
|
|
|
return null;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2013-09-17 02:08:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 18:56:00 +00:00
|
|
|
|
/// <summary>
|
2013-09-04 17:02:19 +00: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 02:08:18 +00:00
|
|
|
|
private void AttachPeople(BaseItemDto dto, BaseItem item)
|
2013-09-04 17:02:19 +00: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 03:35:22 +00:00
|
|
|
|
var people = _libraryManager.GetPeople(item).OrderBy(i => i.SortOrder ?? int.MaxValue)
|
2014-06-30 13:28:38 +00: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 01:33:05 +00:00
|
|
|
|
|
2014-11-21 14:28:30 +00:00
|
|
|
|
var list = new List<BaseItemPerson>();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-09-17 02:08:18 +00:00
|
|
|
|
var dictionary = people.Select(p => p.Name)
|
2013-09-04 17:02:19 +00:00
|
|
|
|
.Distinct(StringComparer.OrdinalIgnoreCase).Select(c =>
|
2013-09-17 02:08:18 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _libraryManager.GetPerson(c);
|
|
|
|
|
}
|
2014-08-25 03:54:45 +00:00
|
|
|
|
catch (Exception ex)
|
2013-09-04 17:02:19 +00:00
|
|
|
|
{
|
2013-09-17 02:08:18 +00:00
|
|
|
|
_logger.ErrorException("Error getting person {0}", ex, c);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}).Where(i => i != null)
|
2015-07-01 15:47:41 +00:00
|
|
|
|
.DistinctBy(i => i.Name, StringComparer.OrdinalIgnoreCase)
|
2013-09-04 17:02:19 +00:00
|
|
|
|
.ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < people.Count; i++)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-09-04 17:02:19 +00:00
|
|
|
|
var person = people[i];
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
var baseItemPerson = new BaseItemPerson
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-09-04 17:02:19 +00:00
|
|
|
|
Name = person.Name,
|
|
|
|
|
Role = person.Role,
|
|
|
|
|
Type = person.Type
|
|
|
|
|
};
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
Person entity;
|
|
|
|
|
|
|
|
|
|
if (dictionary.TryGetValue(person.Name, out entity))
|
|
|
|
|
{
|
2014-02-07 20:30:41 +00:00
|
|
|
|
baseItemPerson.PrimaryImageTag = GetImageCacheTag(entity, ImageType.Primary);
|
2014-05-11 22:38:10 +00:00
|
|
|
|
baseItemPerson.Id = entity.Id.ToString("N");
|
2014-11-21 14:28:30 +00:00
|
|
|
|
list.Add(baseItemPerson);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-21 14:28:30 +00:00
|
|
|
|
|
2017-08-09 19:56:38 +00:00
|
|
|
|
dto.People = list.ToArray(list.Count);
|
2013-09-04 17:02:19 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Attaches the studios.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dto">The dto.</param>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
2013-09-17 02:08:18 +00:00
|
|
|
|
private void AttachStudios(BaseItemDto dto, BaseItem item)
|
2013-09-04 17:02:19 +00:00
|
|
|
|
{
|
2017-05-18 21:05:47 +00:00
|
|
|
|
dto.Studios = item.Studios
|
|
|
|
|
.Where(i => !string.IsNullOrWhiteSpace(i))
|
|
|
|
|
.Select(i => new NameIdPair
|
2013-09-17 02:08:18 +00:00
|
|
|
|
{
|
2017-05-18 21:05:47 +00:00
|
|
|
|
Name = i,
|
|
|
|
|
Id = _libraryManager.GetStudioId(i).ToString("N")
|
|
|
|
|
})
|
|
|
|
|
.ToArray();
|
|
|
|
|
}
|
2013-07-08 19:31:45 +00:00
|
|
|
|
|
2017-05-18 21:05:47 +00:00
|
|
|
|
private void AttachGenreItems(BaseItemDto dto, BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
dto.GenreItems = item.Genres
|
|
|
|
|
.Where(i => !string.IsNullOrWhiteSpace(i))
|
|
|
|
|
.Select(i => new NameIdPair
|
2013-07-08 19:31:45 +00:00
|
|
|
|
{
|
2017-05-18 21:05:47 +00:00
|
|
|
|
Name = i,
|
2017-06-18 07:11:55 +00:00
|
|
|
|
Id = GetGenreId(i, item)
|
2017-05-18 21:05:47 +00:00
|
|
|
|
})
|
|
|
|
|
.ToArray();
|
|
|
|
|
}
|
2013-09-04 17:02:19 +00:00
|
|
|
|
|
2017-06-18 07:11:55 +00:00
|
|
|
|
private string GetGenreId(string name, BaseItem owner)
|
2017-05-18 21:05:47 +00:00
|
|
|
|
{
|
|
|
|
|
if (owner is IHasMusicGenres)
|
|
|
|
|
{
|
2017-06-18 07:11:55 +00:00
|
|
|
|
return _libraryManager.GetMusicGenreId(name).ToString("N");
|
2017-05-18 21:05:47 +00:00
|
|
|
|
}
|
2013-07-08 19:31:45 +00:00
|
|
|
|
|
2017-05-18 21:05:47 +00:00
|
|
|
|
if (owner is Game || owner is GameSystem)
|
|
|
|
|
{
|
|
|
|
|
return _libraryManager.GetGameGenreId(name).ToString("N");
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2017-05-18 21:05:47 +00:00
|
|
|
|
|
|
|
|
|
return _libraryManager.GetGenreId(name).ToString("N");
|
2013-09-04 17:02:19 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
/// <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 15:18:26 +00:00
|
|
|
|
private ChapterInfoDto GetChapterInfoDto(ChapterInfo chapterInfo, BaseItem item)
|
2013-09-04 17:02:19 +00:00
|
|
|
|
{
|
|
|
|
|
var dto = new ChapterInfoDto
|
2013-06-25 01:22:21 +00:00
|
|
|
|
{
|
2013-09-04 17:02:19 +00:00
|
|
|
|
Name = chapterInfo.Name,
|
|
|
|
|
StartPositionTicks = chapterInfo.StartPositionTicks
|
|
|
|
|
};
|
2013-07-06 00:19:44 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(chapterInfo.ImagePath))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2014-02-07 20:30:41 +00:00
|
|
|
|
dto.ImageTag = GetImageCacheTag(item, new ItemImageInfo
|
|
|
|
|
{
|
|
|
|
|
Path = chapterInfo.ImagePath,
|
|
|
|
|
Type = ImageType.Chapter,
|
2016-07-06 17:44:44 +00:00
|
|
|
|
DateModified = chapterInfo.ImageDateModified
|
2014-02-07 20:30:41 +00:00
|
|
|
|
});
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-12 15:18:26 +00:00
|
|
|
|
public List<ChapterInfoDto> GetChapterInfoDtos(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
return _itemRepo.GetChapters(item.Id)
|
|
|
|
|
.Select(c => GetChapterInfoDto(c, item))
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:02:19 +00: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 19:01:33 +00:00
|
|
|
|
/// <param name="options">The options.</param>
|
|
|
|
|
private void AttachBasicFields(BaseItemDto dto, BaseItem item, BaseItem owner, DtoOptions options)
|
2013-09-04 17:02:19 +00:00
|
|
|
|
{
|
2014-11-30 19:01:33 +00:00
|
|
|
|
var fields = options.Fields;
|
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
if (fields.Contains(ItemFields.DateCreated))
|
2013-05-24 04:02:42 +00:00
|
|
|
|
{
|
2013-09-04 17:02:19 +00:00
|
|
|
|
dto.DateCreated = item.DateCreated;
|
2013-05-24 04:02:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-21 05:57:06 +00:00
|
|
|
|
if (fields.Contains(ItemFields.Settings))
|
2013-09-04 17:02:19 +00:00
|
|
|
|
{
|
|
|
|
|
dto.LockedFields = item.LockedFields;
|
2014-03-22 16:16:43 +00:00
|
|
|
|
dto.LockData = item.IsLocked;
|
2014-03-24 17:54:45 +00:00
|
|
|
|
dto.ForcedSortName = item.ForcedSortName;
|
2013-07-16 16:03:28 +00:00
|
|
|
|
}
|
2016-07-17 16:59:50 +00:00
|
|
|
|
dto.Container = item.Container;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
dto.EndDate = item.EndDate;
|
2013-04-24 22:34:38 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
if (fields.Contains(ItemFields.HomePageUrl))
|
2013-04-24 22:34:38 +00:00
|
|
|
|
{
|
2013-09-04 17:02:19 +00:00
|
|
|
|
dto.HomePageUrl = item.HomePageUrl;
|
2013-04-24 22:34:38 +00:00
|
|
|
|
}
|
2013-07-12 19:56:40 +00:00
|
|
|
|
|
2014-02-21 18:48:15 +00:00
|
|
|
|
if (fields.Contains(ItemFields.ExternalUrls))
|
|
|
|
|
{
|
|
|
|
|
dto.ExternalUrls = _providerManager.GetExternalUrls(item).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
if (fields.Contains(ItemFields.Tags))
|
|
|
|
|
{
|
2016-06-02 17:43:29 +00:00
|
|
|
|
dto.Tags = item.Tags;
|
2013-09-04 17:02:19 +00:00
|
|
|
|
}
|
2013-07-12 19:56:40 +00:00
|
|
|
|
|
2013-11-20 03:15:48 +00:00
|
|
|
|
var hasAspectRatio = item as IHasAspectRatio;
|
|
|
|
|
if (hasAspectRatio != null)
|
|
|
|
|
{
|
|
|
|
|
dto.AspectRatio = hasAspectRatio.AspectRatio;
|
|
|
|
|
}
|
2013-08-30 23:55:17 +00:00
|
|
|
|
|
2014-11-30 19:01:33 +00:00
|
|
|
|
var backdropLimit = options.GetImageLimit(ImageType.Backdrop);
|
|
|
|
|
if (backdropLimit > 0)
|
|
|
|
|
{
|
2016-07-05 05:40:18 +00:00
|
|
|
|
dto.BackdropImageTags = GetImageTags(item, item.GetImages(ImageType.Backdrop).Take(backdropLimit).ToList());
|
2014-11-30 19:01:33 +00:00
|
|
|
|
}
|
2013-09-18 02:43:34 +00:00
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.ScreenshotImageTags))
|
|
|
|
|
{
|
2014-11-30 19:01:33 +00:00
|
|
|
|
var screenshotLimit = options.GetImageLimit(ImageType.Screenshot);
|
|
|
|
|
if (screenshotLimit > 0)
|
|
|
|
|
{
|
2016-07-05 06:05:43 +00:00
|
|
|
|
dto.ScreenshotImageTags = GetImageTags(item, item.GetImages(ImageType.Screenshot).Take(screenshotLimit).ToList());
|
2014-11-30 19:01:33 +00:00
|
|
|
|
}
|
2013-09-18 02:43:34 +00:00
|
|
|
|
}
|
2013-09-04 17:02:19 +00:00
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.Genres))
|
2013-08-30 23:55:17 +00:00
|
|
|
|
{
|
2013-09-04 17:02:19 +00:00
|
|
|
|
dto.Genres = item.Genres;
|
2017-05-18 21:05:47 +00:00
|
|
|
|
AttachGenreItems(dto, item);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-18 05:56:10 +00:00
|
|
|
|
if (options.EnableImages)
|
2013-07-23 00:03:33 +00:00
|
|
|
|
{
|
2016-08-18 05:56:10 +00:00
|
|
|
|
dto.ImageTags = new Dictionary<ImageType, string>();
|
2014-11-30 19:01:33 +00:00
|
|
|
|
|
2016-08-18 05:56:10 +00:00
|
|
|
|
// Prevent implicitly captured closure
|
|
|
|
|
var currentItem = item;
|
|
|
|
|
foreach (var image in currentItem.ImageInfos.Where(i => !currentItem.AllowsMultipleImages(i.Type))
|
|
|
|
|
.ToList())
|
|
|
|
|
{
|
|
|
|
|
if (options.GetImageLimit(image.Type) > 0)
|
2014-11-30 19:01:33 +00:00
|
|
|
|
{
|
2016-08-18 05:56:10 +00:00
|
|
|
|
var tag = GetImageCacheTag(item, image);
|
|
|
|
|
|
|
|
|
|
if (tag != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ImageTags[image.Type] = tag;
|
|
|
|
|
}
|
2014-11-30 19:01:33 +00:00
|
|
|
|
}
|
2013-07-23 00:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
dto.Id = GetDtoId(item);
|
|
|
|
|
dto.IndexNumber = item.IndexNumber;
|
2016-07-05 05:40:18 +00:00
|
|
|
|
dto.ParentIndexNumber = item.ParentIndexNumber;
|
2016-08-17 19:28:43 +00:00
|
|
|
|
|
|
|
|
|
if (item.IsFolder)
|
|
|
|
|
{
|
|
|
|
|
dto.IsFolder = true;
|
|
|
|
|
}
|
|
|
|
|
else if (item is IHasMediaSources)
|
|
|
|
|
{
|
|
|
|
|
dto.IsFolder = false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
dto.MediaType = item.MediaType;
|
2017-02-18 08:32:17 +00:00
|
|
|
|
|
|
|
|
|
if (!(item is LiveTvProgram))
|
|
|
|
|
{
|
|
|
|
|
dto.LocationType = item.LocationType;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-28 19:40:38 +00:00
|
|
|
|
if (item.IsHD.HasValue && item.IsHD.Value)
|
|
|
|
|
{
|
|
|
|
|
dto.IsHD = item.IsHD;
|
|
|
|
|
}
|
|
|
|
|
dto.Audio = item.Audio;
|
2013-09-11 17:54:59 +00:00
|
|
|
|
|
2016-10-08 05:57:38 +00:00
|
|
|
|
if (fields.Contains(ItemFields.Settings))
|
|
|
|
|
{
|
|
|
|
|
dto.PreferredMetadataCountryCode = item.PreferredMetadataCountryCode;
|
|
|
|
|
dto.PreferredMetadataLanguage = item.PreferredMetadataLanguage;
|
|
|
|
|
}
|
2013-12-05 16:50:21 +00:00
|
|
|
|
|
2016-07-04 20:11:30 +00:00
|
|
|
|
dto.CriticRating = item.CriticRating;
|
2013-11-06 16:06:16 +00:00
|
|
|
|
|
2013-12-02 16:46:25 +00:00
|
|
|
|
var hasTrailers = item as IHasTrailers;
|
|
|
|
|
if (hasTrailers != null)
|
|
|
|
|
{
|
2014-12-11 06:20:28 +00:00
|
|
|
|
dto.LocalTrailerCount = hasTrailers.GetTrailerIds().Count;
|
2013-12-02 16:46:25 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2014-01-03 20:32:27 +00:00
|
|
|
|
var hasDisplayOrder = item as IHasDisplayOrder;
|
|
|
|
|
if (hasDisplayOrder != null)
|
|
|
|
|
{
|
|
|
|
|
dto.DisplayOrder = hasDisplayOrder.DisplayOrder;
|
|
|
|
|
}
|
2014-01-04 02:35:41 +00:00
|
|
|
|
|
2014-06-05 02:32:40 +00:00
|
|
|
|
var userView = item as UserView;
|
|
|
|
|
if (userView != null)
|
|
|
|
|
{
|
|
|
|
|
dto.CollectionType = userView.ViewType;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-02 16:46:25 +00:00
|
|
|
|
if (fields.Contains(ItemFields.RemoteTrailers))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-12-02 16:46:25 +00:00
|
|
|
|
dto.RemoteTrailers = hasTrailers != null ?
|
|
|
|
|
hasTrailers.RemoteTrailers :
|
2017-08-19 19:43:35 +00:00
|
|
|
|
new MediaUrl[] { };
|
2013-09-04 17:02:19 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
dto.Name = item.Name;
|
|
|
|
|
dto.OfficialRating = item.OfficialRating;
|
2013-03-09 05:15:51 +00:00
|
|
|
|
|
2014-05-27 14:30:21 +00:00
|
|
|
|
if (fields.Contains(ItemFields.Overview))
|
2013-09-04 17:02:19 +00:00
|
|
|
|
{
|
2014-08-05 23:59:24 +00:00
|
|
|
|
dto.Overview = item.Overview;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-20 05:21:40 +00:00
|
|
|
|
if (fields.Contains(ItemFields.OriginalTitle))
|
|
|
|
|
{
|
|
|
|
|
dto.OriginalTitle = item.OriginalTitle;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 04:54:35 +00:00
|
|
|
|
if (fields.Contains(ItemFields.ParentId))
|
2013-07-25 19:17:44 +00:00
|
|
|
|
{
|
2016-04-09 04:16:53 +00:00
|
|
|
|
var displayParentId = item.DisplayParentId;
|
|
|
|
|
if (displayParentId.HasValue)
|
2014-10-24 04:54:35 +00:00
|
|
|
|
{
|
2016-04-09 04:16:53 +00:00
|
|
|
|
dto.ParentId = displayParentId.Value.ToString("N");
|
2014-10-24 04:54:35 +00:00
|
|
|
|
}
|
2013-07-25 19:17:44 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2016-07-05 05:40:18 +00:00
|
|
|
|
AddInheritedImages(dto, item, options, owner);
|
2013-10-24 17:49:24 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
if (fields.Contains(ItemFields.Path))
|
|
|
|
|
{
|
2017-02-20 20:50:58 +00:00
|
|
|
|
dto.Path = GetMappedPath(item, owner);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
dto.PremiereDate = item.PremiereDate;
|
|
|
|
|
dto.ProductionYear = item.ProductionYear;
|
2013-05-04 03:13:28 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
if (fields.Contains(ItemFields.ProviderIds))
|
|
|
|
|
{
|
|
|
|
|
dto.ProviderIds = item.ProviderIds;
|
|
|
|
|
}
|
2013-05-04 03:13:28 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
dto.RunTimeTicks = item.RunTimeTicks;
|
2013-05-04 03:13:28 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
if (fields.Contains(ItemFields.SortName))
|
|
|
|
|
{
|
|
|
|
|
dto.SortName = item.SortName;
|
|
|
|
|
}
|
2013-05-04 03:13:28 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
if (fields.Contains(ItemFields.CustomRating))
|
|
|
|
|
{
|
|
|
|
|
dto.CustomRating = item.CustomRating;
|
|
|
|
|
}
|
2013-05-04 03:13:28 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
if (fields.Contains(ItemFields.Taglines))
|
|
|
|
|
{
|
2016-10-08 05:57:38 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.Tagline))
|
2013-12-05 16:50:21 +00:00
|
|
|
|
{
|
2017-08-09 19:56:38 +00:00
|
|
|
|
dto.Taglines = new string[] { item.Tagline };
|
2013-12-05 16:50:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dto.Taglines == null)
|
|
|
|
|
{
|
2017-08-19 19:43:35 +00:00
|
|
|
|
dto.Taglines = new string[] { };
|
2013-12-05 16:50:21 +00:00
|
|
|
|
}
|
2013-09-04 17:02:19 +00:00
|
|
|
|
}
|
2013-05-04 03:13:28 +00:00
|
|
|
|
|
2013-11-21 20:48:26 +00:00
|
|
|
|
dto.Type = item.GetClientTypeName();
|
2017-02-18 08:32:17 +00:00
|
|
|
|
if ((item.CommunityRating ?? 0) > 0)
|
|
|
|
|
{
|
|
|
|
|
dto.CommunityRating = item.CommunityRating;
|
|
|
|
|
}
|
2014-11-30 19:01:33 +00:00
|
|
|
|
|
2014-03-03 05:11:03 +00:00
|
|
|
|
var supportsPlaceHolders = item as ISupportsPlaceHolders;
|
2017-06-12 07:11:54 +00:00
|
|
|
|
if (supportsPlaceHolders != null && supportsPlaceHolders.IsPlaceHolder)
|
2014-03-03 05:11:03 +00:00
|
|
|
|
{
|
|
|
|
|
dto.IsPlaceHolder = supportsPlaceHolders.IsPlaceHolder;
|
|
|
|
|
}
|
2014-03-22 16:16:43 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
// Add audio info
|
|
|
|
|
var audio = item as Audio;
|
|
|
|
|
if (audio != null)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-09-04 17:02:19 +00:00
|
|
|
|
dto.Album = audio.Album;
|
2017-06-11 20:40:25 +00:00
|
|
|
|
if (audio.ExtraType.HasValue)
|
|
|
|
|
{
|
|
|
|
|
dto.ExtraType = audio.ExtraType.Value.ToString();
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2015-05-04 14:35:38 +00:00
|
|
|
|
var albumParent = audio.AlbumEntity;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
if (albumParent != null)
|
|
|
|
|
{
|
|
|
|
|
dto.AlbumId = GetDtoId(albumParent);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2014-02-07 20:30:41 +00:00
|
|
|
|
dto.AlbumPrimaryImageTag = GetImageCacheTag(albumParent, ImageType.Primary);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2014-03-21 03:31:40 +00:00
|
|
|
|
|
2014-12-01 12:43:34 +00:00
|
|
|
|
//if (fields.Contains(ItemFields.MediaSourceCount))
|
|
|
|
|
//{
|
2015-01-24 19:03:55 +00:00
|
|
|
|
// Songs always have one
|
2014-12-01 12:43:34 +00:00
|
|
|
|
//}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-13 17:25:28 +00:00
|
|
|
|
var hasArtist = item as IHasArtist;
|
|
|
|
|
if (hasArtist != null)
|
|
|
|
|
{
|
|
|
|
|
dto.Artists = hasArtist.Artists;
|
|
|
|
|
|
2016-12-13 07:36:30 +00:00
|
|
|
|
//var artistItems = _libraryManager.GetArtists(new InternalItemsQuery
|
|
|
|
|
//{
|
|
|
|
|
// EnableTotalRecordCount = false,
|
|
|
|
|
// ItemIds = new[] { item.Id.ToString("N") }
|
|
|
|
|
//});
|
|
|
|
|
|
|
|
|
|
//dto.ArtistItems = artistItems.Items
|
|
|
|
|
// .Select(i =>
|
|
|
|
|
// {
|
|
|
|
|
// var artist = i.Item1;
|
|
|
|
|
// return new NameIdPair
|
|
|
|
|
// {
|
|
|
|
|
// Name = artist.Name,
|
|
|
|
|
// Id = artist.Id.ToString("N")
|
|
|
|
|
// };
|
|
|
|
|
// })
|
|
|
|
|
// .ToList();
|
2016-09-06 05:02:05 +00:00
|
|
|
|
|
|
|
|
|
// Include artists that are not in the database yet, e.g., just added via metadata editor
|
2016-12-13 07:36:30 +00:00
|
|
|
|
//var foundArtists = artistItems.Items.Select(i => i.Item1.Name).ToList();
|
2017-08-11 06:29:49 +00:00
|
|
|
|
dto.ArtistItems = hasArtist.Artists
|
2016-12-13 07:36:30 +00:00
|
|
|
|
//.Except(foundArtists, new DistinctNameComparer())
|
2016-09-06 05:02:05 +00:00
|
|
|
|
.Select(i =>
|
|
|
|
|
{
|
2016-10-06 18:55:01 +00:00
|
|
|
|
// This should not be necessary but we're seeing some cases of it
|
|
|
|
|
if (string.IsNullOrWhiteSpace(i))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-22 04:54:02 +00:00
|
|
|
|
var artist = _libraryManager.GetArtist(i, new DtoOptions(false)
|
|
|
|
|
{
|
|
|
|
|
EnableImages = false
|
|
|
|
|
});
|
2016-09-06 05:02:05 +00:00
|
|
|
|
if (artist != null)
|
|
|
|
|
{
|
|
|
|
|
return new NameIdPair
|
|
|
|
|
{
|
|
|
|
|
Name = artist.Name,
|
|
|
|
|
Id = artist.Id.ToString("N")
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
2017-08-11 06:29:49 +00:00
|
|
|
|
}).Where(i => i != null).ToArray();
|
2015-03-13 17:25:28 +00:00
|
|
|
|
}
|
2013-09-06 19:17:15 +00:00
|
|
|
|
|
2015-03-13 17:25:28 +00:00
|
|
|
|
var hasAlbumArtist = item as IHasAlbumArtist;
|
2013-09-06 19:17:15 +00:00
|
|
|
|
if (hasAlbumArtist != null)
|
|
|
|
|
{
|
2014-06-23 16:05:19 +00:00
|
|
|
|
dto.AlbumArtist = hasAlbumArtist.AlbumArtists.FirstOrDefault();
|
2015-03-13 15:54:20 +00:00
|
|
|
|
|
2016-12-13 07:36:30 +00:00
|
|
|
|
//var artistItems = _libraryManager.GetAlbumArtists(new InternalItemsQuery
|
|
|
|
|
//{
|
|
|
|
|
// EnableTotalRecordCount = false,
|
|
|
|
|
// ItemIds = new[] { item.Id.ToString("N") }
|
|
|
|
|
//});
|
|
|
|
|
|
|
|
|
|
//dto.AlbumArtists = artistItems.Items
|
|
|
|
|
// .Select(i =>
|
|
|
|
|
// {
|
|
|
|
|
// var artist = i.Item1;
|
|
|
|
|
// return new NameIdPair
|
|
|
|
|
// {
|
|
|
|
|
// Name = artist.Name,
|
|
|
|
|
// Id = artist.Id.ToString("N")
|
|
|
|
|
// };
|
|
|
|
|
// })
|
|
|
|
|
// .ToList();
|
|
|
|
|
|
2017-08-10 18:01:31 +00:00
|
|
|
|
dto.AlbumArtists = hasAlbumArtist.AlbumArtists
|
2016-12-13 07:36:30 +00:00
|
|
|
|
//.Except(foundArtists, new DistinctNameComparer())
|
2015-03-13 15:54:20 +00:00
|
|
|
|
.Select(i =>
|
|
|
|
|
{
|
2016-12-13 07:36:30 +00:00
|
|
|
|
// This should not be necessary but we're seeing some cases of it
|
|
|
|
|
if (string.IsNullOrWhiteSpace(i))
|
2015-03-13 15:54:20 +00:00
|
|
|
|
{
|
2016-12-13 07:36:30 +00:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-22 04:54:02 +00:00
|
|
|
|
var artist = _libraryManager.GetArtist(i, new DtoOptions(false)
|
|
|
|
|
{
|
|
|
|
|
EnableImages = false
|
|
|
|
|
});
|
2016-12-13 07:36:30 +00:00
|
|
|
|
if (artist != null)
|
|
|
|
|
{
|
|
|
|
|
return new NameIdPair
|
|
|
|
|
{
|
|
|
|
|
Name = artist.Name,
|
|
|
|
|
Id = artist.Id.ToString("N")
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
2017-08-10 18:01:31 +00:00
|
|
|
|
}).Where(i => i != null).ToArray();
|
2013-09-06 19:17:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
// Add video info
|
|
|
|
|
var video = item as Video;
|
|
|
|
|
if (video != null)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-09-04 17:02:19 +00:00
|
|
|
|
dto.VideoType = video.VideoType;
|
|
|
|
|
dto.Video3DFormat = video.Video3DFormat;
|
|
|
|
|
dto.IsoType = video.IsoType;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2015-10-24 15:33:22 +00:00
|
|
|
|
if (video.HasSubtitles)
|
|
|
|
|
{
|
|
|
|
|
dto.HasSubtitles = video.HasSubtitles;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-10 18:01:31 +00:00
|
|
|
|
if (video.AdditionalParts.Length != 0)
|
2014-11-30 19:01:33 +00:00
|
|
|
|
{
|
2017-08-10 18:01:31 +00:00
|
|
|
|
dto.PartCount = video.AdditionalParts.Length + 1;
|
2014-11-30 19:01:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.MediaSourceCount))
|
|
|
|
|
{
|
2016-05-01 20:56:06 +00:00
|
|
|
|
var mediaSourceCount = video.MediaSourceCount;
|
|
|
|
|
if (mediaSourceCount != 1)
|
2014-12-01 12:43:34 +00:00
|
|
|
|
{
|
2016-05-01 20:56:06 +00:00
|
|
|
|
dto.MediaSourceCount = mediaSourceCount;
|
2014-12-01 12:43:34 +00:00
|
|
|
|
}
|
2014-11-30 19:01:33 +00:00
|
|
|
|
}
|
2014-03-16 04:23:58 +00:00
|
|
|
|
|
2014-03-21 03:31:40 +00:00
|
|
|
|
if (fields.Contains(ItemFields.Chapters))
|
2014-03-20 15:55:22 +00:00
|
|
|
|
{
|
2014-10-12 15:18:26 +00:00
|
|
|
|
dto.Chapters = GetChapterInfoDtos(item);
|
2014-03-20 15:55:22 +00:00
|
|
|
|
}
|
2016-03-19 04:22:33 +00:00
|
|
|
|
|
2017-06-11 20:40:25 +00:00
|
|
|
|
if (video.ExtraType.HasValue)
|
|
|
|
|
{
|
|
|
|
|
dto.ExtraType = video.ExtraType.Value.ToString();
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
if (fields.Contains(ItemFields.MediaStreams))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-09-04 17:02:19 +00:00
|
|
|
|
// Add VideoInfo
|
2014-06-11 19:31:33 +00:00
|
|
|
|
var iHasMediaSources = item as IHasMediaSources;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2014-06-11 19:31:33 +00:00
|
|
|
|
if (iHasMediaSources != null)
|
2013-09-04 17:02:19 +00:00
|
|
|
|
{
|
2017-08-19 19:43:35 +00:00
|
|
|
|
MediaStream[] mediaStreams;
|
2014-03-21 03:31:40 +00:00
|
|
|
|
|
2014-03-22 16:16:43 +00:00
|
|
|
|
if (dto.MediaSources != null && dto.MediaSources.Count > 0)
|
2013-12-06 03:39:44 +00:00
|
|
|
|
{
|
2014-03-22 16:31:21 +00:00
|
|
|
|
mediaStreams = dto.MediaSources.Where(i => new Guid(i.Id) == item.Id)
|
2014-03-21 03:31:40 +00:00
|
|
|
|
.SelectMany(i => i.MediaStreams)
|
2017-08-19 19:43:35 +00:00
|
|
|
|
.ToArray();
|
2014-03-21 03:31:40 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-08-19 19:43:35 +00:00
|
|
|
|
mediaStreams = _mediaSourceManager().GetStaticMediaSources(iHasMediaSources, true).First().MediaStreams.ToArray();
|
2014-03-21 03:31:40 +00:00
|
|
|
|
}
|
2013-12-06 03:39:44 +00:00
|
|
|
|
|
2014-03-21 03:31:40 +00:00
|
|
|
|
dto.MediaStreams = mediaStreams;
|
2013-09-04 17:02:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-20 15:48:23 +00:00
|
|
|
|
var hasSpecialFeatures = item as IHasSpecialFeatures;
|
|
|
|
|
if (hasSpecialFeatures != null)
|
|
|
|
|
{
|
2017-08-11 21:55:48 +00:00
|
|
|
|
var specialFeatureCount = hasSpecialFeatures.SpecialFeatureIds.Length;
|
2014-09-20 15:48:23 +00:00
|
|
|
|
|
|
|
|
|
if (specialFeatureCount > 0)
|
2014-01-28 18:37:01 +00:00
|
|
|
|
{
|
2014-09-20 15:48:23 +00:00
|
|
|
|
dto.SpecialFeatureCount = specialFeatureCount;
|
2014-01-28 18:37:01 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
// Add EpisodeInfo
|
|
|
|
|
var episode = item as Episode;
|
|
|
|
|
if (episode != null)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-09-04 17:02:19 +00:00
|
|
|
|
dto.IndexNumberEnd = episode.IndexNumberEnd;
|
2016-05-22 22:37:50 +00:00
|
|
|
|
dto.SeriesName = episode.SeriesName;
|
2013-12-08 20:33:24 +00:00
|
|
|
|
|
2014-12-01 12:43:34 +00:00
|
|
|
|
if (fields.Contains(ItemFields.AlternateEpisodeNumbers))
|
|
|
|
|
{
|
|
|
|
|
dto.DvdSeasonNumber = episode.DvdSeasonNumber;
|
|
|
|
|
dto.DvdEpisodeNumber = episode.DvdEpisodeNumber;
|
|
|
|
|
dto.AbsoluteEpisodeNumber = episode.AbsoluteEpisodeNumber;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-12 05:07:19 +00:00
|
|
|
|
if (fields.Contains(ItemFields.SpecialEpisodeNumbers))
|
2014-12-19 04:20:07 +00:00
|
|
|
|
{
|
|
|
|
|
dto.AirsAfterSeasonNumber = episode.AirsAfterSeasonNumber;
|
|
|
|
|
dto.AirsBeforeEpisodeNumber = episode.AirsBeforeEpisodeNumber;
|
|
|
|
|
dto.AirsBeforeSeasonNumber = episode.AirsBeforeSeasonNumber;
|
|
|
|
|
}
|
2013-12-04 04:18:50 +00:00
|
|
|
|
|
2016-05-22 22:37:50 +00:00
|
|
|
|
var seasonId = episode.SeasonId;
|
|
|
|
|
if (seasonId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
dto.SeasonId = seasonId.Value.ToString("N");
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-04 20:11:30 +00:00
|
|
|
|
dto.SeasonName = episode.SeasonName;
|
2014-12-13 03:56:30 +00:00
|
|
|
|
|
2016-07-05 06:01:31 +00:00
|
|
|
|
var seriesId = episode.SeriesId;
|
|
|
|
|
if (seriesId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
dto.SeriesId = seriesId.Value.ToString("N");
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-05 05:40:18 +00:00
|
|
|
|
Series episodeSeries = null;
|
2016-05-22 22:37:50 +00:00
|
|
|
|
|
2016-07-14 03:36:23 +00:00
|
|
|
|
//if (fields.Contains(ItemFields.SeriesPrimaryImage))
|
2016-07-05 05:40:18 +00:00
|
|
|
|
{
|
|
|
|
|
episodeSeries = episodeSeries ?? episode.Series;
|
|
|
|
|
if (episodeSeries != null)
|
2014-12-01 12:43:34 +00:00
|
|
|
|
{
|
2016-05-22 22:37:50 +00:00
|
|
|
|
dto.SeriesPrimaryImageTag = GetImageCacheTag(episodeSeries, ImageType.Primary);
|
2014-12-01 12:43:34 +00:00
|
|
|
|
}
|
2016-07-05 05:40:18 +00:00
|
|
|
|
}
|
2014-12-01 12:43:34 +00:00
|
|
|
|
|
2016-07-05 05:40:18 +00:00
|
|
|
|
if (fields.Contains(ItemFields.SeriesStudio))
|
|
|
|
|
{
|
|
|
|
|
episodeSeries = episodeSeries ?? episode.Series;
|
|
|
|
|
if (episodeSeries != null)
|
2014-12-01 12:43:34 +00:00
|
|
|
|
{
|
2016-05-22 22:37:50 +00:00
|
|
|
|
dto.SeriesStudio = episodeSeries.Studios.FirstOrDefault();
|
2014-12-01 12:43:34 +00:00
|
|
|
|
}
|
2014-07-04 02:22:57 +00:00
|
|
|
|
}
|
2013-03-31 17:39:28 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2016-05-22 22:37:50 +00:00
|
|
|
|
// Add SeriesInfo
|
|
|
|
|
var series = item as Series;
|
|
|
|
|
if (series != null)
|
|
|
|
|
{
|
2017-08-13 20:15:07 +00:00
|
|
|
|
dto.AirDays = series.AirDays;
|
|
|
|
|
dto.AirTime = series.AirTime;
|
2017-02-19 03:46:09 +00:00
|
|
|
|
dto.Status = series.Status.HasValue ? series.Status.Value.ToString() : null;
|
2016-05-22 22:37:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
// Add SeasonInfo
|
|
|
|
|
var season = item as Season;
|
|
|
|
|
if (season != null)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2016-07-04 20:11:30 +00:00
|
|
|
|
dto.SeriesName = season.SeriesName;
|
|
|
|
|
|
2016-07-05 06:01:31 +00:00
|
|
|
|
var seriesId = season.SeriesId;
|
|
|
|
|
if (seriesId.HasValue)
|
2014-07-04 02:22:57 +00:00
|
|
|
|
{
|
2016-07-05 06:01:31 +00:00
|
|
|
|
dto.SeriesId = seriesId.Value.ToString("N");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
series = null;
|
2016-07-04 20:11:30 +00:00
|
|
|
|
|
2016-07-05 06:01:31 +00:00
|
|
|
|
if (fields.Contains(ItemFields.SeriesStudio))
|
|
|
|
|
{
|
|
|
|
|
series = series ?? season.Series;
|
|
|
|
|
if (series != null)
|
2016-07-04 20:11:30 +00:00
|
|
|
|
{
|
|
|
|
|
dto.SeriesStudio = series.Studios.FirstOrDefault();
|
|
|
|
|
}
|
2016-07-05 06:01:31 +00:00
|
|
|
|
}
|
2013-11-09 18:44:09 +00:00
|
|
|
|
|
2017-06-11 20:40:25 +00:00
|
|
|
|
//if (fields.Contains(ItemFields.SeriesPrimaryImage))
|
2016-07-05 06:01:31 +00:00
|
|
|
|
{
|
|
|
|
|
series = series ?? season.Series;
|
|
|
|
|
if (series != null)
|
2014-12-01 12:43:34 +00:00
|
|
|
|
{
|
|
|
|
|
dto.SeriesPrimaryImageTag = GetImageCacheTag(series, ImageType.Primary);
|
|
|
|
|
}
|
2014-07-04 02:22:57 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
var game = item as Game;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
if (game != null)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-09-04 17:02:19 +00:00
|
|
|
|
SetGameProperties(dto, game);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-27 21:40:42 +00:00
|
|
|
|
var gameSystem = item as GameSystem;
|
|
|
|
|
|
|
|
|
|
if (gameSystem != null)
|
|
|
|
|
{
|
|
|
|
|
SetGameSystemProperties(dto, gameSystem);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
var musicVideo = item as MusicVideo;
|
|
|
|
|
if (musicVideo != null)
|
|
|
|
|
{
|
|
|
|
|
SetMusicVideoProperties(dto, musicVideo);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
var book = item as Book;
|
|
|
|
|
if (book != null)
|
|
|
|
|
{
|
|
|
|
|
SetBookProperties(dto, book);
|
|
|
|
|
}
|
2014-03-30 16:49:40 +00:00
|
|
|
|
|
2017-02-18 08:32:17 +00:00
|
|
|
|
if (fields.Contains(ItemFields.ProductionLocations))
|
2016-10-08 18:51:07 +00:00
|
|
|
|
{
|
2017-08-09 19:56:38 +00:00
|
|
|
|
if (item.ProductionLocations.Length > 0 || item is Movie)
|
2017-02-18 08:32:17 +00:00
|
|
|
|
{
|
2017-08-09 19:56:38 +00:00
|
|
|
|
dto.ProductionLocations = item.ProductionLocations;
|
2017-02-18 08:32:17 +00:00
|
|
|
|
}
|
2016-10-08 18:51:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-29 00:49:25 +00:00
|
|
|
|
var photo = item as Photo;
|
|
|
|
|
if (photo != null)
|
|
|
|
|
{
|
|
|
|
|
SetPhotoProperties(dto, photo);
|
|
|
|
|
}
|
2014-03-30 16:49:40 +00:00
|
|
|
|
|
2015-08-17 04:08:33 +00:00
|
|
|
|
dto.ChannelId = item.ChannelId;
|
2015-10-29 13:28:05 +00:00
|
|
|
|
|
2016-03-19 05:04:38 +00:00
|
|
|
|
if (item.SourceType == SourceType.Channel && !string.IsNullOrWhiteSpace(item.ChannelId))
|
2014-05-17 21:23:48 +00:00
|
|
|
|
{
|
2016-03-19 05:04:38 +00:00
|
|
|
|
var channel = _libraryManager.GetItemById(item.ChannelId);
|
|
|
|
|
if (channel != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ChannelName = channel.Name;
|
|
|
|
|
}
|
2014-05-17 21:23:48 +00:00
|
|
|
|
}
|
2014-03-30 16:49:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-29 19:10:58 +00:00
|
|
|
|
private BaseItem GetImageDisplayParent(BaseItem currentItem, BaseItem originalItem)
|
2016-12-17 08:27:41 +00:00
|
|
|
|
{
|
2017-06-29 19:10:58 +00:00
|
|
|
|
var musicAlbum = currentItem as MusicAlbum;
|
2016-12-17 08:27:41 +00:00
|
|
|
|
if (musicAlbum != null)
|
|
|
|
|
{
|
2017-05-22 04:54:02 +00:00
|
|
|
|
var artist = musicAlbum.GetMusicArtist(new DtoOptions(false));
|
2016-12-17 08:27:41 +00:00
|
|
|
|
if (artist != null)
|
|
|
|
|
{
|
|
|
|
|
return artist;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-15 21:29:00 +00:00
|
|
|
|
|
2017-09-18 16:52:22 +00:00
|
|
|
|
var parent = currentItem.DisplayParent ?? (currentItem.IsOwnedItem ? currentItem.GetOwner() : currentItem.GetParent());
|
2017-06-29 19:10:58 +00:00
|
|
|
|
|
|
|
|
|
if (parent == null && !(originalItem is UserRootFolder) && !(originalItem is UserView) && !(originalItem is AggregateFolder) && !(originalItem is ICollectionFolder) && !(originalItem is Channel))
|
|
|
|
|
{
|
|
|
|
|
parent = _libraryManager.GetCollectionFolders(originalItem).FirstOrDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return parent;
|
2016-12-17 08:27:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-05 05:40:18 +00:00
|
|
|
|
private void AddInheritedImages(BaseItemDto dto, BaseItem item, DtoOptions options, BaseItem owner)
|
|
|
|
|
{
|
2016-11-21 08:54:53 +00:00
|
|
|
|
if (!item.SupportsInheritedParentImages)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-05 05:40:18 +00:00
|
|
|
|
var logoLimit = options.GetImageLimit(ImageType.Logo);
|
|
|
|
|
var artLimit = options.GetImageLimit(ImageType.Art);
|
|
|
|
|
var thumbLimit = options.GetImageLimit(ImageType.Thumb);
|
|
|
|
|
var backdropLimit = options.GetImageLimit(ImageType.Backdrop);
|
|
|
|
|
|
2016-11-21 08:54:53 +00:00
|
|
|
|
// For now. Emby apps are not using this
|
|
|
|
|
artLimit = 0;
|
|
|
|
|
|
2016-07-05 05:40:18 +00:00
|
|
|
|
if (logoLimit == 0 && artLimit == 0 && thumbLimit == 0 && backdropLimit == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BaseItem parent = null;
|
|
|
|
|
var isFirst = true;
|
|
|
|
|
|
2017-08-10 20:06:36 +00:00
|
|
|
|
var imageTags = dto.ImageTags;
|
|
|
|
|
|
|
|
|
|
while (((!(imageTags != null && imageTags.ContainsKey(ImageType.Logo)) && logoLimit > 0) || (!(imageTags != null && imageTags.ContainsKey(ImageType.Art)) && artLimit > 0) || (!(imageTags != null && imageTags.ContainsKey(ImageType.Thumb)) && thumbLimit > 0) || parent is Series) &&
|
2017-06-29 19:10:58 +00:00
|
|
|
|
(parent = parent ?? (isFirst ? GetImageDisplayParent(item, item) ?? owner : parent)) != null)
|
2016-07-05 05:40:18 +00:00
|
|
|
|
{
|
2016-07-08 03:22:02 +00:00
|
|
|
|
if (parent == null)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var allImages = parent.ImageInfos;
|
|
|
|
|
|
2017-08-10 20:06:36 +00:00
|
|
|
|
if (logoLimit > 0 && !(imageTags != null && imageTags.ContainsKey(ImageType.Logo)) && dto.ParentLogoItemId == null)
|
2016-07-05 05:40:18 +00:00
|
|
|
|
{
|
2016-07-08 03:22:02 +00:00
|
|
|
|
var image = allImages.FirstOrDefault(i => i.Type == ImageType.Logo);
|
2016-07-05 05:40:18 +00:00
|
|
|
|
|
|
|
|
|
if (image != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ParentLogoItemId = GetDtoId(parent);
|
|
|
|
|
dto.ParentLogoImageTag = GetImageCacheTag(parent, image);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-10 20:06:36 +00:00
|
|
|
|
if (artLimit > 0 && !(imageTags != null && imageTags.ContainsKey(ImageType.Art)) && dto.ParentArtItemId == null)
|
2016-07-05 05:40:18 +00:00
|
|
|
|
{
|
2016-07-08 03:22:02 +00:00
|
|
|
|
var image = allImages.FirstOrDefault(i => i.Type == ImageType.Art);
|
2016-07-05 05:40:18 +00:00
|
|
|
|
|
|
|
|
|
if (image != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ParentArtItemId = GetDtoId(parent);
|
|
|
|
|
dto.ParentArtImageTag = GetImageCacheTag(parent, image);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-10 20:06:36 +00:00
|
|
|
|
if (thumbLimit > 0 && !(imageTags != null && imageTags.ContainsKey(ImageType.Thumb)) && (dto.ParentThumbItemId == null || parent is Series) && !(parent is ICollectionFolder) && !(parent is UserView))
|
2016-07-05 05:40:18 +00:00
|
|
|
|
{
|
2016-07-08 03:22:02 +00:00
|
|
|
|
var image = allImages.FirstOrDefault(i => i.Type == ImageType.Thumb);
|
2016-07-05 05:40:18 +00:00
|
|
|
|
|
|
|
|
|
if (image != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ParentThumbItemId = GetDtoId(parent);
|
|
|
|
|
dto.ParentThumbImageTag = GetImageCacheTag(parent, image);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-10 20:06:36 +00:00
|
|
|
|
if (backdropLimit > 0 && !((dto.BackdropImageTags != null && dto.BackdropImageTags.Length > 0) || (dto.ParentBackdropImageTags != null && dto.ParentBackdropImageTags.Length > 0)))
|
2016-07-05 05:40:18 +00:00
|
|
|
|
{
|
2016-07-08 03:22:02 +00:00
|
|
|
|
var images = allImages.Where(i => i.Type == ImageType.Backdrop).Take(backdropLimit).ToList();
|
2016-07-05 05:40:18 +00:00
|
|
|
|
|
|
|
|
|
if (images.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
dto.ParentBackdropItemId = GetDtoId(parent);
|
|
|
|
|
dto.ParentBackdropImageTags = GetImageTags(parent, images);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isFirst = false;
|
2016-11-21 08:54:53 +00:00
|
|
|
|
|
|
|
|
|
if (!parent.SupportsInheritedParentImages)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-29 19:10:58 +00:00
|
|
|
|
parent = GetImageDisplayParent(parent, item);
|
2016-07-05 05:40:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-20 20:50:58 +00:00
|
|
|
|
private string GetMappedPath(BaseItem item, BaseItem ownerItem)
|
2014-03-20 15:55:22 +00:00
|
|
|
|
{
|
2014-03-21 03:31:40 +00:00
|
|
|
|
var path = item.Path;
|
2014-03-20 15:55:22 +00:00
|
|
|
|
|
2014-03-21 03:31:40 +00:00
|
|
|
|
var locationType = item.LocationType;
|
2014-03-20 15:55:22 +00:00
|
|
|
|
|
2014-06-02 19:32:41 +00:00
|
|
|
|
if (locationType == LocationType.FileSystem || locationType == LocationType.Offline)
|
2014-03-20 15:55:22 +00:00
|
|
|
|
{
|
2017-02-20 20:50:58 +00:00
|
|
|
|
path = _libraryManager.GetPathAfterNetworkSubstitution(path, ownerItem ?? item);
|
2014-03-20 15:55:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
2013-09-04 17:02:19 +00:00
|
|
|
|
/// Attaches the primary image aspect ratio.
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// </summary>
|
2013-09-04 17:02:19 +00:00
|
|
|
|
/// <param name="dto">The dto.</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <param name="item">The item.</param>
|
2013-09-04 17:02:19 +00:00
|
|
|
|
/// <returns>Task.</returns>
|
2017-10-22 06:22:43 +00:00
|
|
|
|
public void AttachPrimaryImageAspectRatio(IItemDto dto, BaseItem item)
|
2016-01-16 05:01:57 +00:00
|
|
|
|
{
|
|
|
|
|
dto.PrimaryImageAspectRatio = GetPrimaryImageAspectRatio(item);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-22 06:22:43 +00:00
|
|
|
|
public double? GetPrimaryImageAspectRatio(BaseItem item)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2014-02-07 20:30:41 +00:00
|
|
|
|
var imageInfo = item.GetImageInfo(ImageType.Primary, 0);
|
2013-05-05 04:49:49 +00:00
|
|
|
|
|
2017-06-11 20:40:25 +00:00
|
|
|
|
if (imageInfo == null)
|
2013-09-04 17:02:19 +00:00
|
|
|
|
{
|
2016-01-16 05:01:57 +00:00
|
|
|
|
return null;
|
2013-09-04 17:02:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-24 19:52:19 +00:00
|
|
|
|
var supportedEnhancers = _imageProcessor.GetSupportedEnhancers(item, ImageType.Primary);
|
2017-02-10 20:06:52 +00:00
|
|
|
|
|
2013-09-04 17:02:19 +00:00
|
|
|
|
ImageSize size;
|
2013-07-06 00:19:44 +00:00
|
|
|
|
|
2017-05-15 21:14:51 +00:00
|
|
|
|
var defaultAspectRatio = item.GetDefaultPrimaryImageAspectRatio();
|
2017-02-10 20:06:52 +00:00
|
|
|
|
|
2017-05-15 21:14:51 +00:00
|
|
|
|
if (defaultAspectRatio.HasValue)
|
|
|
|
|
{
|
|
|
|
|
if (supportedEnhancers.Count == 0)
|
2017-02-10 20:06:52 +00:00
|
|
|
|
{
|
|
|
|
|
return defaultAspectRatio.Value;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-15 21:14:51 +00:00
|
|
|
|
double dummyWidth = 200;
|
|
|
|
|
double dummyHeight = dummyWidth / defaultAspectRatio.Value;
|
|
|
|
|
size = new ImageSize(dummyWidth, dummyHeight);
|
2013-09-04 17:02:19 +00:00
|
|
|
|
}
|
2017-05-15 21:14:51 +00:00
|
|
|
|
else
|
2014-10-15 00:05:09 +00:00
|
|
|
|
{
|
2017-06-11 20:40:25 +00:00
|
|
|
|
if (!imageInfo.IsLocalFile)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-15 21:14:51 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-10-22 06:22:43 +00:00
|
|
|
|
size = _imageProcessor.GetImageSize(item, imageInfo);
|
|
|
|
|
|
|
|
|
|
if (size.Width <= 0 || size.Height <= 0)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2017-05-15 21:14:51 +00:00
|
|
|
|
}
|
2017-10-23 00:43:52 +00:00
|
|
|
|
catch (Exception ex)
|
2017-05-15 21:14:51 +00:00
|
|
|
|
{
|
2017-10-23 00:43:52 +00:00
|
|
|
|
//_logger.ErrorException("Failed to determine primary image aspect ratio for {0}", ex, imageInfo.Path);
|
2017-05-15 21:14:51 +00:00
|
|
|
|
return null;
|
|
|
|
|
}
|
2013-09-04 17:02:19 +00: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 04:49:49 +00:00
|
|
|
|
}
|
2013-09-04 17:02:19 +00:00
|
|
|
|
|
2016-01-21 08:23:02 +00:00
|
|
|
|
var width = size.Width;
|
|
|
|
|
var height = size.Height;
|
|
|
|
|
|
2017-03-14 19:44:11 +00:00
|
|
|
|
if (width.Equals(0) || height.Equals(0))
|
2015-01-30 21:17:19 +00:00
|
|
|
|
{
|
2016-01-21 08:23:02 +00:00
|
|
|
|
return null;
|
2015-01-30 21:17:19 +00:00
|
|
|
|
}
|
2016-01-21 08:23:02 +00:00
|
|
|
|
|
|
|
|
|
return width / height;
|
2013-05-05 04:49:49 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|