restore changes

This commit is contained in:
Luke Pulverenti 2015-11-20 22:13:03 -05:00
parent c379ebed06
commit be1dad4a32
2 changed files with 50 additions and 14 deletions

View File

@ -130,7 +130,7 @@ namespace MediaBrowser.Providers.Manager
{
if (!IsEnabled(savedOptions, imageType, item)) continue;
if (!item.HasImage(imageType) || (refreshOptions.IsReplacingImage(imageType) && !downloadedImages.Contains(imageType)))
if (!HasImage(item, imageType) || (refreshOptions.IsReplacingImage(imageType) && !downloadedImages.Contains(imageType)))
{
_logger.Debug("Running {0} for {1}", provider.GetType().Name, item.Path ?? item.Name);
@ -199,6 +199,14 @@ namespace MediaBrowser.Providers.Manager
ImageType.Thumb
};
private bool HasImage(IHasImages item, ImageType type)
{
var image = item.GetImageInfo(type, 0);
// if it's a placeholder image then pretend like it's not there so that we can replace it
return image != null && !image.IsPlaceholder;
}
/// <summary>
/// Determines if an item already contains the given images
/// </summary>
@ -210,7 +218,7 @@ namespace MediaBrowser.Providers.Manager
/// <returns><c>true</c> if the specified item contains images; otherwise, <c>false</c>.</returns>
private bool ContainsImages(IHasImages item, List<ImageType> images, MetadataOptions savedOptions, int backdropLimit, int screenshotLimit)
{
if (_singularImages.Any(i => images.Contains(i) && !item.HasImage(i) && savedOptions.GetLimit(i) > 0))
if (_singularImages.Any(i => images.Contains(i) && !HasImage(item, i) && savedOptions.GetLimit(i) > 0))
{
return false;
}
@ -282,7 +290,7 @@ namespace MediaBrowser.Providers.Manager
{
if (!IsEnabled(savedOptions, imageType, item)) continue;
if (!item.HasImage(imageType) || (refreshOptions.IsReplacingImage(imageType) && !downloadedImages.Contains(imageType)))
if (!HasImage(item, imageType) || (refreshOptions.IsReplacingImage(imageType) && !downloadedImages.Contains(imageType)))
{
minWidth = savedOptions.GetMinWidth(imageType);
var downloaded = await DownloadImage(item, provider, result, list, minWidth, imageType, cancellationToken).ConfigureAwait(false);
@ -613,4 +621,4 @@ namespace MediaBrowser.Providers.Manager
}
}
}
}
}

View File

@ -82,7 +82,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
UserAgent = UserAgent,
CancellationToken = cancellationToken,
// The data can be large so give it some extra time
TimeoutMs = 120000,
TimeoutMs = 60000,
LogErrorResponseBody = true
};
@ -114,7 +114,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
var requestString = _jsonSerializer.SerializeToString(requestList);
_logger.Debug("Request string for schedules is: " + requestString);
httpOptions.RequestContent = requestString;
using (var response = await _httpClient.Post(httpOptions))
using (var response = await Post(httpOptions).ConfigureAwait(false))
{
StreamReader reader = new StreamReader(response.Content);
string responseString = reader.ReadToEnd();
@ -138,7 +138,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
var requestBody = "[\"" + string.Join("\", \"", programsID) + "\"]";
httpOptions.RequestContent = requestBody;
using (var innerResponse = await _httpClient.Post(httpOptions))
using (var innerResponse = await Post(httpOptions).ConfigureAwait(false))
{
StreamReader innerReader = new StreamReader(innerResponse.Content);
responseString = innerReader.ReadToEnd();
@ -222,12 +222,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
Url = ApiUrl + "/lineups/" + info.ListingsId,
UserAgent = UserAgent,
CancellationToken = cancellationToken,
LogErrorResponseBody = true
LogErrorResponseBody = true,
// The data can be large so give it some extra time
TimeoutMs = 60000
};
httpOptions.RequestHeaders["token"] = token;
using (var response = await _httpClient.Get(httpOptions))
using (var response = await Get(httpOptions).ConfigureAwait(false))
{
var root = _jsonSerializer.DeserializeFromStream<ScheduleDirect.Channel>(response);
_logger.Info("Found " + root.map.Count() + " channels on the lineup on ScheduleDirect");
@ -470,7 +472,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
TimeoutMs = 60000
};
List<ScheduleDirect.ShowImages> images;
using (var innerResponse2 = await _httpClient.Post(httpOptions))
using (var innerResponse2 = await Post(httpOptions).ConfigureAwait(false))
{
images = _jsonSerializer.DeserializeFromStream<List<ScheduleDirect.ShowImages>>(
innerResponse2.Content);
@ -502,7 +504,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
try
{
using (Stream responce = await _httpClient.Get(options).ConfigureAwait(false))
using (Stream responce = await Get(options).ConfigureAwait(false))
{
var root = _jsonSerializer.DeserializeFromStream<List<ScheduleDirect.Headends>>(responce);
@ -571,7 +573,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
if (long.TryParse(savedToken.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out ticks))
{
// If it's under 24 hours old we can still use it
if ((DateTime.UtcNow.Ticks - ticks) < TimeSpan.FromHours(24).Ticks)
if ((DateTime.UtcNow.Ticks - ticks) < TimeSpan.FromHours(20).Ticks)
{
return savedToken.Name;
}
@ -604,6 +606,32 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
}
}
private async Task<HttpResponseInfo> Post(HttpRequestOptions options)
{
try
{
return await _httpClient.Post(options).ConfigureAwait(false);
}
catch
{
_tokens.Clear();
throw;
}
}
private async Task<Stream> Get(HttpRequestOptions options)
{
try
{
return await _httpClient.Get(options).ConfigureAwait(false);
}
catch
{
_tokens.Clear();
throw;
}
}
private async Task<string> GetTokenInternal(string username, string password,
CancellationToken cancellationToken)
{
@ -618,7 +646,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
//_logger.Info("Obtaining token from Schedules Direct from addres: " + httpOptions.Url + " with body " +
// httpOptions.RequestContent);
using (var responce = await _httpClient.Post(httpOptions))
using (var responce = await Post(httpOptions).ConfigureAwait(false))
{
var root = _jsonSerializer.DeserializeFromStream<ScheduleDirect.Token>(responce.Content);
if (root.message == "OK")
@ -700,7 +728,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
try
{
using (var response = await _httpClient.Get(options).ConfigureAwait(false))
using (var response = await Get(options).ConfigureAwait(false))
{
var root = _jsonSerializer.DeserializeFromStream<ScheduleDirect.Lineups>(response);