123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- using MediaBrowser.Common.Progress;
- using MediaBrowser.Controller.Providers;
- using MediaBrowser.Model.Configuration;
- using MediaBrowser.Model.Entities;
- using MediaBrowser.Model.Querying;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.Threading;
- using System.Threading.Tasks;
- namespace MediaBrowser.Controller.Entities.Movies
- {
- /// <summary>
- /// Class BoxSet
- /// </summary>
- public class BoxSet : Folder, IHasTrailers, IHasKeywords, IHasPreferredMetadataLanguage, IHasDisplayOrder, IHasLookupInfo<BoxSetInfo>, IMetadataContainer, IHasShares
- {
- public List<Share> Shares { get; set; }
-
- public BoxSet()
- {
- RemoteTrailers = new List<MediaUrl>();
- LocalTrailerIds = new List<Guid>();
- RemoteTrailerIds = new List<Guid>();
- DisplayOrder = ItemSortBy.PremiereDate;
- Keywords = new List<string>();
- Shares = new List<Share>();
- }
- protected override bool FilterLinkedChildrenPerUser
- {
- get
- {
- return true;
- }
- }
- public List<Guid> LocalTrailerIds { get; set; }
- public List<Guid> RemoteTrailerIds { get; set; }
- /// <summary>
- /// Gets or sets the remote trailers.
- /// </summary>
- /// <value>The remote trailers.</value>
- public List<MediaUrl> RemoteTrailers { get; set; }
- /// <summary>
- /// Gets or sets the tags.
- /// </summary>
- /// <value>The tags.</value>
- public List<string> Keywords { get; set; }
- public string PreferredMetadataLanguage { get; set; }
- /// <summary>
- /// Gets or sets the preferred metadata country code.
- /// </summary>
- /// <value>The preferred metadata country code.</value>
- public string PreferredMetadataCountryCode { get; set; }
- /// <summary>
- /// Gets or sets the display order.
- /// </summary>
- /// <value>The display order.</value>
- public string DisplayOrder { get; set; }
- protected override bool GetBlockUnratedValue(UserConfiguration config)
- {
- return config.BlockUnratedItems.Contains(UnratedItem.Movie);
- }
- [IgnoreDataMember]
- public override bool IsPreSorted
- {
- get
- {
- return true;
- }
- }
- /// <summary>
- /// Gets the trailer ids.
- /// </summary>
- /// <returns>List<Guid>.</returns>
- public List<Guid> GetTrailerIds()
- {
- var list = LocalTrailerIds.ToList();
- list.AddRange(RemoteTrailerIds);
- return list;
- }
- public override IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren)
- {
- var children = base.GetChildren(user, includeLinkedChildren);
- if (string.Equals(DisplayOrder, ItemSortBy.SortName, StringComparison.OrdinalIgnoreCase))
- {
- // Sort by name
- return LibraryManager.Sort(children, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending);
- }
- if (string.Equals(DisplayOrder, ItemSortBy.PremiereDate, StringComparison.OrdinalIgnoreCase))
- {
- // Sort by release date
- return LibraryManager.Sort(children, user, new[] { ItemSortBy.ProductionYear, ItemSortBy.PremiereDate, ItemSortBy.SortName }, SortOrder.Ascending);
- }
- // Default sorting
- return LibraryManager.Sort(children, user, new[] { ItemSortBy.ProductionYear, ItemSortBy.PremiereDate, ItemSortBy.SortName }, SortOrder.Ascending);
- }
- public BoxSetInfo GetLookupInfo()
- {
- return GetItemLookupInfo<BoxSetInfo>();
- }
- public async Task RefreshAllMetadata(MetadataRefreshOptions refreshOptions, IProgress<double> progress, CancellationToken cancellationToken)
- {
- // Refresh bottom up, children first, then the boxset
- // By then hopefully the movies within will have Tmdb collection values
- var items = RecursiveChildren.ToList();
- var totalItems = items.Count;
- var percentages = new Dictionary<Guid, double>(totalItems);
- // Refresh songs
- foreach (var item in items)
- {
- cancellationToken.ThrowIfCancellationRequested();
- var innerProgress = new ActionableProgress<double>();
- // Avoid implicitly captured closure
- var currentChild = item;
- innerProgress.RegisterAction(p =>
- {
- lock (percentages)
- {
- percentages[currentChild.Id] = p / 100;
- var percent = percentages.Values.Sum();
- percent /= totalItems;
- percent *= 100;
- progress.Report(percent);
- }
- });
- // Avoid implicitly captured closure
- await RefreshItem(item, refreshOptions, innerProgress, cancellationToken).ConfigureAwait(false);
- }
- // Refresh current item
- await RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
- progress.Report(100);
- }
- private async Task RefreshItem(BaseItem item, MetadataRefreshOptions refreshOptions, IProgress<double> progress, CancellationToken cancellationToken)
- {
- await item.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
- progress.Report(100);
- }
- public override bool IsVisible(User user)
- {
- if (base.IsVisible(user))
- {
- var userId = user.Id.ToString("N");
- return Shares.Any(i => string.Equals(userId, i.UserId, StringComparison.OrdinalIgnoreCase)) ||
- // Need to support this for boxsets created prior to the creation of Shares
- Shares.Count == 0;
- }
- return false;
- }
- }
- }
|