using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Providers.TV
{
///
/// Making this a provider because of how slow it is
/// It only ever needs to run once
///
public class EpisodeIndexNumberProvider : BaseMetadataProvider
{
///
/// Initializes a new instance of the class.
///
/// The log manager.
/// The configuration manager.
public EpisodeIndexNumberProvider(ILogManager logManager, IServerConfigurationManager configurationManager)
: base(logManager, configurationManager)
{
}
///
/// Supportses the specified item.
///
/// The item.
/// true if XXXX, false otherwise
public override bool Supports(BaseItem item)
{
return item is Episode;
}
///
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
///
/// The item.
/// if set to true [force].
/// The cancellation token.
/// Task{System.Boolean}.
public override Task FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
var episode = (Episode)item;
episode.IndexNumber = TVUtils.GetEpisodeNumberFromFile(item.Path, item.Parent is Season);
episode.IndexNumberEnd = TVUtils.GetEndingEpisodeNumberFromFile(item.Path);
SetLastRefreshed(item, DateTime.UtcNow);
return TrueTaskResult;
}
///
/// Gets the priority.
///
/// The priority.
public override MetadataProviderPriority Priority
{
get { return MetadataProviderPriority.First; }
}
}
}