|
|
|
@ -88,39 +88,17 @@ namespace MediaBrowser.Providers.MediaInfo
|
|
|
|
|
}).OfType<Video>()
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var failHistoryPath = Path.Combine(_config.ApplicationPaths.CachePath, "subtitlehistory.json");
|
|
|
|
|
var history = GetHistory(failHistoryPath);
|
|
|
|
|
|
|
|
|
|
var numComplete = 0;
|
|
|
|
|
|
|
|
|
|
foreach (var video in videos)
|
|
|
|
|
{
|
|
|
|
|
DateTime lastAttempt;
|
|
|
|
|
if (history.TryGetValue(video.Id.ToString("N"), out lastAttempt))
|
|
|
|
|
{
|
|
|
|
|
if ((DateTime.UtcNow - lastAttempt).TotalDays <= 7)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var shouldRetry = await DownloadSubtitles(video, options, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
if (shouldRetry)
|
|
|
|
|
{
|
|
|
|
|
history[video.Id.ToString("N")] = DateTime.UtcNow;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
history.Remove(video.Id.ToString("N"));
|
|
|
|
|
}
|
|
|
|
|
await DownloadSubtitles(video, options, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error downloading subtitles for {0}", ex, video.Path);
|
|
|
|
|
history[video.Id.ToString("N")] = DateTime.UtcNow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update progress
|
|
|
|
@ -130,26 +108,6 @@ namespace MediaBrowser.Providers.MediaInfo
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|