slightly reduce simultaneous requests

This commit is contained in:
Luke Pulverenti 2013-05-19 17:20:47 -04:00
parent 40a2af83c9
commit b2b85d20a5
9 changed files with 50 additions and 50 deletions

View File

@ -97,7 +97,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
};
client = new HttpClient(handler);
client.Timeout = TimeSpan.FromSeconds(15);
client.Timeout = TimeSpan.FromSeconds(30);
_httpClients.TryAdd(host, client);
}

View File

@ -20,47 +20,47 @@ namespace MediaBrowser.Controller.Providers
public abstract class FanartBaseProvider : BaseMetadataProvider
{
protected static readonly SemaphoreSlim FanArtResourcePool = new SemaphoreSlim(5,5);
protected static readonly SemaphoreSlim FanArtResourcePool = new SemaphoreSlim(3,3);
/// <summary>
/// The LOG o_ FILE
/// </summary>
protected const string LOGO_FILE = "logo.png";
protected const string LogoFile = "logo.png";
/// <summary>
/// The AR t_ FILE
/// </summary>
protected const string ART_FILE = "clearart.png";
protected const string ArtFile = "clearart.png";
/// <summary>
/// The THUM b_ FILE
/// </summary>
protected const string THUMB_FILE = "thumb.jpg";
protected const string ThumbFile = "thumb.jpg";
/// <summary>
/// The DIS c_ FILE
/// </summary>
protected const string DISC_FILE = "disc.png";
protected const string DiscFile = "disc.png";
/// <summary>
/// The BANNE r_ FILE
/// </summary>
protected const string BANNER_FILE = "banner.png";
protected const string BannerFile = "banner.png";
/// <summary>
/// The Backdrop
/// </summary>
protected const string BACKDROP_FILE = "backdrop.jpg";
protected const string BackdropFile = "backdrop.jpg";
/// <summary>
/// The Primary image
/// </summary>
protected const string PRIMARY_FILE = "folder.jpg";
protected const string PrimaryFile = "folder.jpg";
/// <summary>
/// The API key
/// </summary>
protected const string APIKey = "5c6b04c68e904cfed1e6cbc9a9e683d4";
protected const string ApiKey = "5c6b04c68e904cfed1e6cbc9a9e683d4";
protected FanartBaseProvider(ILogManager logManager, IServerConfigurationManager configurationManager) : base(logManager, configurationManager)
{

View File

@ -172,7 +172,7 @@ namespace MediaBrowser.Controller.Providers.Movies
var movie = item;
var language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
var url = string.Format(FanArtBaseUrl, APIKey, movie.GetProviderId(MetadataProviders.Tmdb));
var url = string.Format(FanArtBaseUrl, ApiKey, movie.GetProviderId(MetadataProviders.Tmdb));
var doc = new XmlDocument();
using (var xml = await HttpClient.Get(new HttpRequestOptions
@ -198,7 +198,7 @@ namespace MediaBrowser.Controller.Providers.Movies
var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : "";
var hasLogo = item.LocationType == LocationType.FileSystem ?
item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE)
item.ResolveArgs.ContainsMetaFileByName(LogoFile)
: item.HasImage(ImageType.Logo);
if (ConfigurationManager.Configuration.DownloadMovieImages.Logo && !hasLogo)
@ -214,13 +214,13 @@ namespace MediaBrowser.Controller.Providers.Movies
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
movie.SetImage(ImageType.Logo, await _providerManager.DownloadAndSaveImage(movie, path, LOGO_FILE, saveLocal, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
movie.SetImage(ImageType.Logo, await _providerManager.DownloadAndSaveImage(movie, path, LogoFile, saveLocal, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
cancellationToken.ThrowIfCancellationRequested();
var hasArt = item.LocationType == LocationType.FileSystem ?
item.ResolveArgs.ContainsMetaFileByName(ART_FILE)
item.ResolveArgs.ContainsMetaFileByName(ArtFile)
: item.HasImage(ImageType.Art);
if (ConfigurationManager.Configuration.DownloadMovieImages.Art && !hasArt)
@ -233,13 +233,13 @@ namespace MediaBrowser.Controller.Providers.Movies
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
movie.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(movie, path, ART_FILE, saveLocal, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
movie.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(movie, path, ArtFile, saveLocal, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
cancellationToken.ThrowIfCancellationRequested();
var hasDisc = item.LocationType == LocationType.FileSystem ?
item.ResolveArgs.ContainsMetaFileByName(DISC_FILE)
item.ResolveArgs.ContainsMetaFileByName(DiscFile)
: item.HasImage(ImageType.Disc);
if (ConfigurationManager.Configuration.DownloadMovieImages.Disc && !hasDisc)
@ -249,14 +249,14 @@ namespace MediaBrowser.Controller.Providers.Movies
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
movie.SetImage(ImageType.Disc, await _providerManager.DownloadAndSaveImage(movie, path, DISC_FILE, saveLocal, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
movie.SetImage(ImageType.Disc, await _providerManager.DownloadAndSaveImage(movie, path, DiscFile, saveLocal, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
cancellationToken.ThrowIfCancellationRequested();
var hasBanner = item.LocationType == LocationType.FileSystem ?
item.ResolveArgs.ContainsMetaFileByName(BANNER_FILE)
item.ResolveArgs.ContainsMetaFileByName(BannerFile)
: item.HasImage(ImageType.Banner);
if (ConfigurationManager.Configuration.DownloadMovieImages.Banner && !hasBanner)
@ -266,14 +266,14 @@ namespace MediaBrowser.Controller.Providers.Movies
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
movie.SetImage(ImageType.Banner, await _providerManager.DownloadAndSaveImage(movie, path, BANNER_FILE, saveLocal, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
movie.SetImage(ImageType.Banner, await _providerManager.DownloadAndSaveImage(movie, path, BannerFile, saveLocal, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
cancellationToken.ThrowIfCancellationRequested();
var hasThumb = item.LocationType == LocationType.FileSystem ?
item.ResolveArgs.ContainsMetaFileByName(THUMB_FILE)
item.ResolveArgs.ContainsMetaFileByName(ThumbFile)
: item.HasImage(ImageType.Thumb);
if (ConfigurationManager.Configuration.DownloadMovieImages.Thumb && !hasThumb)
@ -283,12 +283,12 @@ namespace MediaBrowser.Controller.Providers.Movies
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
movie.SetImage(ImageType.Thumb, await _providerManager.DownloadAndSaveImage(movie, path, THUMB_FILE, saveLocal, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
movie.SetImage(ImageType.Thumb, await _providerManager.DownloadAndSaveImage(movie, path, ThumbFile, saveLocal, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
var hasBackdrop = item.LocationType == LocationType.FileSystem ?
item.ResolveArgs.ContainsMetaFileByName(BACKDROP_FILE)
item.ResolveArgs.ContainsMetaFileByName(BackdropFile)
: item.BackdropImagePaths.Count > 0;
if (ConfigurationManager.Configuration.DownloadMovieImages.Backdrops && !hasBackdrop)

View File

@ -896,7 +896,7 @@ namespace MediaBrowser.Controller.Providers.Movies
try
{
// Limit to three requests per second
var diff = 330 - (DateTime.Now - _lastRequestDate).TotalMilliseconds;
var diff = 400 - (DateTime.Now - _lastRequestDate).TotalMilliseconds;
if (diff > 0)
{

View File

@ -134,7 +134,7 @@ namespace MediaBrowser.Controller.Providers.Music
return true;
}
var url = string.Format("http://api.fanart.tv/webservice/album/{0}/{1}/xml/all/1/1", APIKey, album.MusicBrainzReleaseGroupId);
var url = string.Format("http://api.fanart.tv/webservice/album/{0}/{1}/xml/all/1/1", ApiKey, album.MusicBrainzReleaseGroupId);
var doc = new XmlDocument();
@ -154,7 +154,7 @@ namespace MediaBrowser.Controller.Providers.Music
if (doc.HasChildNodes)
{
if (ConfigurationManager.Configuration.DownloadMusicAlbumImages.Disc && !item.ResolveArgs.ContainsMetaFileByName(DISC_FILE))
if (ConfigurationManager.Configuration.DownloadMusicAlbumImages.Disc && !item.ResolveArgs.ContainsMetaFileByName(DiscFile))
{
var node = doc.SelectSingleNode("//fanart/music/albums/album/cdart/@url");
@ -163,11 +163,11 @@ namespace MediaBrowser.Controller.Providers.Music
if (!string.IsNullOrEmpty(path))
{
Logger.Debug("FanArtProvider getting Disc for " + item.Name);
item.SetImage(ImageType.Disc, await _providerManager.DownloadAndSaveImage(item, path, DISC_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
item.SetImage(ImageType.Disc, await _providerManager.DownloadAndSaveImage(item, path, DiscFile, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
if (ConfigurationManager.Configuration.DownloadMusicAlbumImages.Primary && !item.ResolveArgs.ContainsMetaFileByName(PRIMARY_FILE))
if (ConfigurationManager.Configuration.DownloadMusicAlbumImages.Primary && !item.ResolveArgs.ContainsMetaFileByName(PrimaryFile))
{
var node = doc.SelectSingleNode("//fanart/music/albums/album/albumcover/@url");
@ -176,7 +176,7 @@ namespace MediaBrowser.Controller.Providers.Music
if (!string.IsNullOrEmpty(path))
{
Logger.Debug("FanArtProvider getting albumcover for " + item.Name);
item.SetImage(ImageType.Primary, await _providerManager.DownloadAndSaveImage(item, path, PRIMARY_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
item.SetImage(ImageType.Primary, await _providerManager.DownloadAndSaveImage(item, path, PrimaryFile, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
}

View File

@ -114,7 +114,7 @@ namespace MediaBrowser.Controller.Providers.Music
//var artist = item;
var url = string.Format(FanArtBaseUrl, APIKey, item.GetProviderId(MetadataProviders.Musicbrainz));
var url = string.Format(FanArtBaseUrl, ApiKey, item.GetProviderId(MetadataProviders.Musicbrainz));
var doc = new XmlDocument();
var status = ProviderRefreshStatus.Success;
@ -137,7 +137,7 @@ namespace MediaBrowser.Controller.Providers.Music
{
string path;
var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : "";
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo && !item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE))
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo && !item.ResolveArgs.ContainsMetaFileByName(LogoFile))
{
var node =
doc.SelectSingleNode("//fanart/music/musiclogos/" + hd + "musiclogo/@url") ??
@ -146,12 +146,12 @@ namespace MediaBrowser.Controller.Providers.Music
if (!string.IsNullOrEmpty(path))
{
Logger.Debug("FanArtProvider getting ClearLogo for " + item.Name);
item.SetImage(ImageType.Logo, await _providerManager.DownloadAndSaveImage(item, path, LOGO_FILE, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
item.SetImage(ImageType.Logo, await _providerManager.DownloadAndSaveImage(item, path, LogoFile, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
cancellationToken.ThrowIfCancellationRequested();
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Backdrops && !item.ResolveArgs.ContainsMetaFileByName(BACKDROP_FILE))
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Backdrops && !item.ResolveArgs.ContainsMetaFileByName(BackdropFile))
{
var nodes = doc.SelectNodes("//fanart/music/artistbackgrounds//@url");
if (nodes != null)
@ -176,7 +176,7 @@ namespace MediaBrowser.Controller.Providers.Music
cancellationToken.ThrowIfCancellationRequested();
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Art && !item.ResolveArgs.ContainsMetaFileByName(ART_FILE))
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Art && !item.ResolveArgs.ContainsMetaFileByName(ArtFile))
{
var node =
doc.SelectSingleNode("//fanart/music/musicarts/" + hd + "musicart/@url") ??
@ -185,12 +185,12 @@ namespace MediaBrowser.Controller.Providers.Music
if (!string.IsNullOrEmpty(path))
{
Logger.Debug("FanArtProvider getting ClearArt for " + item.Name);
item.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(item, path, ART_FILE, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
item.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(item, path, ArtFile, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
cancellationToken.ThrowIfCancellationRequested();
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Banner && !item.ResolveArgs.ContainsMetaFileByName(BANNER_FILE))
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Banner && !item.ResolveArgs.ContainsMetaFileByName(BannerFile))
{
var node = doc.SelectSingleNode("//fanart/music/musicbanners/" + hd + "musicbanner/@url") ??
doc.SelectSingleNode("//fanart/music/musicbanners/musicbanner/@url");
@ -198,21 +198,21 @@ namespace MediaBrowser.Controller.Providers.Music
if (!string.IsNullOrEmpty(path))
{
Logger.Debug("FanArtProvider getting Banner for " + item.Name);
item.SetImage(ImageType.Banner, await _providerManager.DownloadAndSaveImage(item, path, BANNER_FILE, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
item.SetImage(ImageType.Banner, await _providerManager.DownloadAndSaveImage(item, path, BannerFile, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
cancellationToken.ThrowIfCancellationRequested();
// Artist thumbs are actually primary images (they are square/portrait)
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Primary && !item.ResolveArgs.ContainsMetaFileByName(PRIMARY_FILE))
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Primary && !item.ResolveArgs.ContainsMetaFileByName(PrimaryFile))
{
var node = doc.SelectSingleNode("//fanart/music/artistthumbs/artistthumb/@url");
path = node != null ? node.Value : null;
if (!string.IsNullOrEmpty(path))
{
Logger.Debug("FanArtProvider getting Primary image for " + item.Name);
item.SetImage(ImageType.Primary, await _providerManager.DownloadAndSaveImage(item, path, PRIMARY_FILE, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
item.SetImage(ImageType.Primary, await _providerManager.DownloadAndSaveImage(item, path, PrimaryFile, SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
}

View File

@ -96,7 +96,7 @@ namespace MediaBrowser.Controller.Providers.TV
var series = (Series)item;
string language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
string url = string.Format(FanArtBaseUrl, APIKey, series.GetProviderId(MetadataProviders.Tvdb));
string url = string.Format(FanArtBaseUrl, ApiKey, series.GetProviderId(MetadataProviders.Tvdb));
var doc = new XmlDocument();
using (var xml = await HttpClient.Get(new HttpRequestOptions
@ -117,7 +117,7 @@ namespace MediaBrowser.Controller.Providers.TV
{
string path;
var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hdtv" : "clear";
if (ConfigurationManager.Configuration.DownloadSeriesImages.Logo && !series.ResolveArgs.ContainsMetaFileByName(LOGO_FILE))
if (ConfigurationManager.Configuration.DownloadSeriesImages.Logo && !series.ResolveArgs.ContainsMetaFileByName(LogoFile))
{
var node = doc.SelectSingleNode("//fanart/series/" + hd + "logos/" + hd + "logo[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/clearlogos/clearlogo[@lang = \"" + language + "\"]/@url") ??
@ -127,14 +127,14 @@ namespace MediaBrowser.Controller.Providers.TV
if (!string.IsNullOrEmpty(path))
{
Logger.Debug("FanArtProvider getting ClearLogo for " + series.Name);
series.SetImage(ImageType.Logo, await _providerManager.DownloadAndSaveImage(series, path, LOGO_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
series.SetImage(ImageType.Logo, await _providerManager.DownloadAndSaveImage(series, path, LogoFile, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
cancellationToken.ThrowIfCancellationRequested();
hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : "";
if (ConfigurationManager.Configuration.DownloadSeriesImages.Art && !series.ResolveArgs.ContainsMetaFileByName(ART_FILE))
if (ConfigurationManager.Configuration.DownloadSeriesImages.Art && !series.ResolveArgs.ContainsMetaFileByName(ArtFile))
{
var node = doc.SelectSingleNode("//fanart/series/" + hd + "cleararts/" + hd + "clearart[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/cleararts/clearart[@lang = \"" + language + "\"]/@url") ??
@ -144,13 +144,13 @@ namespace MediaBrowser.Controller.Providers.TV
if (!string.IsNullOrEmpty(path))
{
Logger.Debug("FanArtProvider getting ClearArt for " + series.Name);
series.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(series, path, ART_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
series.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(series, path, ArtFile, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
cancellationToken.ThrowIfCancellationRequested();
if (ConfigurationManager.Configuration.DownloadSeriesImages.Thumb && !series.ResolveArgs.ContainsMetaFileByName(THUMB_FILE))
if (ConfigurationManager.Configuration.DownloadSeriesImages.Thumb && !series.ResolveArgs.ContainsMetaFileByName(ThumbFile))
{
var node = doc.SelectSingleNode("//fanart/series/tvthumbs/tvthumb[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/tvthumbs/tvthumb/@url");
@ -158,11 +158,11 @@ namespace MediaBrowser.Controller.Providers.TV
if (!string.IsNullOrEmpty(path))
{
Logger.Debug("FanArtProvider getting ThumbArt for " + series.Name);
series.SetImage(ImageType.Thumb, await _providerManager.DownloadAndSaveImage(series, path, THUMB_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
series.SetImage(ImageType.Thumb, await _providerManager.DownloadAndSaveImage(series, path, ThumbFile, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
if (ConfigurationManager.Configuration.DownloadSeriesImages.Banner && !series.ResolveArgs.ContainsMetaFileByName(BANNER_FILE))
if (ConfigurationManager.Configuration.DownloadSeriesImages.Banner && !series.ResolveArgs.ContainsMetaFileByName(BannerFile))
{
var node = doc.SelectSingleNode("//fanart/series/tbbanners/tvbanner[@lang = \"" + language + "\"]/@url") ??
doc.SelectSingleNode("//fanart/series/tbbanners/tvbanner/@url");
@ -170,7 +170,7 @@ namespace MediaBrowser.Controller.Providers.TV
if (!string.IsNullOrEmpty(path))
{
Logger.Debug("FanArtProvider getting banner for " + series.Name);
series.SetImage(ImageType.Banner, await _providerManager.DownloadAndSaveImage(series, path, BANNER_FILE, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
series.SetImage(ImageType.Banner, await _providerManager.DownloadAndSaveImage(series, path, BannerFile, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
}
}

View File

@ -30,7 +30,7 @@ namespace MediaBrowser.Controller.Providers.TV
/// <summary>
/// The tv db
/// </summary>
internal readonly SemaphoreSlim TvDbResourcePool = new SemaphoreSlim(5, 5);
internal readonly SemaphoreSlim TvDbResourcePool = new SemaphoreSlim(3, 3);
internal static RemoteSeriesProvider Current { get; private set; }

View File

@ -186,12 +186,12 @@ namespace MediaBrowser.Server.Implementations.Providers
// Put this check below the await because the needs refresh of the next tier of providers may depend on the previous ones running
// This is the case for the fan art provider which depends on the movie and tv providers having run before them
if (!force && !provider.NeedsRefresh(item))
if (provider.RequiresInternet && item.DontFetchMeta)
{
continue;
}
if (provider.RequiresInternet && item.DontFetchMeta)
if (!force && !provider.NeedsRefresh(item))
{
continue;
}