|
|
|
@ -1,11 +1,23 @@
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Common.Extensions;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Providers
|
|
|
|
|
{
|
|
|
|
|
public abstract class BaseMetadataProvider
|
|
|
|
|
{
|
|
|
|
|
protected Guid _id;
|
|
|
|
|
public virtual Guid Id
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_id == null) _id = this.GetType().FullName.GetMD5();
|
|
|
|
|
return _id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract bool Supports(BaseEntity item);
|
|
|
|
|
|
|
|
|
|
public virtual bool RequiresInternet
|
|
|
|
@ -16,6 +28,49 @@ namespace MediaBrowser.Controller.Providers
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the last refresh time of this provider for this item. Providers that care should
|
|
|
|
|
/// call SetLastRefreshed to update this value.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected virtual DateTime LastRefreshed(BaseEntity item)
|
|
|
|
|
{
|
|
|
|
|
return (item.ProviderData[this.Id] ?? new BaseProviderInfo()).LastRefreshed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the persisted last refresh date on the item for this provider.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item"></param>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
protected virtual void SetLastRefreshed(BaseEntity item, DateTime value)
|
|
|
|
|
{
|
|
|
|
|
var data = item.ProviderData[this.Id] ?? new BaseProviderInfo();
|
|
|
|
|
data.LastRefreshed = value;
|
|
|
|
|
item.ProviderData[this.Id] = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns whether or not this provider should be re-fetched. Default functionality can
|
|
|
|
|
/// compare a provided date with a last refresh time. This can be overridden for more complex
|
|
|
|
|
/// determinations.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public virtual bool NeedsRefresh(BaseEntity item)
|
|
|
|
|
{
|
|
|
|
|
return CompareDate(item) > LastRefreshed(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Override this to return the date that should be compared to the last refresh date
|
|
|
|
|
/// to determine if this provider should be re-fetched.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual DateTime CompareDate(BaseEntity item)
|
|
|
|
|
{
|
|
|
|
|
return DateTime.MinValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract Task FetchAsync(BaseEntity item, ItemResolveEventArgs args);
|
|
|
|
|
|
|
|
|
|
public abstract MetadataProviderPriority Priority { get; }
|
|
|
|
|