jellyfin-server/MediaBrowser.Controller/Entities/Movies/BoxSet.cs

148 lines
5.3 KiB
C#
Raw Normal View History

2014-02-07 03:10:13 +00:00
using MediaBrowser.Common.Progress;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
2013-12-02 16:46:25 +00:00
using MediaBrowser.Model.Entities;
2014-01-02 03:53:27 +00:00
using MediaBrowser.Model.Querying;
2013-12-26 16:53:23 +00:00
using System;
2013-12-02 16:46:25 +00:00
using System.Collections.Generic;
2014-02-07 03:10:13 +00:00
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
2013-12-02 16:46:25 +00:00
2013-02-21 01:33:05 +00:00
namespace MediaBrowser.Controller.Entities.Movies
{
/// <summary>
/// Class BoxSet
/// </summary>
2014-02-07 03:10:13 +00:00
public class BoxSet : Folder, IHasTrailers, IHasTags, IHasKeywords, IHasPreferredMetadataLanguage, IHasDisplayOrder, IHasLookupInfo<BoxSetInfo>, IMetadataContainer
2013-02-21 01:33:05 +00:00
{
2013-12-02 16:46:25 +00:00
public BoxSet()
{
RemoteTrailers = new List<MediaUrl>();
LocalTrailerIds = new List<Guid>();
Tags = new List<string>();
2014-01-03 20:43:44 +00:00
DisplayOrder = ItemSortBy.PremiereDate;
2014-01-14 15:50:39 +00:00
Keywords = new List<string>();
2013-12-02 16:46:25 +00:00
}
public List<Guid> LocalTrailerIds { get; set; }
2014-01-02 03:53:27 +00:00
2013-12-02 16:46:25 +00:00
/// <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> Tags { get; set; }
2014-01-14 15:50:39 +00:00
public List<string> Keywords { get; set; }
2013-12-26 16:53:23 +00:00
public string PreferredMetadataLanguage { get; set; }
2013-12-28 16:58:13 +00:00
/// <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; }
2013-12-26 16:53:23 +00:00
protected override bool GetBlockUnratedValue(UserConfiguration config)
{
return config.BlockUnratedItems.Contains(UnratedItem.Movie);
2013-12-26 16:53:23 +00:00
}
2014-01-02 03:53:27 +00:00
public override IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren)
{
var children = base.GetChildren(user, includeLinkedChildren);
2014-01-03 20:43:44 +00:00
if (string.Equals(DisplayOrder, ItemSortBy.SortName, StringComparison.OrdinalIgnoreCase))
{
// Sort by name
return LibraryManager.Sort(children, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending);
}
2014-01-03 20:43:44 +00:00
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
2014-01-02 03:53:27 +00:00
return LibraryManager.Sort(children, user, new[] { ItemSortBy.ProductionYear, ItemSortBy.PremiereDate, ItemSortBy.SortName }, SortOrder.Ascending);
}
2014-02-07 03:10:13 +00:00
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);
var tasks = new List<Task>();
// Refresh songs
foreach (var item in items)
{
2014-02-19 05:21:03 +00:00
if (tasks.Count >= 3)
2014-02-07 03:10:13 +00:00
{
await Task.WhenAll(tasks).ConfigureAwait(false);
tasks.Clear();
}
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);
}
});
2014-02-15 16:36:09 +00:00
// Avoid implicitly captured closure
var taskChild = item;
tasks.Add(Task.Run(async () => await RefreshItem(taskChild, refreshOptions, innerProgress, cancellationToken).ConfigureAwait(false), cancellationToken));
2014-02-07 03:10:13 +00:00
}
await Task.WhenAll(tasks).ConfigureAwait(false);
tasks.Clear();
// 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);
}
2013-02-21 01:33:05 +00:00
}
}