mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-15 09:59:06 -07:00
100 lines
3.2 KiB
C#
100 lines
3.2 KiB
C#
using MediaBrowser.Controller.Configuration;
|
|
using MediaBrowser.Controller.Entities;
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
using MediaBrowser.Controller.Library;
|
|
using MediaBrowser.Controller.Providers;
|
|
using MediaBrowser.Model.Entities;
|
|
using MediaBrowser.Model.Logging;
|
|
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MediaBrowser.Providers.TV
|
|
{
|
|
/// <summary>
|
|
/// Making this a provider because of how slow it is
|
|
/// It only ever needs to run once
|
|
/// </summary>
|
|
public class EpisodeIndexNumberProvider : BaseMetadataProvider
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="BaseMetadataProvider" /> class.
|
|
/// </summary>
|
|
/// <param name="logManager">The log manager.</param>
|
|
/// <param name="configurationManager">The configuration manager.</param>
|
|
public EpisodeIndexNumberProvider(ILogManager logManager, IServerConfigurationManager configurationManager)
|
|
: base(logManager, configurationManager)
|
|
{
|
|
}
|
|
|
|
protected override bool RefreshOnVersionChange
|
|
{
|
|
get
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
protected override string ProviderVersion
|
|
{
|
|
get
|
|
{
|
|
return "2";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Supportses the specified item.
|
|
/// </summary>
|
|
/// <param name="item">The item.</param>
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
|
public override bool Supports(BaseItem item)
|
|
{
|
|
if (item is Episode)
|
|
{
|
|
var locationType = item.LocationType;
|
|
return locationType != LocationType.Virtual && locationType != LocationType.Remote;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
|
|
/// </summary>
|
|
/// <param name="item">The item.</param>
|
|
/// <param name="force">if set to <c>true</c> [force].</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <returns>Task{System.Boolean}.</returns>
|
|
public override Task<bool> FetchAsync(BaseItem item, bool force, BaseProviderInfo providerInfo, CancellationToken cancellationToken)
|
|
{
|
|
var episode = (Episode)item;
|
|
|
|
episode.IndexNumber = TVUtils.GetEpisodeNumberFromFile(item.Path, item.Parent is Season);
|
|
episode.IndexNumberEnd = TVUtils.GetEndingEpisodeNumberFromFile(item.Path);
|
|
|
|
if (!episode.ParentIndexNumber.HasValue)
|
|
{
|
|
var season = episode.Parent as Season;
|
|
|
|
if (season != null)
|
|
{
|
|
episode.ParentIndexNumber = season.IndexNumber;
|
|
}
|
|
}
|
|
|
|
SetLastRefreshed(item, DateTime.UtcNow, providerInfo);
|
|
|
|
return TrueTaskResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the priority.
|
|
/// </summary>
|
|
/// <value>The priority.</value>
|
|
public override MetadataProviderPriority Priority
|
|
{
|
|
get { return MetadataProviderPriority.First; }
|
|
}
|
|
}
|
|
}
|