remove subtitle history

This commit is contained in:
Luke Pulverenti 2016-10-30 14:37:42 -04:00
parent 1031daa9b0
commit 6d0270db18

View File

@ -88,39 +88,17 @@ namespace MediaBrowser.Providers.MediaInfo
}).OfType<Video>() }).OfType<Video>()
.ToList(); .ToList();
var failHistoryPath = Path.Combine(_config.ApplicationPaths.CachePath, "subtitlehistory.json");
var history = GetHistory(failHistoryPath);
var numComplete = 0; var numComplete = 0;
foreach (var video in videos) foreach (var video in videos)
{ {
DateTime lastAttempt;
if (history.TryGetValue(video.Id.ToString("N"), out lastAttempt))
{
if ((DateTime.UtcNow - lastAttempt).TotalDays <= 7)
{
continue;
}
}
try try
{ {
var shouldRetry = await DownloadSubtitles(video, options, cancellationToken).ConfigureAwait(false); await DownloadSubtitles(video, options, cancellationToken).ConfigureAwait(false);
if (shouldRetry)
{
history[video.Id.ToString("N")] = DateTime.UtcNow;
}
else
{
history.Remove(video.Id.ToString("N"));
}
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.ErrorException("Error downloading subtitles for {0}", ex, video.Path); _logger.ErrorException("Error downloading subtitles for {0}", ex, video.Path);
history[video.Id.ToString("N")] = DateTime.UtcNow;
} }
// Update progress // Update progress
@ -130,26 +108,6 @@ namespace MediaBrowser.Providers.MediaInfo
progress.Report(100 * percent); progress.Report(100 * percent);
} }
_json.SerializeToFile(history, failHistoryPath);
}
private Dictionary<string,DateTime> GetHistory(string path)
{
try
{
var result = _json.DeserializeFromFile<Dictionary<string, DateTime>>(path);
if (result != null)
{
return result;
}
}
catch
{
}
return new Dictionary<string, DateTime>();
} }
private async Task<bool> DownloadSubtitles(Video video, SubtitleOptions options, CancellationToken cancellationToken) private async Task<bool> DownloadSubtitles(Video video, SubtitleOptions options, CancellationToken cancellationToken)