mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-16 02:18:54 -07:00
consolidated duplicate code
This commit is contained in:
parent
46a546732c
commit
2a5ba9e707
@ -203,6 +203,8 @@ namespace MediaBrowser.Controller.Providers
|
||||
throw new ArgumentNullException("providerInfo");
|
||||
}
|
||||
|
||||
if (item.DontFetchMeta && RequiresInternet) return false;
|
||||
|
||||
if (CompareDate(item) > providerInfo.LastRefreshed)
|
||||
{
|
||||
return true;
|
||||
@ -218,6 +220,16 @@ namespace MediaBrowser.Controller.Providers
|
||||
return true;
|
||||
}
|
||||
|
||||
if (RequiresInternet && DateTime.UtcNow > (providerInfo.LastRefreshed.AddDays(ConfigurationManager.Configuration.MetadataRefreshDays)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (providerInfo.LastRefreshStatus != ProviderRefreshStatus.Success)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -67,20 +67,6 @@ namespace MediaBrowser.Controller.Providers
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Needses the refresh internal.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="providerInfo">The provider info.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||
{
|
||||
if (item.DontFetchMeta) return false;
|
||||
|
||||
return DateTime.UtcNow > (providerInfo.LastRefreshed.AddDays(ConfigurationManager.Configuration.MetadataRefreshDays))
|
||||
&& ShouldFetch(item, providerInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether [requires internet].
|
||||
/// </summary>
|
||||
@ -99,16 +85,6 @@ namespace MediaBrowser.Controller.Providers
|
||||
get { return MetadataProviderPriority.Third; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shoulds the fetch.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="providerInfo">The provider info.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
protected virtual bool ShouldFetch(BaseItem item, BaseProviderInfo providerInfo)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#region Result Objects
|
||||
|
||||
protected class FanArtImageInfo
|
||||
|
@ -1,5 +1,4 @@
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
@ -74,22 +73,26 @@ namespace MediaBrowser.Controller.Providers.Movies
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shoulds the fetch.
|
||||
/// Needses the refresh internal.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="providerInfo">The provider info.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
protected override bool ShouldFetch(BaseItem item, BaseProviderInfo providerInfo)
|
||||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||
{
|
||||
var baseItem = item;
|
||||
if (item.Path == null || item.DontFetchMeta || string.IsNullOrEmpty(baseItem.GetProviderId(MetadataProviders.Tmdb))) return false; //nothing to do
|
||||
var artExists = item.ResolveArgs.ContainsMetaFileByName(ART_FILE);
|
||||
var logoExists = item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE);
|
||||
var discExists = item.ResolveArgs.ContainsMetaFileByName(DISC_FILE);
|
||||
if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tmdb)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return (!artExists && ConfigurationManager.Configuration.DownloadMovieImages.Art)
|
||||
|| (!logoExists && ConfigurationManager.Configuration.DownloadMovieImages.Logo)
|
||||
|| (!discExists && ConfigurationManager.Configuration.DownloadMovieImages.Disc);
|
||||
if (!ConfigurationManager.Configuration.DownloadMovieImages.Art &&
|
||||
!ConfigurationManager.Configuration.DownloadMovieImages.Logo &&
|
||||
!ConfigurationManager.Configuration.DownloadMovieImages.Disc)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.NeedsRefreshInternal(item, providerInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -105,14 +108,6 @@ namespace MediaBrowser.Controller.Providers.Movies
|
||||
|
||||
var movie = item;
|
||||
|
||||
BaseProviderInfo providerData;
|
||||
|
||||
if (!item.ProviderData.TryGetValue(Id, out providerData))
|
||||
{
|
||||
providerData = new BaseProviderInfo();
|
||||
}
|
||||
if (ShouldFetch(movie, providerData))
|
||||
{
|
||||
var language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
|
||||
var url = string.Format(FanArtBaseUrl, APIKey, movie.GetProviderId(MetadataProviders.Tmdb));
|
||||
var doc = new XmlDocument();
|
||||
@ -259,7 +254,6 @@ namespace MediaBrowser.Controller.Providers.Movies
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SetLastRefreshed(movie, DateTime.UtcNow);
|
||||
return true;
|
||||
}
|
||||
|
@ -31,19 +31,6 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
return item is MusicAlbum;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Needses the refresh internal.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="providerInfo">The provider info.</param>
|
||||
/// <returns><c>true</c> if we need refreshing, <c>false</c> otherwise</returns>
|
||||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||
{
|
||||
//we fetch if image needed and haven't already tried recently
|
||||
return (string.IsNullOrEmpty(item.PrimaryImagePath) || !item.HasImage(ImageType.Disc)) &&
|
||||
DateTime.Today.Subtract(providerInfo.LastRefreshed).TotalDays > ConfigurationManager.Configuration.MetadataRefreshDays;
|
||||
}
|
||||
|
||||
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
|
||||
{
|
||||
var mbid = item.GetProviderId(MetadataProviders.Musicbrainz);
|
||||
|
@ -1,8 +1,6 @@
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Net;
|
||||
@ -60,18 +58,28 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shoulds the fetch.
|
||||
/// Needses the refresh internal.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="providerInfo">The provider info.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
protected override bool ShouldFetch(BaseItem item, BaseProviderInfo providerInfo)
|
||||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||
{
|
||||
if (item.Path == null || item.DontFetchMeta || string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Musicbrainz))) return false; //nothing to do
|
||||
if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Musicbrainz)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return (!item.ResolveArgs.ContainsMetaFileByName(ART_FILE) && ConfigurationManager.Configuration.DownloadMusicArtistImages.Art)
|
||||
|| (!item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE) && ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo)
|
||||
|| (!item.ResolveArgs.ContainsMetaFileByName(DISC_FILE) && ConfigurationManager.Configuration.DownloadMusicArtistImages.Disc);
|
||||
if (!ConfigurationManager.Configuration.DownloadMusicArtistImages.Art &&
|
||||
!ConfigurationManager.Configuration.DownloadMusicArtistImages.Backdrops &&
|
||||
!ConfigurationManager.Configuration.DownloadMusicArtistImages.Banner &&
|
||||
!ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo &&
|
||||
!ConfigurationManager.Configuration.DownloadMusicArtistImages.Primary)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.NeedsRefreshInternal(item, providerInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -87,15 +95,6 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
|
||||
//var artist = item;
|
||||
|
||||
BaseProviderInfo providerData;
|
||||
|
||||
if (!item.ProviderData.TryGetValue(Id, out providerData))
|
||||
{
|
||||
providerData = new BaseProviderInfo();
|
||||
}
|
||||
|
||||
if (ShouldFetch(item, providerData))
|
||||
{
|
||||
var url = string.Format(FanArtBaseUrl, APIKey, item.GetProviderId(MetadataProviders.Musicbrainz));
|
||||
var doc = new XmlDocument();
|
||||
|
||||
@ -201,7 +200,7 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
|
||||
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Banner && !item.ResolveArgs.ContainsMetaFileByName(BANNER_FILE))
|
||||
{
|
||||
var node = doc.SelectSingleNode("//fanart/music/musicbanners/"+hd+"musicbanner/@url") ??
|
||||
var node = doc.SelectSingleNode("//fanart/music/musicbanners/" + hd + "musicbanner/@url") ??
|
||||
doc.SelectSingleNode("//fanart/music/musicbanners/musicbanner/@url");
|
||||
path = node != null ? node.Value : null;
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
@ -245,7 +244,7 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SetLastRefreshed(item, DateTime.UtcNow);
|
||||
return true;
|
||||
}
|
||||
|
@ -168,36 +168,6 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
return WebUtility.UrlEncode(name);
|
||||
}
|
||||
|
||||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||
{
|
||||
if (item.DontFetchMeta) return false;
|
||||
|
||||
if (RefreshOnFileSystemStampChange && HasFileSystemStampChanged(item, providerInfo))
|
||||
{
|
||||
//If they deleted something from file system, chances are, this item was mis-identified the first time
|
||||
item.SetProviderId(MetadataProviders.Musicbrainz, null);
|
||||
Logger.Debug("LastfmProvider reports file system stamp change...");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (providerInfo.LastRefreshStatus != ProviderRefreshStatus.Success)
|
||||
{
|
||||
Logger.Debug("LastfmProvider for {0} - last attempt had errors. Will try again.", item.Path);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (RefreshOnVersionChange && ProviderVersion != providerInfo.ProviderVersion)
|
||||
{
|
||||
Logger.Debug("LastfmProvider version change re-running for {0}", item.Path);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (DateTime.UtcNow.Subtract(providerInfo.LastRefreshed).TotalDays > ConfigurationManager.Configuration.MetadataRefreshDays) // only refresh every n days
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
|
||||
/// </summary>
|
||||
|
@ -1,5 +1,4 @@
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
@ -42,17 +41,27 @@ namespace MediaBrowser.Controller.Providers.TV
|
||||
return item is Series;
|
||||
}
|
||||
|
||||
protected override bool ShouldFetch(BaseItem item, BaseProviderInfo providerInfo)
|
||||
/// <summary>
|
||||
/// Needses the refresh internal.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="providerInfo">The provider info.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||
{
|
||||
if (item.DontFetchMeta || string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tvdb))) return false; //nothing to do
|
||||
var artExists = item.ResolveArgs.ContainsMetaFileByName(ART_FILE);
|
||||
var logoExists = item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE);
|
||||
var thumbExists = item.ResolveArgs.ContainsMetaFileByName(THUMB_FILE);
|
||||
if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tvdb)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ConfigurationManager.Configuration.DownloadSeriesImages.Art &&
|
||||
!ConfigurationManager.Configuration.DownloadSeriesImages.Logo &&
|
||||
!ConfigurationManager.Configuration.DownloadSeriesImages.Thumb)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return (!artExists && ConfigurationManager.Configuration.DownloadSeriesImages.Art)
|
||||
|| (!logoExists && ConfigurationManager.Configuration.DownloadSeriesImages.Logo)
|
||||
|| (!thumbExists && ConfigurationManager.Configuration.DownloadSeriesImages.Thumb);
|
||||
return base.NeedsRefreshInternal(item, providerInfo);
|
||||
}
|
||||
|
||||
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
|
||||
@ -61,15 +70,6 @@ namespace MediaBrowser.Controller.Providers.TV
|
||||
|
||||
var series = (Series)item;
|
||||
|
||||
BaseProviderInfo providerData;
|
||||
|
||||
if (!item.ProviderData.TryGetValue(Id, out providerData))
|
||||
{
|
||||
providerData = new BaseProviderInfo();
|
||||
}
|
||||
|
||||
if (ShouldFetch(series, providerData))
|
||||
{
|
||||
string language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
|
||||
string url = string.Format(FanArtBaseUrl, APIKey, series.GetProviderId(MetadataProviders.Tvdb));
|
||||
var doc = new XmlDocument();
|
||||
@ -93,9 +93,9 @@ namespace MediaBrowser.Controller.Providers.TV
|
||||
var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hdtv" : "clear";
|
||||
if (ConfigurationManager.Configuration.DownloadSeriesImages.Logo && !series.ResolveArgs.ContainsMetaFileByName(LOGO_FILE))
|
||||
{
|
||||
var node = doc.SelectSingleNode("//fanart/series/"+hd+"logos/"+hd+"logo[@lang = \"" + language + "\"]/@url") ??
|
||||
var node = doc.SelectSingleNode("//fanart/series/" + hd + "logos/" + hd + "logo[@lang = \"" + language + "\"]/@url") ??
|
||||
doc.SelectSingleNode("//fanart/series/clearlogos/clearlogo[@lang = \"" + language + "\"]/@url") ??
|
||||
doc.SelectSingleNode("//fanart/series/"+hd+"logos/"+hd+"logo/@url") ??
|
||||
doc.SelectSingleNode("//fanart/series/" + hd + "logos/" + hd + "logo/@url") ??
|
||||
doc.SelectSingleNode("//fanart/series/clearlogos/clearlogo/@url");
|
||||
path = node != null ? node.Value : null;
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
@ -120,9 +120,9 @@ namespace MediaBrowser.Controller.Providers.TV
|
||||
hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : "";
|
||||
if (ConfigurationManager.Configuration.DownloadSeriesImages.Art && !series.ResolveArgs.ContainsMetaFileByName(ART_FILE))
|
||||
{
|
||||
var node = doc.SelectSingleNode("//fanart/series/"+hd+"cleararts/"+hd+"clearart[@lang = \"" + language + "\"]/@url") ??
|
||||
var node = doc.SelectSingleNode("//fanart/series/" + hd + "cleararts/" + hd + "clearart[@lang = \"" + language + "\"]/@url") ??
|
||||
doc.SelectSingleNode("//fanart/series/cleararts/clearart[@lang = \"" + language + "\"]/@url") ??
|
||||
doc.SelectSingleNode("//fanart/series/"+hd+"cleararts/"+hd+"clearart/@url") ??
|
||||
doc.SelectSingleNode("//fanart/series/" + hd + "cleararts/" + hd + "clearart/@url") ??
|
||||
doc.SelectSingleNode("//fanart/series/cleararts/clearart/@url");
|
||||
path = node != null ? node.Value : null;
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
@ -166,8 +166,9 @@ namespace MediaBrowser.Controller.Providers.TV
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SetLastRefreshed(series, DateTime.UtcNow);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -96,22 +96,12 @@ namespace MediaBrowser.Controller.Providers.TV
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||
{
|
||||
bool fetch = false;
|
||||
var episode = (Episode)item;
|
||||
var downloadDate = providerInfo.LastRefreshed;
|
||||
|
||||
if (ConfigurationManager.Configuration.MetadataRefreshDays == -1 && downloadDate != DateTime.MinValue)
|
||||
if (HasLocalMeta(item))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!item.DontFetchMeta && !HasLocalMeta(episode))
|
||||
{
|
||||
fetch = ConfigurationManager.Configuration.MetadataRefreshDays != -1 &&
|
||||
DateTime.Today.Subtract(downloadDate).TotalDays > ConfigurationManager.Configuration.MetadataRefreshDays;
|
||||
}
|
||||
|
||||
return fetch;
|
||||
return base.NeedsRefreshInternal(item, providerInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -313,7 +303,7 @@ namespace MediaBrowser.Controller.Providers.TV
|
||||
/// </summary>
|
||||
/// <param name="episode">The episode.</param>
|
||||
/// <returns><c>true</c> if [has local meta] [the specified episode]; otherwise, <c>false</c>.</returns>
|
||||
private bool HasLocalMeta(Episode episode)
|
||||
private bool HasLocalMeta(BaseItem episode)
|
||||
{
|
||||
return (episode.Parent.ResolveArgs.ContainsMetaFileByName(Path.GetFileNameWithoutExtension(episode.Path) + ".xml"));
|
||||
}
|
||||
|
@ -78,19 +78,12 @@ namespace MediaBrowser.Controller.Providers.TV
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||
{
|
||||
bool fetch = false;
|
||||
var downloadDate = providerInfo.LastRefreshed;
|
||||
|
||||
if (ConfigurationManager.Configuration.MetadataRefreshDays == -1 && downloadDate != DateTime.MinValue)
|
||||
return false;
|
||||
|
||||
if (!HasLocalMeta(item))
|
||||
if (HasLocalMeta(item))
|
||||
{
|
||||
fetch = ConfigurationManager.Configuration.MetadataRefreshDays != -1 &&
|
||||
DateTime.UtcNow.Subtract(downloadDate).TotalDays > ConfigurationManager.Configuration.MetadataRefreshDays;
|
||||
return false;
|
||||
}
|
||||
|
||||
return fetch;
|
||||
return base.NeedsRefreshInternal(item, providerInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user