Merge pull request #83 from MBR-0001/limit-handling2

This commit is contained in:
Cody Robibero 2021-11-17 17:13:55 -07:00 committed by GitHub
commit de10383b22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -29,6 +29,7 @@ namespace Jellyfin.Plugin.OpenSubtitles
private readonly ILogger<OpenSubtitleDownloader> _logger;
private LoginInfo? _login;
private DateTime? _limitReset;
private DateTime? _lastRatelimitLog;
private IReadOnlyList<string>? _languages;
private string _customApiKey;
@ -86,6 +87,19 @@ namespace Jellyfin.Plugin.OpenSubtitles
throw new ArgumentNullException(nameof(request));
}
await Login(cancellationToken).ConfigureAwait(false);
if (request.IsAutomated && _login?.User?.RemainingDownloads <= 0)
{
if (_lastRatelimitLog == null || DateTime.UtcNow.Subtract(_lastRatelimitLog.Value).TotalSeconds > 60)
{
_logger.LogInformation("Daily download limit reached, returning no results for automated task");
_lastRatelimitLog = DateTime.UtcNow;
}
return Enumerable.Empty<RemoteSubtitleInfo>();
}
long.TryParse(request.GetProviderId(MetadataProvider.Imdb)?.TrimStart('t') ?? string.Empty, NumberStyles.Any, CultureInfo.InvariantCulture, out var imdbId);
if (request.ContentType == VideoContentType.Episode && (!request.IndexNumber.HasValue || !request.ParentIndexNumber.HasValue || string.IsNullOrEmpty(request.SeriesName)))
@ -100,8 +114,6 @@ namespace Jellyfin.Plugin.OpenSubtitles
return Enumerable.Empty<RemoteSubtitleInfo>();
}
await Login(cancellationToken).ConfigureAwait(false);
var language = await GetLanguage(request.TwoLetterISOLanguageName, cancellationToken).ConfigureAwait(false);
string hash;

View File

@ -26,7 +26,7 @@ This is a plugin allows you to download subtitles from [Open Subtitles](https://
## Build
1. To build this plugin you will need [.Net 5.x](https://dotnet.microsoft.com/download/dotnet/5.0).
1. To build this plugin you will need [.Net 6.x](https://dotnet.microsoft.com/download/dotnet/6.0).
2. Build plugin with following command
```