2014-08-30 10:26:29 -04:00
|
|
|
|
using MediaBrowser.Common.IO;
|
2014-05-17 17:23:48 -04:00
|
|
|
|
using MediaBrowser.Controller.Channels;
|
2014-01-30 00:20:18 -05:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2013-09-18 14:49:06 -04:00
|
|
|
|
using MediaBrowser.Controller.Drawing;
|
2013-09-04 13:02:19 -04:00
|
|
|
|
using MediaBrowser.Controller.Dto;
|
2013-03-12 18:49:45 -04:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-04-13 14:02:30 -04:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-03-30 12:49:40 -04:00
|
|
|
|
using MediaBrowser.Controller.LiveTv;
|
2013-04-13 14:02:30 -04:00
|
|
|
|
using MediaBrowser.Controller.Persistence;
|
2014-08-02 22:16:37 -04:00
|
|
|
|
using MediaBrowser.Controller.Playlists;
|
2014-02-21 13:48:15 -05:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-07-22 12:36:34 -04:00
|
|
|
|
using MediaBrowser.Controller.Sync;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
using MediaBrowser.Model.Drawing;
|
2013-02-21 12:50:46 -05:00
|
|
|
|
using MediaBrowser.Model.Dto;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-02-21 01:38:23 -05:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-03-12 18:49:45 -04:00
|
|
|
|
using MediaBrowser.Model.Querying;
|
2013-09-04 13:02:19 -04:00
|
|
|
|
using MoreLinq;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
namespace MediaBrowser.Server.Implementations.Dto
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
public class DtoService : IDtoService
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-03-01 16:22:34 -05:00
|
|
|
|
private readonly ILogger _logger;
|
2013-03-12 18:49:45 -04:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2013-10-02 12:08:58 -04:00
|
|
|
|
private readonly IUserDataManager _userDataRepository;
|
2013-06-18 15:16:27 -04:00
|
|
|
|
private readonly IItemRepository _itemRepo;
|
2013-02-21 20:26:35 -05:00
|
|
|
|
|
2013-09-18 14:49:06 -04:00
|
|
|
|
private readonly IImageProcessor _imageProcessor;
|
2014-01-30 00:20:18 -05:00
|
|
|
|
private readonly IServerConfigurationManager _config;
|
2014-02-07 15:30:41 -05:00
|
|
|
|
private readonly IFileSystem _fileSystem;
|
2014-02-21 13:48:15 -05:00
|
|
|
|
private readonly IProviderManager _providerManager;
|
2013-10-02 12:08:58 -04:00
|
|
|
|
|
2014-05-19 15:51:56 -04:00
|
|
|
|
private readonly Func<IChannelManager> _channelManagerFactory;
|
2014-07-22 12:36:34 -04:00
|
|
|
|
private readonly ISyncManager _syncManager;
|
2014-05-19 15:51:56 -04:00
|
|
|
|
|
2014-07-22 12:36:34 -04:00
|
|
|
|
public DtoService(ILogger logger, ILibraryManager libraryManager, IUserDataManager userDataRepository, IItemRepository itemRepo, IImageProcessor imageProcessor, IServerConfigurationManager config, IFileSystem fileSystem, IProviderManager providerManager, Func<IChannelManager> channelManagerFactory, ISyncManager syncManager)
|
2013-02-21 20:26:35 -05:00
|
|
|
|
{
|
2013-03-01 16:22:34 -05:00
|
|
|
|
_logger = logger;
|
2013-03-12 18:49:45 -04:00
|
|
|
|
_libraryManager = libraryManager;
|
2013-04-13 14:02:30 -04:00
|
|
|
|
_userDataRepository = userDataRepository;
|
2013-06-18 15:16:27 -04:00
|
|
|
|
_itemRepo = itemRepo;
|
2013-09-18 14:49:06 -04:00
|
|
|
|
_imageProcessor = imageProcessor;
|
2014-01-30 00:20:18 -05:00
|
|
|
|
_config = config;
|
2014-02-07 15:30:41 -05:00
|
|
|
|
_fileSystem = fileSystem;
|
2014-02-21 13:48:15 -05:00
|
|
|
|
_providerManager = providerManager;
|
2014-05-19 15:51:56 -04:00
|
|
|
|
_channelManagerFactory = channelManagerFactory;
|
2014-07-22 12:36:34 -04:00
|
|
|
|
_syncManager = syncManager;
|
2013-09-16 22:08:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 20:33:05 -05:00
|
|
|
|
/// <summary>
|
2013-05-15 12:56:38 -04:00
|
|
|
|
/// Converts a BaseItem to a DTOBaseItem
|
2013-02-20 20:33:05 -05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="fields">The fields.</param>
|
2013-05-15 12:56:38 -04:00
|
|
|
|
/// <param name="user">The user.</param>
|
2013-07-30 10:51:28 -04:00
|
|
|
|
/// <param name="owner">The owner.</param>
|
2013-02-20 20:33:05 -05:00
|
|
|
|
/// <returns>Task{DtoBaseItem}.</returns>
|
|
|
|
|
/// <exception cref="System.ArgumentNullException">item</exception>
|
2013-09-16 22:44:06 -04:00
|
|
|
|
public BaseItemDto GetBaseItemDto(BaseItem item, List<ItemFields> fields, User user = null, BaseItem owner = null)
|
2014-06-28 15:35:30 -04:00
|
|
|
|
{
|
2014-07-27 18:01:29 -04:00
|
|
|
|
var dto = GetBaseItemDtoInternal(item, fields, user, owner);
|
|
|
|
|
|
2014-06-28 15:35:30 -04:00
|
|
|
|
var byName = item as IItemByName;
|
|
|
|
|
|
2014-07-27 18:01:29 -04:00
|
|
|
|
if (byName != null && !(item is LiveTvChannel))
|
2014-06-28 15:35:30 -04:00
|
|
|
|
{
|
2014-07-27 18:01:29 -04:00
|
|
|
|
IEnumerable<BaseItem> libraryItems;
|
|
|
|
|
|
|
|
|
|
var artist = item as MusicArtist;
|
2014-06-28 15:35:30 -04:00
|
|
|
|
|
2014-07-27 18:01:29 -04:00
|
|
|
|
if (artist == null || artist.IsAccessedByName)
|
|
|
|
|
{
|
|
|
|
|
libraryItems = user != null ?
|
|
|
|
|
user.RootFolder.GetRecursiveChildren(user) :
|
|
|
|
|
_libraryManager.RootFolder.RecursiveChildren;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
libraryItems = user != null ?
|
|
|
|
|
artist.GetRecursiveChildren(user) :
|
|
|
|
|
artist.RecursiveChildren;
|
|
|
|
|
}
|
2014-06-28 15:35:30 -04:00
|
|
|
|
|
|
|
|
|
SetItemByNameInfo(item, dto, byName.GetTaggedItems(libraryItems).ToList(), user);
|
|
|
|
|
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-27 18:01:29 -04:00
|
|
|
|
return dto;
|
2014-06-28 15:35:30 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BaseItemDto GetBaseItemDtoInternal(BaseItem item, List<ItemFields> fields, User user = null, BaseItem owner = null)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
|
|
|
|
if (item == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("item");
|
|
|
|
|
}
|
2013-05-15 12:56:38 -04:00
|
|
|
|
|
2013-02-20 20:33:05 -05:00
|
|
|
|
if (fields == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("fields");
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 12:50:46 -05:00
|
|
|
|
var dto = new BaseItemDto();
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2014-08-05 19:59:24 -04:00
|
|
|
|
dto.SupportsPlaylists = item.SupportsAddingToPlaylist;
|
|
|
|
|
|
2013-04-02 22:59:27 -04:00
|
|
|
|
if (fields.Contains(ItemFields.People))
|
|
|
|
|
{
|
2013-09-16 22:08:18 -04:00
|
|
|
|
AttachPeople(dto, item);
|
2013-04-02 22:59:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.PrimaryImageAspectRatio))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-09-16 22:44:06 -04:00
|
|
|
|
AttachPrimaryImageAspectRatio(dto, item);
|
2013-04-02 22:59:27 -04: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 13:18:56 -04:00
|
|
|
|
if (fields.Contains(ItemFields.DisplayPreferencesId))
|
|
|
|
|
{
|
|
|
|
|
dto.DisplayPreferencesId = item.DisplayPreferencesId.ToString("N");
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-17 16:35:43 -04:00
|
|
|
|
if (user != null)
|
|
|
|
|
{
|
|
|
|
|
AttachUserSpecificInfo(dto, item, user, fields);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-14 14:24:20 -04:00
|
|
|
|
var hasMediaSources = item as IHasMediaSources;
|
|
|
|
|
if (hasMediaSources != null)
|
|
|
|
|
{
|
|
|
|
|
if (fields.Contains(ItemFields.MediaSources))
|
|
|
|
|
{
|
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
|
|
|
|
dto.MediaSources = hasMediaSources.GetMediaSources(true).ToList();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dto.MediaSources = hasMediaSources.GetMediaSources(true, user).ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-16 22:08:18 -04:00
|
|
|
|
if (fields.Contains(ItemFields.Studios))
|
|
|
|
|
{
|
|
|
|
|
AttachStudios(dto, item);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-30 10:51:28 -04:00
|
|
|
|
AttachBasicFields(dto, item, owner, fields);
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2014-07-22 12:36:34 -04:00
|
|
|
|
if (fields.Contains(ItemFields.SyncInfo))
|
|
|
|
|
{
|
|
|
|
|
dto.SupportsSync = _syncManager.SupportsSync(item);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 12:03:28 -04:00
|
|
|
|
if (fields.Contains(ItemFields.SoundtrackIds))
|
|
|
|
|
{
|
2013-11-12 10:36:08 -05:00
|
|
|
|
var hasSoundtracks = item as IHasSoundtracks;
|
|
|
|
|
|
|
|
|
|
if (hasSoundtracks != null)
|
|
|
|
|
{
|
|
|
|
|
dto.SoundtrackIds = hasSoundtracks.SoundtrackIds
|
|
|
|
|
.Select(i => i.ToString("N"))
|
|
|
|
|
.ToArray();
|
|
|
|
|
}
|
2013-07-16 12:03:28 -04:00
|
|
|
|
}
|
2013-08-30 21:08:32 -04:00
|
|
|
|
|
2014-08-02 22:16:37 -04:00
|
|
|
|
if (item is Playlist)
|
|
|
|
|
{
|
|
|
|
|
AttachLinkedChildImages(dto, (Folder)item, user);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 20:33:05 -05:00
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-28 15:35:30 -04:00
|
|
|
|
public BaseItemDto GetItemByNameDto<T>(T item, List<ItemFields> fields, List<BaseItem> taggedItems, User user = null)
|
2014-03-09 18:14:44 -04:00
|
|
|
|
where T : BaseItem, IItemByName
|
2013-09-10 14:56:00 -04:00
|
|
|
|
{
|
2014-06-28 15:35:30 -04:00
|
|
|
|
var dto = GetBaseItemDtoInternal(item, fields, user);
|
|
|
|
|
|
|
|
|
|
SetItemByNameInfo(item, dto, taggedItems, user);
|
2014-03-09 18:14:44 -04:00
|
|
|
|
|
2014-06-28 15:35:30 -04:00
|
|
|
|
return dto;
|
2014-03-09 18:14:44 -04:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-28 15:35:30 -04:00
|
|
|
|
private void SetItemByNameInfo(BaseItem item, BaseItemDto dto, List<BaseItem> taggedItems, User user = null)
|
2014-03-09 18:14:44 -04:00
|
|
|
|
{
|
|
|
|
|
if (item is MusicArtist || item is MusicGenre)
|
2013-09-10 14:56:00 -04:00
|
|
|
|
{
|
2014-03-09 18:14:44 -04: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.AdultVideoCount = taggedItems.Count(i => i is AdultVideo);
|
|
|
|
|
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);
|
|
|
|
|
dto.MusicVideoCount = taggedItems.Count(i => i is MusicVideo);
|
|
|
|
|
dto.SeriesCount = taggedItems.Count(i => i is Series);
|
|
|
|
|
dto.SongCount = taggedItems.Count(i => i is Audio);
|
|
|
|
|
dto.TrailerCount = taggedItems.Count(i => i is Trailer);
|
2013-09-10 14:56:00 -04:00
|
|
|
|
}
|
2013-12-02 16:46:22 -05:00
|
|
|
|
|
2014-03-09 18:14:44 -04:00
|
|
|
|
dto.ChildCount = taggedItems.Count;
|
2013-09-10 14:56:00 -04:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 20:33:05 -05: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>
|
2013-06-17 16:35:43 -04:00
|
|
|
|
private void AttachUserSpecificInfo(BaseItemDto dto, BaseItem item, User user, List<ItemFields> fields)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
|
|
|
|
if (item.IsFolder)
|
|
|
|
|
{
|
2014-07-03 22:22:57 -04:00
|
|
|
|
var userData = _userDataRepository.GetUserData(user.Id, item.GetUserDataKey());
|
|
|
|
|
|
|
|
|
|
// 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 10:26:20 -04:00
|
|
|
|
var folder = (Folder)item;
|
2013-07-25 15:17:44 -04:00
|
|
|
|
|
2013-12-10 15:42:42 -05:00
|
|
|
|
dto.ChildCount = GetChildCount(folder, user);
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2014-08-21 12:21:39 -04:00
|
|
|
|
// These are just far too slow.
|
|
|
|
|
// TODO: Disable for CollectionFolder
|
|
|
|
|
if (!(folder is UserRootFolder) && !(folder is UserView))
|
2013-09-23 10:26:20 -04:00
|
|
|
|
{
|
|
|
|
|
SetSpecialCounts(folder, user, dto, fields);
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
2013-05-07 21:17:41 -04:00
|
|
|
|
|
2014-08-17 01:38:13 -04:00
|
|
|
|
dto.UserData.Played = dto.UserData.PlayedPercentage.HasValue && dto.UserData.PlayedPercentage.Value >= 100;
|
2014-07-03 22:22:57 -04:00
|
|
|
|
}
|
2013-05-07 21:17:41 -04:00
|
|
|
|
|
2014-07-03 22:22:57 -04:00
|
|
|
|
else
|
2013-07-16 13:18:32 -04:00
|
|
|
|
{
|
2014-07-03 22:22:57 -04:00
|
|
|
|
dto.UserData = _userDataRepository.GetUserDataDto(item, user);
|
2013-05-07 21:17:41 -04:00
|
|
|
|
}
|
2014-02-21 00:35:56 -05:00
|
|
|
|
|
|
|
|
|
dto.PlayAccess = item.GetPlayAccess(user);
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
2013-04-13 14:02:30 -04:00
|
|
|
|
|
2013-12-10 15:42:42 -05:00
|
|
|
|
private int GetChildCount(Folder folder, User user)
|
|
|
|
|
{
|
|
|
|
|
return folder.GetChildren(user, true)
|
|
|
|
|
.Count();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-16 22:44:06 -04:00
|
|
|
|
public UserDto GetUserDto(User user)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (user == null)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
throw new ArgumentNullException("user");
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
var dto = new UserDto
|
2013-03-20 10:06:22 -04:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
Id = user.Id.ToString("N"),
|
|
|
|
|
Name = user.Name,
|
|
|
|
|
HasPassword = !String.IsNullOrEmpty(user.Password),
|
|
|
|
|
LastActivityDate = user.LastActivityDate,
|
|
|
|
|
LastLoginDate = user.LastLoginDate,
|
|
|
|
|
Configuration = user.Configuration
|
|
|
|
|
};
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2014-02-07 15:30:41 -05:00
|
|
|
|
var image = user.GetImageInfo(ImageType.Primary, 0);
|
2013-06-12 17:46:50 -04:00
|
|
|
|
|
2014-02-07 15:30:41 -05:00
|
|
|
|
if (image != null)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2014-02-07 15:30:41 -05:00
|
|
|
|
dto.PrimaryImageTag = GetImageCacheTag(user, image);
|
2013-09-04 13:02:19 -04:00
|
|
|
|
|
2013-05-28 16:01:12 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
2013-09-16 22:44:06 -04:00
|
|
|
|
AttachPrimaryImageAspectRatio(dto, user);
|
2013-05-28 16:01:12 -04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
// Have to use a catch-all unfortunately because some .net image methods throw plain Exceptions
|
|
|
|
|
_logger.ErrorException("Error generating PrimaryImageAspectRatio for {0}", ex, user.Name);
|
2013-05-28 16:01:12 -04:00
|
|
|
|
}
|
2013-09-04 13:02:19 -04:00
|
|
|
|
}
|
2013-05-28 16:01:12 -04:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
return dto;
|
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04: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 10:13:47 -04:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
throw new ArgumentNullException("item");
|
2013-04-12 10:13:47 -04:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
return item.Id.ToString("N");
|
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04: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-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
throw new ArgumentNullException("data");
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
return new UserItemDataDto
|
2013-06-11 23:00:23 -04:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
IsFavorite = data.IsFavorite,
|
|
|
|
|
Likes = data.Likes,
|
|
|
|
|
PlaybackPositionTicks = data.PlaybackPositionTicks,
|
|
|
|
|
PlayCount = data.PlayCount,
|
|
|
|
|
Rating = data.Rating,
|
|
|
|
|
Played = data.Played,
|
2013-10-03 14:02:23 -04:00
|
|
|
|
LastPlayedDate = data.LastPlayedDate,
|
|
|
|
|
Key = data.Key
|
2013-09-04 13:02:19 -04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
private void SetBookProperties(BaseItemDto dto, Book item)
|
|
|
|
|
{
|
|
|
|
|
dto.SeriesName = item.SeriesName;
|
|
|
|
|
}
|
2014-08-28 20:49:25 -04: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 10:26:29 -04:00
|
|
|
|
|
|
|
|
|
dto.Latitude = item.Latitude;
|
|
|
|
|
dto.Longitude = item.Longitude;
|
|
|
|
|
dto.Altitude = item.Altitude;
|
|
|
|
|
dto.IsoSpeedRating = item.IsoSpeedRating;
|
|
|
|
|
|
|
|
|
|
var album = item.Album;
|
|
|
|
|
|
|
|
|
|
if (album != null)
|
|
|
|
|
{
|
|
|
|
|
dto.Album = item.Name;
|
|
|
|
|
dto.AlbumId = item.Id.ToString("N");
|
|
|
|
|
}
|
2014-08-28 20:49:25 -04:00
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
private void SetMusicVideoProperties(BaseItemDto dto, MusicVideo item)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(item.Album))
|
|
|
|
|
{
|
|
|
|
|
var parentAlbum = _libraryManager.RootFolder
|
2014-07-01 17:13:32 -04:00
|
|
|
|
.GetRecursiveChildren()
|
|
|
|
|
.Where(i => i is MusicAlbum)
|
2013-09-04 13:02:19 -04:00
|
|
|
|
.FirstOrDefault(i => string.Equals(i.Name, item.Album, StringComparison.OrdinalIgnoreCase));
|
2013-07-05 20:19:44 -04:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (parentAlbum != null)
|
2013-07-05 20:19:44 -04:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.AlbumId = GetDtoId(parentAlbum);
|
2013-07-05 20:19:44 -04:00
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.Album = item.Album;
|
2013-09-11 13:54:59 -04:00
|
|
|
|
dto.Artists = string.IsNullOrEmpty(item.Artist) ? new List<string>() : new List<string> { item.Artist };
|
2013-09-04 13:02:19 -04:00
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
private void SetGameProperties(BaseItemDto dto, Game item)
|
|
|
|
|
{
|
|
|
|
|
dto.Players = item.PlayersSupported;
|
|
|
|
|
dto.GameSystem = item.GameSystem;
|
2014-04-26 23:42:05 -04:00
|
|
|
|
dto.MultiPartGameFiles = item.MultiPartGameFiles;
|
2013-09-04 13:02:19 -04:00
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-10-27 17:40:42 -04:00
|
|
|
|
private void SetGameSystemProperties(BaseItemDto dto, GameSystem item)
|
|
|
|
|
{
|
|
|
|
|
dto.GameSystem = item.GameSystemName;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the backdrop image tags.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns>List{System.String}.</returns>
|
2014-05-08 16:09:53 -04:00
|
|
|
|
private List<string> GetBackdropImageTags(BaseItem item)
|
2013-09-04 13:02:19 -04:00
|
|
|
|
{
|
2014-02-07 15:30:41 -05:00
|
|
|
|
return GetCacheTags(item, ImageType.Backdrop).ToList();
|
2013-09-04 13:02:19 -04:00
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the screenshot image tags.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns>List{Guid}.</returns>
|
2014-05-08 16:09:53 -04:00
|
|
|
|
private List<string> GetScreenshotImageTags(BaseItem item)
|
2013-09-04 13:02:19 -04:00
|
|
|
|
{
|
2013-12-05 11:50:21 -05:00
|
|
|
|
var hasScreenshots = item as IHasScreenshots;
|
|
|
|
|
if (hasScreenshots == null)
|
|
|
|
|
{
|
2014-05-08 16:09:53 -04:00
|
|
|
|
return new List<string>();
|
2013-12-05 11:50:21 -05:00
|
|
|
|
}
|
2014-02-07 15:30:41 -05:00
|
|
|
|
return GetCacheTags(item, ImageType.Screenshot).ToList();
|
|
|
|
|
}
|
2013-12-05 11:50:21 -05:00
|
|
|
|
|
2014-05-08 16:09:53 -04:00
|
|
|
|
private IEnumerable<string> GetCacheTags(BaseItem item, ImageType type)
|
2014-02-07 15:30:41 -05:00
|
|
|
|
{
|
|
|
|
|
return item.GetImages(type)
|
|
|
|
|
.Select(p => GetImageCacheTag(item, p))
|
2014-05-08 16:09:53 -04:00
|
|
|
|
.Where(i => i != null)
|
2013-09-04 13:02:19 -04:00
|
|
|
|
.ToList();
|
|
|
|
|
}
|
2013-03-12 22:10:43 -04:00
|
|
|
|
|
2014-05-08 16:09:53 -04:00
|
|
|
|
private string GetImageCacheTag(BaseItem item, ImageType type)
|
2014-02-07 15:30:41 -05:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _imageProcessor.GetImageCacheTag(item, type);
|
|
|
|
|
}
|
2014-04-13 13:27:13 -04:00
|
|
|
|
catch (Exception ex)
|
2014-02-07 15:30:41 -05:00
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error getting {0} image info", ex, type);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 16:09:53 -04:00
|
|
|
|
private string GetImageCacheTag(BaseItem item, ItemImageInfo image)
|
2013-09-04 13:02:19 -04:00
|
|
|
|
{
|
|
|
|
|
try
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2014-02-07 15:30:41 -05:00
|
|
|
|
return _imageProcessor.GetImageCacheTag(item, image);
|
2013-03-12 18:49:45 -04:00
|
|
|
|
}
|
2014-04-13 13:27:13 -04:00
|
|
|
|
catch (Exception ex)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2014-02-07 15:30:41 -05:00
|
|
|
|
_logger.ErrorException("Error getting {0} image info for {1}", ex, image.Type, image.Path);
|
2013-09-04 13:02:19 -04:00
|
|
|
|
return null;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
2013-09-16 22:08:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 14:56:00 -04:00
|
|
|
|
/// <summary>
|
2013-09-04 13:02:19 -04: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-16 22:08:18 -04:00
|
|
|
|
private void AttachPeople(BaseItemDto dto, BaseItem item)
|
2013-09-04 13:02:19 -04: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
|
2014-06-30 09:28:38 -04:00
|
|
|
|
var people = item.People.OrderBy(i => i.SortOrder ?? int.MaxValue)
|
|
|
|
|
.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-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
// Attach People by transforming them into BaseItemPerson (DTO)
|
|
|
|
|
dto.People = new BaseItemPerson[people.Count];
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-16 22:08:18 -04:00
|
|
|
|
var dictionary = people.Select(p => p.Name)
|
2013-09-04 13:02:19 -04:00
|
|
|
|
.Distinct(StringComparer.OrdinalIgnoreCase).Select(c =>
|
2013-09-16 22:08:18 -04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _libraryManager.GetPerson(c);
|
|
|
|
|
}
|
2014-08-24 23:54:45 -04:00
|
|
|
|
catch (Exception ex)
|
2013-09-04 13:02:19 -04:00
|
|
|
|
{
|
2013-09-16 22:08:18 -04:00
|
|
|
|
_logger.ErrorException("Error getting person {0}", ex, c);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}).Where(i => i != null)
|
2013-09-04 13:02:19 -04:00
|
|
|
|
.DistinctBy(i => i.Name)
|
|
|
|
|
.ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < people.Count; i++)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
var person = people[i];
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
var baseItemPerson = new BaseItemPerson
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
Name = person.Name,
|
|
|
|
|
Role = person.Role,
|
|
|
|
|
Type = person.Type
|
|
|
|
|
};
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
Person entity;
|
|
|
|
|
|
|
|
|
|
if (dictionary.TryGetValue(person.Name, out entity))
|
|
|
|
|
{
|
2014-02-07 15:30:41 -05:00
|
|
|
|
baseItemPerson.PrimaryImageTag = GetImageCacheTag(entity, ImageType.Primary);
|
2014-05-11 18:38:10 -04:00
|
|
|
|
baseItemPerson.Id = entity.Id.ToString("N");
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
2013-09-04 13:02:19 -04:00
|
|
|
|
|
|
|
|
|
dto.People[i] = baseItemPerson;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
2013-09-04 13:02:19 -04:00
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Attaches the studios.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dto">The dto.</param>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
2013-09-16 22:08:18 -04:00
|
|
|
|
private void AttachStudios(BaseItemDto dto, BaseItem item)
|
2013-09-04 13:02:19 -04:00
|
|
|
|
{
|
|
|
|
|
var studios = item.Studios.ToList();
|
|
|
|
|
|
|
|
|
|
dto.Studios = new StudioDto[studios.Count];
|
|
|
|
|
|
2013-09-16 22:08:18 -04: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)
|
|
|
|
|
.ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);
|
2013-09-04 13:02:19 -04:00
|
|
|
|
|
|
|
|
|
for (var i = 0; i < studios.Count; i++)
|
2013-07-08 15:31:45 -04:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
var studio = studios[i];
|
2013-07-08 15:31:45 -04:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
var studioDto = new StudioDto
|
2013-07-08 15:31:45 -04:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
Name = studio
|
|
|
|
|
};
|
2013-07-08 15:31:45 -04:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
Studio entity;
|
|
|
|
|
|
|
|
|
|
if (dictionary.TryGetValue(studio, out entity))
|
|
|
|
|
{
|
2014-07-01 17:13:32 -04:00
|
|
|
|
studioDto.Id = entity.Id.ToString("N");
|
2014-02-07 15:30:41 -05:00
|
|
|
|
studioDto.PrimaryImageTag = GetImageCacheTag(entity, ImageType.Primary);
|
2013-07-08 15:31:45 -04:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.Studios[i] = studioDto;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
2013-09-04 13:02:19 -04:00
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04: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)
|
|
|
|
|
{
|
|
|
|
|
var parent = item.Parent ?? owner;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
while (parent != null)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2014-02-07 15:30:41 -05:00
|
|
|
|
if (parent.GetImages(ImageType.Backdrop).Any())
|
2013-09-04 13:02:19 -04:00
|
|
|
|
{
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parent = parent.Parent;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
return null;
|
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04: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)
|
|
|
|
|
{
|
|
|
|
|
var parent = item.Parent ?? owner;
|
|
|
|
|
|
|
|
|
|
while (parent != null)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (parent.HasImage(type))
|
|
|
|
|
{
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parent = parent.Parent;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04: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-03-19 00:59:45 -04:00
|
|
|
|
public ChapterInfoDto GetChapterInfoDto(ChapterInfo chapterInfo, BaseItem item)
|
2013-09-04 13:02:19 -04:00
|
|
|
|
{
|
|
|
|
|
var dto = new ChapterInfoDto
|
2013-06-24 21:22:21 -04:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
Name = chapterInfo.Name,
|
|
|
|
|
StartPositionTicks = chapterInfo.StartPositionTicks
|
|
|
|
|
};
|
2013-07-05 20:19:44 -04:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (!string.IsNullOrEmpty(chapterInfo.ImagePath))
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2014-02-07 15:30:41 -05:00
|
|
|
|
dto.ImageTag = GetImageCacheTag(item, new ItemImageInfo
|
|
|
|
|
{
|
|
|
|
|
Path = chapterInfo.ImagePath,
|
|
|
|
|
Type = ImageType.Chapter,
|
|
|
|
|
DateModified = _fileSystem.GetLastWriteTimeUtc(chapterInfo.ImagePath)
|
|
|
|
|
});
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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>
|
|
|
|
|
/// <param name="fields">The fields.</param>
|
|
|
|
|
private void AttachBasicFields(BaseItemDto dto, BaseItem item, BaseItem owner, List<ItemFields> fields)
|
|
|
|
|
{
|
|
|
|
|
if (fields.Contains(ItemFields.DateCreated))
|
2013-05-24 00:02:42 -04:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.DateCreated = item.DateCreated;
|
2013-05-24 00:02:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-21 12:55:47 -04:00
|
|
|
|
if (fields.Contains(ItemFields.DisplayMediaType))
|
|
|
|
|
{
|
|
|
|
|
dto.DisplayMediaType = item.DisplayMediaType;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 23:13:44 -05:00
|
|
|
|
dto.IsUnidentified = item.IsUnidentified;
|
2013-08-30 21:08:32 -04:00
|
|
|
|
|
2013-12-10 16:26:30 -05:00
|
|
|
|
if (fields.Contains(ItemFields.Settings))
|
2013-09-04 13:02:19 -04:00
|
|
|
|
{
|
|
|
|
|
dto.LockedFields = item.LockedFields;
|
2014-03-22 12:16:43 -04:00
|
|
|
|
dto.LockData = item.IsLocked;
|
2014-03-24 13:54:45 -04:00
|
|
|
|
dto.ForcedSortName = item.ForcedSortName;
|
2013-07-16 12:03:28 -04:00
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-12-02 11:16:03 -05:00
|
|
|
|
var hasBudget = item as IHasBudget;
|
|
|
|
|
if (hasBudget != null)
|
2013-07-16 12:03:28 -04:00
|
|
|
|
{
|
2013-12-02 11:16:03 -05:00
|
|
|
|
if (fields.Contains(ItemFields.Budget))
|
|
|
|
|
{
|
|
|
|
|
dto.Budget = hasBudget.Budget;
|
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-12-02 11:16:03 -05:00
|
|
|
|
if (fields.Contains(ItemFields.Revenue))
|
|
|
|
|
{
|
|
|
|
|
dto.Revenue = hasBudget.Revenue;
|
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
2013-04-24 18:34:38 -04:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.EndDate = item.EndDate;
|
2013-04-24 18:34:38 -04:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (fields.Contains(ItemFields.HomePageUrl))
|
2013-04-24 18:34:38 -04:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.HomePageUrl = item.HomePageUrl;
|
2013-04-24 18:34:38 -04:00
|
|
|
|
}
|
2013-07-12 15:56:40 -04:00
|
|
|
|
|
2014-02-21 13:48:15 -05:00
|
|
|
|
if (fields.Contains(ItemFields.ExternalUrls))
|
|
|
|
|
{
|
|
|
|
|
dto.ExternalUrls = _providerManager.GetExternalUrls(item).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (fields.Contains(ItemFields.Tags))
|
|
|
|
|
{
|
2013-12-05 11:50:21 -05: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 13:02:19 -04:00
|
|
|
|
}
|
2013-07-12 15:56:40 -04:00
|
|
|
|
|
2014-01-14 10:50:39 -05:00
|
|
|
|
if (fields.Contains(ItemFields.Keywords))
|
|
|
|
|
{
|
2014-02-07 15:30:41 -05:00
|
|
|
|
var hasTags = item as IHasKeywords;
|
2014-01-14 10:50:39 -05:00
|
|
|
|
if (hasTags != null)
|
|
|
|
|
{
|
|
|
|
|
dto.Keywords = hasTags.Keywords;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dto.Keywords == null)
|
|
|
|
|
{
|
|
|
|
|
dto.Keywords = new List<string>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (fields.Contains(ItemFields.ProductionLocations))
|
2013-07-12 15:56:40 -04:00
|
|
|
|
{
|
2013-12-05 11:50:21 -05:00
|
|
|
|
SetProductionLocations(item, dto);
|
2013-07-12 15:56:40 -04:00
|
|
|
|
}
|
2013-08-30 19:55:17 -04:00
|
|
|
|
|
2013-11-19 22:15:48 -05:00
|
|
|
|
var hasAspectRatio = item as IHasAspectRatio;
|
|
|
|
|
if (hasAspectRatio != null)
|
|
|
|
|
{
|
|
|
|
|
dto.AspectRatio = hasAspectRatio.AspectRatio;
|
|
|
|
|
}
|
2013-08-30 19:55:17 -04:00
|
|
|
|
|
2014-01-15 00:01:58 -05:00
|
|
|
|
var hasMetascore = item as IHasMetascore;
|
|
|
|
|
if (hasMetascore != null)
|
|
|
|
|
{
|
|
|
|
|
dto.Metascore = hasMetascore.Metascore;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.AwardSummary))
|
|
|
|
|
{
|
|
|
|
|
var hasAwards = item as IHasAwards;
|
|
|
|
|
if (hasAwards != null)
|
|
|
|
|
{
|
|
|
|
|
dto.AwardSummary = hasAwards.AwardSummary;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.BackdropImageTags = GetBackdropImageTags(item);
|
2013-09-17 22:43:34 -04:00
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.ScreenshotImageTags))
|
|
|
|
|
{
|
|
|
|
|
dto.ScreenshotImageTags = GetScreenshotImageTags(item);
|
|
|
|
|
}
|
2013-09-04 13:02:19 -04:00
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.Genres))
|
2013-08-30 19:55:17 -04:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.Genres = item.Genres;
|
2013-08-30 19:55:17 -04:00
|
|
|
|
}
|
2013-07-12 15:56:40 -04:00
|
|
|
|
|
2014-05-08 16:09:53 -04:00
|
|
|
|
dto.ImageTags = new Dictionary<ImageType, string>();
|
2013-08-30 21:08:32 -04:00
|
|
|
|
|
2014-02-07 15:30:41 -05:00
|
|
|
|
// Prevent implicitly captured closure
|
|
|
|
|
var currentItem = item;
|
|
|
|
|
foreach (var image in currentItem.ImageInfos.Where(i => !currentItem.AllowsMultipleImages(i.Type)))
|
2013-07-22 20:03:33 -04:00
|
|
|
|
{
|
2014-02-07 15:30:41 -05:00
|
|
|
|
var tag = GetImageCacheTag(item, image);
|
2013-09-04 13:02:19 -04:00
|
|
|
|
|
2014-05-08 16:09:53 -04:00
|
|
|
|
if (tag != null)
|
2013-07-22 20:03:33 -04:00
|
|
|
|
{
|
2014-05-08 16:09:53 -04:00
|
|
|
|
dto.ImageTags[image.Type] = tag;
|
2013-07-22 20:03:33 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.Id = GetDtoId(item);
|
|
|
|
|
dto.IndexNumber = item.IndexNumber;
|
|
|
|
|
dto.IsFolder = item.IsFolder;
|
|
|
|
|
dto.MediaType = item.MediaType;
|
|
|
|
|
dto.LocationType = item.LocationType;
|
2013-09-11 13:54:59 -04:00
|
|
|
|
|
2013-12-28 11:58:13 -05:00
|
|
|
|
var hasLang = item as IHasPreferredMetadataLanguage;
|
|
|
|
|
|
|
|
|
|
if (hasLang != null)
|
2013-12-05 11:50:21 -05:00
|
|
|
|
{
|
2013-12-28 11:58:13 -05:00
|
|
|
|
dto.PreferredMetadataCountryCode = hasLang.PreferredMetadataCountryCode;
|
|
|
|
|
dto.PreferredMetadataLanguage = hasLang.PreferredMetadataLanguage;
|
2013-12-05 11:50:21 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-06 11:06:16 -05:00
|
|
|
|
var hasCriticRating = item as IHasCriticRating;
|
|
|
|
|
if (hasCriticRating != null)
|
2013-09-04 13:02:19 -04:00
|
|
|
|
{
|
2013-11-06 11:06:16 -05:00
|
|
|
|
dto.CriticRating = hasCriticRating.CriticRating;
|
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.CriticRatingSummary))
|
|
|
|
|
{
|
|
|
|
|
dto.CriticRatingSummary = hasCriticRating.CriticRatingSummary;
|
|
|
|
|
}
|
2013-09-04 13:02:19 -04:00
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-12-02 11:46:25 -05:00
|
|
|
|
var hasTrailers = item as IHasTrailers;
|
|
|
|
|
if (hasTrailers != null)
|
|
|
|
|
{
|
|
|
|
|
dto.LocalTrailerCount = hasTrailers.LocalTrailerIds.Count;
|
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2014-01-03 15:32:27 -05:00
|
|
|
|
var hasDisplayOrder = item as IHasDisplayOrder;
|
|
|
|
|
if (hasDisplayOrder != null)
|
|
|
|
|
{
|
|
|
|
|
dto.DisplayOrder = hasDisplayOrder.DisplayOrder;
|
|
|
|
|
}
|
2014-01-03 21:35:41 -05:00
|
|
|
|
|
2014-08-02 22:16:37 -04:00
|
|
|
|
var collectionFolder = item as ICollectionFolder;
|
2014-01-03 21:35:41 -05:00
|
|
|
|
if (collectionFolder != null)
|
|
|
|
|
{
|
|
|
|
|
dto.CollectionType = collectionFolder.CollectionType;
|
|
|
|
|
}
|
2014-02-07 15:30:41 -05:00
|
|
|
|
|
2014-06-04 22:32:40 -04:00
|
|
|
|
var userView = item as UserView;
|
|
|
|
|
if (userView != null)
|
|
|
|
|
{
|
|
|
|
|
dto.CollectionType = userView.ViewType;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-02 11:46:25 -05:00
|
|
|
|
if (fields.Contains(ItemFields.RemoteTrailers))
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-12-02 11:46:25 -05:00
|
|
|
|
dto.RemoteTrailers = hasTrailers != null ?
|
|
|
|
|
hasTrailers.RemoteTrailers :
|
|
|
|
|
new List<MediaUrl>();
|
2013-09-04 13:02:19 -04:00
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.Name = item.Name;
|
|
|
|
|
dto.OfficialRating = item.OfficialRating;
|
2013-03-09 00:15:51 -05:00
|
|
|
|
|
2014-05-27 10:30:21 -04:00
|
|
|
|
if (fields.Contains(ItemFields.Overview))
|
2013-09-04 13:02:19 -04:00
|
|
|
|
{
|
2014-08-05 19:59:24 -04:00
|
|
|
|
dto.Overview = item.Overview;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 00:18:02 -04:00
|
|
|
|
if (fields.Contains(ItemFields.ShortOverview))
|
|
|
|
|
{
|
|
|
|
|
var hasShortOverview = item as IHasShortOverview;
|
|
|
|
|
if (hasShortOverview != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ShortOverview = hasShortOverview.ShortOverview;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
// If there are no backdrops, indicate what parent has them in case the Ui wants to allow inheritance
|
|
|
|
|
if (dto.BackdropImageTags.Count == 0)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
var parentWithBackdrop = GetParentBackdropItem(item, owner);
|
|
|
|
|
|
|
|
|
|
if (parentWithBackdrop != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ParentBackdropItemId = GetDtoId(parentWithBackdrop);
|
|
|
|
|
dto.ParentBackdropImageTags = GetBackdropImageTags(parentWithBackdrop);
|
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
2013-07-25 15:17:44 -04:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (item.Parent != null && fields.Contains(ItemFields.ParentId))
|
2013-07-25 15:17:44 -04:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.ParentId = GetDtoId(item.Parent);
|
2013-07-25 15:17:44 -04:00
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.ParentIndexNumber = item.ParentIndexNumber;
|
2013-04-14 16:47:09 -04:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
// If there is no logo, indicate what parent has one in case the Ui wants to allow inheritance
|
|
|
|
|
if (!dto.HasLogo)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
var parentWithLogo = GetParentImageItem(item, ImageType.Logo, owner);
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (parentWithLogo != null)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.ParentLogoItemId = GetDtoId(parentWithLogo);
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2014-02-07 15:30:41 -05:00
|
|
|
|
dto.ParentLogoImageTag = GetImageCacheTag(parentWithLogo, ImageType.Logo);
|
2013-09-04 13:02:19 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
// If there is no art, indicate what parent has one in case the Ui wants to allow inheritance
|
|
|
|
|
if (!dto.HasArtImage)
|
|
|
|
|
{
|
|
|
|
|
var parentWithImage = GetParentImageItem(item, ImageType.Art, owner);
|
|
|
|
|
|
|
|
|
|
if (parentWithImage != null)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.ParentArtItemId = GetDtoId(parentWithImage);
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2014-02-07 15:30:41 -05:00
|
|
|
|
dto.ParentArtImageTag = GetImageCacheTag(parentWithImage, ImageType.Art);
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
2013-09-04 13:02:19 -04:00
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-10-24 13:49:24 -04:00
|
|
|
|
// If there is no thumb, indicate what parent has one in case the Ui wants to allow inheritance
|
|
|
|
|
if (!dto.HasThumb)
|
|
|
|
|
{
|
|
|
|
|
var parentWithImage = GetParentImageItem(item, ImageType.Thumb, owner);
|
|
|
|
|
|
|
|
|
|
if (parentWithImage != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ParentThumbItemId = GetDtoId(parentWithImage);
|
|
|
|
|
|
2014-02-07 15:30:41 -05:00
|
|
|
|
dto.ParentThumbImageTag = GetImageCacheTag(parentWithImage, ImageType.Thumb);
|
2013-10-24 13:49:24 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (fields.Contains(ItemFields.Path))
|
|
|
|
|
{
|
2014-06-02 15:32:41 -04:00
|
|
|
|
dto.Path = GetMappedPath(item);
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.PremiereDate = item.PremiereDate;
|
|
|
|
|
dto.ProductionYear = item.ProductionYear;
|
2013-05-03 23:13:28 -04:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (fields.Contains(ItemFields.ProviderIds))
|
|
|
|
|
{
|
|
|
|
|
dto.ProviderIds = item.ProviderIds;
|
|
|
|
|
}
|
2013-05-03 23:13:28 -04:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.RunTimeTicks = item.RunTimeTicks;
|
2013-05-03 23:13:28 -04:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (fields.Contains(ItemFields.SortName))
|
|
|
|
|
{
|
|
|
|
|
dto.SortName = item.SortName;
|
|
|
|
|
}
|
2013-05-03 23:13:28 -04:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (fields.Contains(ItemFields.CustomRating))
|
|
|
|
|
{
|
|
|
|
|
dto.CustomRating = item.CustomRating;
|
|
|
|
|
}
|
2013-05-03 23:13:28 -04:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (fields.Contains(ItemFields.Taglines))
|
|
|
|
|
{
|
2013-12-05 11:50:21 -05: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 13:02:19 -04:00
|
|
|
|
}
|
2013-05-03 23:13:28 -04:00
|
|
|
|
|
2013-11-21 15:48:26 -05:00
|
|
|
|
dto.Type = item.GetClientTypeName();
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.CommunityRating = item.CommunityRating;
|
2013-10-13 10:37:17 -04:00
|
|
|
|
dto.VoteCount = item.VoteCount;
|
2013-05-03 23:13:28 -04:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (item.IsFolder)
|
|
|
|
|
{
|
|
|
|
|
var folder = (Folder)item;
|
2013-05-03 23:13:28 -04:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (fields.Contains(ItemFields.IndexOptions))
|
2013-05-03 23:13:28 -04:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.IndexOptions = folder.IndexByOptionStrings.ToArray();
|
2013-05-03 23:13:28 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2014-03-03 00:11:03 -05:00
|
|
|
|
var supportsPlaceHolders = item as ISupportsPlaceHolders;
|
|
|
|
|
if (supportsPlaceHolders != null)
|
|
|
|
|
{
|
|
|
|
|
dto.IsPlaceHolder = supportsPlaceHolders.IsPlaceHolder;
|
|
|
|
|
}
|
2014-03-22 12:16:43 -04:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
// Add audio info
|
|
|
|
|
var audio = item as Audio;
|
|
|
|
|
if (audio != null)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.Album = audio.Album;
|
2013-09-11 13:54:59 -04:00
|
|
|
|
dto.Artists = audio.Artists;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
var albumParent = audio.FindParent<MusicAlbum>();
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (albumParent != null)
|
|
|
|
|
{
|
|
|
|
|
dto.AlbumId = GetDtoId(albumParent);
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2014-02-07 15:30:41 -05:00
|
|
|
|
dto.AlbumPrimaryImageTag = GetImageCacheTag(albumParent, ImageType.Primary);
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
2014-03-20 23:31:40 -04:00
|
|
|
|
|
2014-03-22 12:16:43 -04:00
|
|
|
|
dto.MediaSourceCount = 1;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
var album = item as MusicAlbum;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (album != null)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-10 14:56:00 -04:00
|
|
|
|
dto.Artists = album.Artists;
|
2013-11-12 10:36:08 -05:00
|
|
|
|
|
|
|
|
|
dto.SoundtrackIds = album.SoundtrackIds
|
|
|
|
|
.Select(i => i.ToString("N"))
|
|
|
|
|
.ToArray();
|
2013-09-04 13:02:19 -04:00
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-06 15:17:15 -04:00
|
|
|
|
var hasAlbumArtist = item as IHasAlbumArtist;
|
|
|
|
|
|
|
|
|
|
if (hasAlbumArtist != null)
|
|
|
|
|
{
|
2014-06-23 12:05:19 -04:00
|
|
|
|
dto.AlbumArtist = hasAlbumArtist.AlbumArtists.FirstOrDefault();
|
2013-09-06 15:17:15 -04:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
// Add video info
|
|
|
|
|
var video = item as Video;
|
|
|
|
|
if (video != null)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.VideoType = video.VideoType;
|
|
|
|
|
dto.Video3DFormat = video.Video3DFormat;
|
|
|
|
|
dto.IsoType = video.IsoType;
|
2013-09-29 20:51:04 -04:00
|
|
|
|
dto.IsHD = video.IsHD;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.PartCount = video.AdditionalPartIds.Count + 1;
|
2014-03-22 12:16:43 -04:00
|
|
|
|
dto.MediaSourceCount = video.MediaSourceCount;
|
2014-03-16 00:23:58 -04:00
|
|
|
|
|
2014-03-20 23:31:40 -04:00
|
|
|
|
if (fields.Contains(ItemFields.Chapters))
|
2014-03-20 11:55:22 -04:00
|
|
|
|
{
|
2014-03-20 23:31:40 -04:00
|
|
|
|
List<ChapterInfoDto> chapters;
|
|
|
|
|
|
2014-03-22 12:16:43 -04:00
|
|
|
|
if (dto.MediaSources != null && dto.MediaSources.Count > 0)
|
2014-03-20 23:31:40 -04:00
|
|
|
|
{
|
2014-03-21 23:35:03 -04:00
|
|
|
|
chapters = _itemRepo.GetChapters(item.Id).Select(c => GetChapterInfoDto(c, item)).ToList();
|
2014-03-20 23:31:40 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
chapters = _itemRepo.GetChapters(video.Id)
|
|
|
|
|
.Select(c => GetChapterInfoDto(c, item))
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dto.Chapters = chapters;
|
2014-03-20 11:55:22 -04:00
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (fields.Contains(ItemFields.MediaStreams))
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
// Add VideoInfo
|
2014-06-11 15:31:33 -04:00
|
|
|
|
var iHasMediaSources = item as IHasMediaSources;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2014-06-11 15:31:33 -04:00
|
|
|
|
if (iHasMediaSources != null)
|
2013-09-04 13:02:19 -04:00
|
|
|
|
{
|
2014-03-20 23:31:40 -04:00
|
|
|
|
List<MediaStream> mediaStreams;
|
|
|
|
|
|
2014-03-22 12:16:43 -04:00
|
|
|
|
if (dto.MediaSources != null && dto.MediaSources.Count > 0)
|
2013-12-05 22:39:44 -05:00
|
|
|
|
{
|
2014-03-22 12:31:21 -04:00
|
|
|
|
mediaStreams = dto.MediaSources.Where(i => new Guid(i.Id) == item.Id)
|
2014-03-20 23:31:40 -04:00
|
|
|
|
.SelectMany(i => i.MediaStreams)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-06-11 15:31:33 -04:00
|
|
|
|
mediaStreams = iHasMediaSources.GetMediaSources(true).First().MediaStreams;
|
2014-03-20 23:31:40 -04:00
|
|
|
|
}
|
2013-12-05 22:39:44 -05:00
|
|
|
|
|
2014-03-20 23:31:40 -04:00
|
|
|
|
dto.MediaStreams = mediaStreams;
|
2013-09-04 13:02:19 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add MovieInfo
|
|
|
|
|
var movie = item as Movie;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (movie != null)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
var specialFeatureCount = movie.SpecialFeatureIds.Count;
|
|
|
|
|
|
|
|
|
|
if (specialFeatureCount > 0)
|
2013-07-05 20:19:44 -04:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.SpecialFeatureCount = specialFeatureCount;
|
2013-07-05 20:19:44 -04:00
|
|
|
|
}
|
2014-01-28 13:37:01 -05:00
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.TmdbCollectionName))
|
|
|
|
|
{
|
|
|
|
|
dto.TmdbCollectionName = movie.TmdbCollectionName;
|
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
// Add EpisodeInfo
|
|
|
|
|
var episode = item as Episode;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (episode != null)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.IndexNumberEnd = episode.IndexNumberEnd;
|
2013-12-08 15:33:24 -05:00
|
|
|
|
|
|
|
|
|
dto.DvdSeasonNumber = episode.DvdSeasonNumber;
|
|
|
|
|
dto.DvdEpisodeNumber = episode.DvdEpisodeNumber;
|
|
|
|
|
dto.AirsAfterSeasonNumber = episode.AirsAfterSeasonNumber;
|
|
|
|
|
dto.AirsBeforeEpisodeNumber = episode.AirsBeforeEpisodeNumber;
|
|
|
|
|
dto.AirsBeforeSeasonNumber = episode.AirsBeforeSeasonNumber;
|
2013-12-10 15:42:42 -05:00
|
|
|
|
dto.AbsoluteEpisodeNumber = episode.AbsoluteEpisodeNumber;
|
2013-12-03 23:18:50 -05:00
|
|
|
|
|
|
|
|
|
var seasonId = episode.SeasonId;
|
|
|
|
|
if (seasonId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
dto.SeasonId = seasonId.Value.ToString("N");
|
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
// Add SeriesInfo
|
|
|
|
|
var series = item as Series;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (series != null)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.AirDays = series.AirDays;
|
|
|
|
|
dto.AirTime = series.AirTime;
|
|
|
|
|
dto.Status = series.Status;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.SpecialFeatureCount = series.SpecialFeatureIds.Count;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.SeasonCount = series.SeasonCount;
|
2013-12-10 16:26:30 -05:00
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.Settings))
|
|
|
|
|
{
|
|
|
|
|
dto.DisplaySpecialsWithSeasons = series.DisplaySpecialsWithSeasons;
|
|
|
|
|
}
|
2014-02-28 23:13:44 -05:00
|
|
|
|
|
|
|
|
|
dto.AnimeSeriesIndex = series.AnimeSeriesIndex;
|
2013-09-04 13:02:19 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (episode != null)
|
2013-03-31 13:39:28 -04:00
|
|
|
|
{
|
2014-07-03 22:22:57 -04:00
|
|
|
|
series = episode.Series;
|
2013-09-04 13:02:19 -04:00
|
|
|
|
|
2014-07-03 22:22:57 -04:00
|
|
|
|
if (series != null)
|
|
|
|
|
{
|
|
|
|
|
dto.SeriesId = GetDtoId(series);
|
|
|
|
|
dto.SeriesName = series.Name;
|
|
|
|
|
dto.AirTime = series.AirTime;
|
|
|
|
|
dto.SeriesStudio = series.Studios.FirstOrDefault();
|
|
|
|
|
dto.SeriesThumbImageTag = GetImageCacheTag(series, ImageType.Thumb);
|
|
|
|
|
dto.SeriesPrimaryImageTag = GetImageCacheTag(series, ImageType.Primary);
|
|
|
|
|
}
|
2013-03-31 13:39:28 -04:00
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
// Add SeasonInfo
|
|
|
|
|
var season = item as Season;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (season != null)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2014-07-03 22:22:57 -04:00
|
|
|
|
series = season.Series;
|
2013-09-04 13:02:19 -04:00
|
|
|
|
|
2014-07-03 22:22:57 -04:00
|
|
|
|
if (series != null)
|
|
|
|
|
{
|
|
|
|
|
dto.SeriesId = GetDtoId(series);
|
|
|
|
|
dto.SeriesName = series.Name;
|
|
|
|
|
dto.AirTime = series.AirTime;
|
|
|
|
|
dto.SeriesStudio = series.Studios.FirstOrDefault();
|
2013-11-09 13:44:09 -05:00
|
|
|
|
|
2014-07-03 22:22:57 -04:00
|
|
|
|
dto.SeriesPrimaryImageTag = GetImageCacheTag(series, ImageType.Primary);
|
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
var game = item as Game;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (game != null)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
SetGameProperties(dto, game);
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-27 17:40:42 -04:00
|
|
|
|
var gameSystem = item as GameSystem;
|
|
|
|
|
|
|
|
|
|
if (gameSystem != null)
|
|
|
|
|
{
|
|
|
|
|
SetGameSystemProperties(dto, gameSystem);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
var musicVideo = item as MusicVideo;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (musicVideo != null)
|
|
|
|
|
{
|
|
|
|
|
SetMusicVideoProperties(dto, musicVideo);
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
var book = item as Book;
|
|
|
|
|
if (book != null)
|
|
|
|
|
{
|
|
|
|
|
SetBookProperties(dto, book);
|
|
|
|
|
}
|
2014-03-30 12:49:40 -04:00
|
|
|
|
|
2014-08-28 20:49:25 -04:00
|
|
|
|
var photo = item as Photo;
|
|
|
|
|
if (photo != null)
|
|
|
|
|
{
|
|
|
|
|
SetPhotoProperties(dto, photo);
|
|
|
|
|
}
|
2014-03-30 12:49:40 -04:00
|
|
|
|
|
2014-08-28 20:49:25 -04:00
|
|
|
|
var tvChannel = item as LiveTvChannel;
|
2014-03-30 12:49:40 -04:00
|
|
|
|
if (tvChannel != null)
|
|
|
|
|
{
|
2014-06-16 21:56:23 -04:00
|
|
|
|
dto.MediaSources = tvChannel.GetMediaSources(true).ToList();
|
2014-03-30 12:49:40 -04:00
|
|
|
|
}
|
2014-05-17 17:23:48 -04:00
|
|
|
|
|
|
|
|
|
var channelItem = item as IChannelItem;
|
|
|
|
|
if (channelItem != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ChannelId = channelItem.ChannelId;
|
2014-05-19 15:51:56 -04:00
|
|
|
|
dto.ChannelName = _channelManagerFactory().GetChannel(channelItem.ChannelId).Name;
|
2014-05-17 17:23:48 -04:00
|
|
|
|
}
|
2014-03-30 12:49:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-02 22:16:37 -04:00
|
|
|
|
private void AttachLinkedChildImages(BaseItemDto dto, Folder folder, User user)
|
|
|
|
|
{
|
|
|
|
|
List<BaseItem> linkedChildren = null;
|
|
|
|
|
|
|
|
|
|
if (dto.BackdropImageTags.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
if (linkedChildren == null)
|
|
|
|
|
{
|
|
|
|
|
linkedChildren = user == null
|
|
|
|
|
? folder.GetRecursiveChildren().ToList()
|
|
|
|
|
: folder.GetRecursiveChildren(user, true).ToList();
|
|
|
|
|
}
|
|
|
|
|
var parentWithBackdrop = linkedChildren.FirstOrDefault(i => i.GetImages(ImageType.Backdrop).Any());
|
|
|
|
|
|
|
|
|
|
if (parentWithBackdrop != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ParentBackdropItemId = GetDtoId(parentWithBackdrop);
|
|
|
|
|
dto.ParentBackdropImageTags = GetBackdropImageTags(parentWithBackdrop);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!dto.ImageTags.ContainsKey(ImageType.Primary))
|
|
|
|
|
{
|
|
|
|
|
if (linkedChildren == null)
|
|
|
|
|
{
|
|
|
|
|
linkedChildren = user == null
|
|
|
|
|
? folder.GetRecursiveChildren().ToList()
|
|
|
|
|
: folder.GetRecursiveChildren(user, true).ToList();
|
|
|
|
|
}
|
|
|
|
|
var parentWithImage = linkedChildren.FirstOrDefault(i => i.GetImages(ImageType.Primary).Any());
|
|
|
|
|
|
|
|
|
|
if (parentWithImage != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ParentPrimaryImageItemId = GetDtoId(parentWithImage);
|
|
|
|
|
dto.ParentPrimaryImageTag = GetImageCacheTag(parentWithImage, ImageType.Primary);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-20 23:31:40 -04:00
|
|
|
|
private string GetMappedPath(IHasMetadata item)
|
2014-03-20 11:55:22 -04:00
|
|
|
|
{
|
2014-03-20 23:31:40 -04:00
|
|
|
|
var path = item.Path;
|
2014-03-20 11:55:22 -04:00
|
|
|
|
|
2014-03-20 23:31:40 -04:00
|
|
|
|
var locationType = item.LocationType;
|
2014-03-20 11:55:22 -04:00
|
|
|
|
|
2014-06-02 15:32:41 -04:00
|
|
|
|
if (locationType == LocationType.FileSystem || locationType == LocationType.Offline)
|
2014-03-20 11:55:22 -04:00
|
|
|
|
{
|
2014-06-02 15:32:41 -04:00
|
|
|
|
foreach (var map in _config.Configuration.PathSubstitutions)
|
|
|
|
|
{
|
|
|
|
|
path = _fileSystem.SubstitutePath(path, map.From, map.To);
|
|
|
|
|
}
|
2014-03-20 11:55:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 11:50:21 -05: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-20 20:33:05 -05:00
|
|
|
|
/// <summary>
|
2013-09-04 13:02:19 -04: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-20 20:33:05 -05:00
|
|
|
|
/// </summary>
|
2013-09-04 13:02:19 -04:00
|
|
|
|
/// <param name="folder">The folder.</param>
|
|
|
|
|
/// <param name="user">The user.</param>
|
|
|
|
|
/// <param name="dto">The dto.</param>
|
2013-09-23 10:26:20 -04:00
|
|
|
|
/// <param name="fields">The fields.</param>
|
2013-09-04 13:02:19 -04:00
|
|
|
|
/// <returns>Task.</returns>
|
2013-09-23 10:26:20 -04:00
|
|
|
|
private void SetSpecialCounts(Folder folder, User user, BaseItemDto dto, List<ItemFields> fields)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
var recursiveItemCount = 0;
|
|
|
|
|
var unplayed = 0;
|
|
|
|
|
long runtime = 0;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2014-02-10 13:43:33 -05:00
|
|
|
|
DateTime? dateLastMediaAdded = null;
|
2013-09-04 13:02:19 -04:00
|
|
|
|
double totalPercentPlayed = 0;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-12-10 15:42:42 -05:00
|
|
|
|
IEnumerable<BaseItem> children;
|
|
|
|
|
|
|
|
|
|
var season = folder as Season;
|
|
|
|
|
|
|
|
|
|
if (season != null)
|
|
|
|
|
{
|
|
|
|
|
children = season.GetEpisodes(user).Where(i => i.LocationType != LocationType.Virtual);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-07-01 17:13:32 -04:00
|
|
|
|
children = folder.GetRecursiveChildren(user)
|
|
|
|
|
.Where(i => !i.IsFolder && i.LocationType != LocationType.Virtual);
|
2013-12-10 15:42:42 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
// Loop through each recursive child
|
2013-12-10 15:42:42 -05:00
|
|
|
|
foreach (var child in children)
|
2013-09-04 13:02:19 -04:00
|
|
|
|
{
|
2014-02-10 13:43:33 -05:00
|
|
|
|
if (!dateLastMediaAdded.HasValue)
|
|
|
|
|
{
|
|
|
|
|
dateLastMediaAdded = child.DateCreated;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dateLastMediaAdded = new[] { dateLastMediaAdded.Value, child.DateCreated }.Max();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
var userdata = _userDataRepository.GetUserData(user.Id, child.GetUserDataKey());
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
recursiveItemCount++;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
var isUnplayed = true;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
// Incrememt totalPercentPlayed
|
|
|
|
|
if (userdata != null)
|
|
|
|
|
{
|
|
|
|
|
if (userdata.Played)
|
|
|
|
|
{
|
|
|
|
|
totalPercentPlayed += 100;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04: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-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
if (isUnplayed)
|
|
|
|
|
{
|
|
|
|
|
unplayed++;
|
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
runtime += child.RunTimeTicks ?? 0;
|
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
dto.RecursiveItemCount = recursiveItemCount;
|
2014-08-17 01:38:13 -04:00
|
|
|
|
dto.UserData.UnplayedItemCount = unplayed;
|
2014-08-21 22:24:38 -04:00
|
|
|
|
dto.RecursiveUnplayedItemCount = unplayed;
|
2013-09-04 13:02:19 -04:00
|
|
|
|
|
|
|
|
|
if (recursiveItemCount > 0)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2014-08-17 01:38:13 -04:00
|
|
|
|
dto.UserData.PlayedPercentage = totalPercentPlayed / recursiveItemCount;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-23 10:26:20 -04:00
|
|
|
|
if (runtime > 0 && fields.Contains(ItemFields.CumulativeRunTimeTicks))
|
2013-09-04 13:02:19 -04:00
|
|
|
|
{
|
|
|
|
|
dto.CumulativeRunTimeTicks = runtime;
|
|
|
|
|
}
|
2014-02-10 13:43:33 -05:00
|
|
|
|
|
|
|
|
|
if (fields.Contains(ItemFields.DateLastMediaAdded))
|
|
|
|
|
{
|
|
|
|
|
dto.DateLastMediaAdded = dateLastMediaAdded;
|
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2013-09-04 13:02:19 -04:00
|
|
|
|
/// Attaches the primary image aspect ratio.
|
2013-02-20 20:33:05 -05:00
|
|
|
|
/// </summary>
|
2013-09-04 13:02:19 -04:00
|
|
|
|
/// <param name="dto">The dto.</param>
|
2013-02-20 20:33:05 -05:00
|
|
|
|
/// <param name="item">The item.</param>
|
2013-09-04 13:02:19 -04:00
|
|
|
|
/// <returns>Task.</returns>
|
2014-01-14 15:03:35 -05:00
|
|
|
|
public void AttachPrimaryImageAspectRatio(IItemDto dto, IHasImages item)
|
2013-02-20 20:33:05 -05:00
|
|
|
|
{
|
2014-02-07 15:30:41 -05:00
|
|
|
|
var imageInfo = item.GetImageInfo(ImageType.Primary, 0);
|
2013-05-05 00:49:49 -04:00
|
|
|
|
|
2014-02-07 15:30:41 -05:00
|
|
|
|
if (imageInfo == null)
|
2013-09-04 13:02:19 -04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-07 15:30:41 -05:00
|
|
|
|
var path = imageInfo.Path;
|
|
|
|
|
|
2013-09-04 13:02:19 -04:00
|
|
|
|
// See if we can avoid a file system lookup by looking for the file in ResolveArgs
|
2014-02-07 15:30:41 -05:00
|
|
|
|
var dateModified = imageInfo.DateModified;
|
2013-09-04 13:02:19 -04:00
|
|
|
|
|
|
|
|
|
ImageSize size;
|
2013-07-05 20:19:44 -04:00
|
|
|
|
|
|
|
|
|
try
|
2013-05-05 00:49:49 -04:00
|
|
|
|
{
|
2013-09-18 14:49:06 -04:00
|
|
|
|
size = _imageProcessor.GetImageSize(path, dateModified);
|
2013-07-05 20:19:44 -04:00
|
|
|
|
}
|
2013-09-04 13:02:19 -04:00
|
|
|
|
catch (FileNotFoundException)
|
2013-07-05 20:19:44 -04:00
|
|
|
|
{
|
2013-09-04 13:02:19 -04:00
|
|
|
|
_logger.Error("Image file does not exist: {0}", path);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Failed to determine primary image aspect ratio for {0}", ex, path);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dto.OriginalPrimaryImageAspectRatio = size.Width / size.Height;
|
|
|
|
|
|
2013-09-18 14:49:06 -04:00
|
|
|
|
var supportedEnhancers = _imageProcessor.GetSupportedEnhancers(item, ImageType.Primary).ToList();
|
2013-09-04 13:02:19 -04: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 00:49:49 -04:00
|
|
|
|
}
|
2013-09-04 13:02:19 -04:00
|
|
|
|
|
|
|
|
|
dto.PrimaryImageAspectRatio = size.Width / size.Height;
|
2013-05-05 00:49:49 -04:00
|
|
|
|
}
|
2013-02-20 20:33:05 -05:00
|
|
|
|
}
|
|
|
|
|
}
|