mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-15 18:08:53 -07:00
fixes #2588 - OpenSubtitlesDownloader doesn't respect X-Ratelimit-Requests-Remaining
This commit is contained in:
parent
e7706fa8a3
commit
6ff89eab78
@ -25,4 +25,25 @@ namespace MediaBrowser.Common.Extensions
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class RateLimitExceededException : Exception
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="RateLimitExceededException" /> class.
|
||||||
|
/// </summary>
|
||||||
|
public RateLimitExceededException()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="RateLimitExceededException" /> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The message.</param>
|
||||||
|
public RateLimitExceededException(string message)
|
||||||
|
: base(message)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|||||||
|
|
||||||
if ((DateTime.UtcNow - _lastRateLimitException).TotalHours < 1)
|
if ((DateTime.UtcNow - _lastRateLimitException).TotalHours < 1)
|
||||||
{
|
{
|
||||||
throw new Exception("OpenSubtitles rate limit reached");
|
throw new RateLimitExceededException("OpenSubtitles rate limit reached");
|
||||||
}
|
}
|
||||||
|
|
||||||
var resultDownLoad = await OpenSubtitles.DownloadSubtitlesAsync(downloadsList, cancellationToken).ConfigureAwait(false);
|
var resultDownLoad = await OpenSubtitles.DownloadSubtitlesAsync(downloadsList, cancellationToken).ConfigureAwait(false);
|
||||||
@ -144,7 +144,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|||||||
if ((resultDownLoad.Status ?? string.Empty).IndexOf("407", StringComparison.OrdinalIgnoreCase) != -1)
|
if ((resultDownLoad.Status ?? string.Empty).IndexOf("407", StringComparison.OrdinalIgnoreCase) != -1)
|
||||||
{
|
{
|
||||||
_lastRateLimitException = DateTime.UtcNow;
|
_lastRateLimitException = DateTime.UtcNow;
|
||||||
throw new Exception("OpenSubtitles rate limit reached");
|
throw new RateLimitExceededException("OpenSubtitles rate limit reached");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(resultDownLoad is MethodResponseSubtitleDownload))
|
if (!(resultDownLoad is MethodResponseSubtitleDownload))
|
||||||
|
@ -10,6 +10,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using MediaBrowser.Common.Extensions;
|
||||||
|
|
||||||
namespace MediaBrowser.Providers.MediaInfo
|
namespace MediaBrowser.Providers.MediaInfo
|
||||||
{
|
{
|
||||||
@ -139,7 +140,7 @@ namespace MediaBrowser.Providers.MediaInfo
|
|||||||
request.IndexNumberEnd = episode.IndexNumberEnd;
|
request.IndexNumberEnd = episode.IndexNumberEnd;
|
||||||
request.SeriesName = episode.SeriesName;
|
request.SeriesName = episode.SeriesName;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var searchResults = await _subtitleManager.SearchSubtitles(request, cancellationToken).ConfigureAwait(false);
|
var searchResults = await _subtitleManager.SearchSubtitles(request, cancellationToken).ConfigureAwait(false);
|
||||||
@ -154,6 +155,9 @@ namespace MediaBrowser.Providers.MediaInfo
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (RateLimitExceededException)
|
||||||
|
{
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.ErrorException("Error downloading subtitles", ex);
|
_logger.ErrorException("Error downloading subtitles", ex);
|
||||||
|
@ -133,7 +133,8 @@ namespace MediaBrowser.Providers.Subtitles
|
|||||||
{
|
{
|
||||||
//var isText = MediaStream.IsTextFormat(response.Format);
|
//var isText = MediaStream.IsTextFormat(response.Format);
|
||||||
|
|
||||||
using (var fs = _fileSystem.GetFileStream(savePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
|
using (var fs = _fileSystem.GetFileStream(savePath, FileOpenMode.Create, FileAccessMode.Write,
|
||||||
|
FileShareMode.Read, true))
|
||||||
{
|
{
|
||||||
await stream.CopyToAsync(fs).ConfigureAwait(false);
|
await stream.CopyToAsync(fs).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
@ -154,6 +155,10 @@ namespace MediaBrowser.Providers.Subtitles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (RateLimitExceededException)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
EventHelper.FireEventIfNotNull(SubtitleDownloadFailure, this, new SubtitleDownloadFailureEventArgs
|
EventHelper.FireEventIfNotNull(SubtitleDownloadFailure, this, new SubtitleDownloadFailureEventArgs
|
||||||
|
Loading…
Reference in New Issue
Block a user