diff --git a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNet.cs b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNet.cs index 61b994c4e..f84051457 100644 --- a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNet.cs +++ b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNet.cs @@ -1,4 +1,5 @@ -using NLog; +using System; +using NLog; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.Localization; @@ -14,6 +15,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet public override bool SupportsRss => true; public override bool SupportsSearch => true; public override int PageSize => 100; + public override TimeSpan RateLimit => TimeSpan.FromSeconds(5); public BroadcastheNet(IHttpClient httpClient, IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, Logger logger, ILocalizationService localizationService) : base(httpClient, indexerStatusService, configService, parsingService, logger, localizationService) @@ -22,15 +24,13 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet public override IIndexerRequestGenerator GetRequestGenerator() { - var requestGenerator = new BroadcastheNetRequestGenerator() { Settings = Settings, PageSize = PageSize }; + var requestGenerator = new BroadcastheNetRequestGenerator { Settings = Settings, PageSize = PageSize }; var releaseInfo = _indexerStatusService.GetLastRssSyncReleaseInfo(Definition.Id); - if (releaseInfo != null) + + if (releaseInfo != null && int.TryParse(releaseInfo.Guid.Replace("BTN-", string.Empty), out var torrentId)) { - if (int.TryParse(releaseInfo.Guid.Replace("BTN-", string.Empty), out var torrentId)) - { - requestGenerator.LastRecentTorrentID = torrentId; - } + requestGenerator.LastRecentTorrentId = torrentId; } return requestGenerator; diff --git a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetParser.cs b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetParser.cs index f135a9db6..0849d9625 100644 --- a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetParser.cs +++ b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetParser.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Net; using System.Text.RegularExpressions; +using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Core.Indexers.Exceptions; using NzbDrone.Core.Parser.Model; @@ -10,13 +11,14 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet { public class BroadcastheNetParser : IParseIndexerResponse { - private static readonly Regex RegexProtocol = new Regex("^https?:", RegexOptions.Compiled); + private static readonly Regex RegexProtocol = new ("^https?:", RegexOptions.Compiled); public IList ParseResponse(IndexerResponse indexerResponse) { var results = new List(); + var indexerHttpResponse = indexerResponse.HttpResponse; - switch (indexerResponse.HttpResponse.StatusCode) + switch (indexerHttpResponse.StatusCode) { case HttpStatusCode.Unauthorized: throw new ApiKeyException("API Key invalid or not authorized"); @@ -25,25 +27,30 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet case HttpStatusCode.ServiceUnavailable: throw new RequestLimitReachedException("Cannot do more than 150 API requests per hour."); default: - if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK) + if (indexerHttpResponse.StatusCode != HttpStatusCode.OK) { - throw new IndexerException(indexerResponse, "Indexer API call returned an unexpected StatusCode [{0}]", indexerResponse.HttpResponse.StatusCode); + throw new IndexerException(indexerResponse, "Indexer API call returned an unexpected StatusCode [{0}]", indexerHttpResponse.StatusCode); } break; } - if (indexerResponse.HttpResponse.Headers.ContentType != null && indexerResponse.HttpResponse.Headers.ContentType.Contains("text/html")) + if (indexerHttpResponse.Headers.ContentType != null && indexerHttpResponse.Headers.ContentType.Contains("text/html")) { throw new IndexerException(indexerResponse, "Indexer responded with html content. Site is likely blocked or unavailable."); } + if (indexerResponse.Content.ContainsIgnoreCase("Call Limit Exceeded")) + { + throw new RequestLimitReachedException("Cannot do more than 150 API requests per hour."); + } + if (indexerResponse.Content == "Query execution was interrupted") { throw new IndexerException(indexerResponse, "Indexer API returned an internal server error"); } - var jsonResponse = new HttpResponse>(indexerResponse.HttpResponse).Resource; + var jsonResponse = new HttpResponse>(indexerHttpResponse).Resource; if (jsonResponse.Error != null || jsonResponse.Result == null) { @@ -59,38 +66,34 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet foreach (var torrent in jsonResponse.Result.Torrents.Values) { - var torrentInfo = new TorrentInfo(); + var torrentInfo = new TorrentInfo + { + Guid = $"BTN-{torrent.TorrentID}", + InfoUrl = $"{protocol}//broadcasthe.net/torrents.php?id={torrent.GroupID}&torrentid={torrent.TorrentID}", + DownloadUrl = RegexProtocol.Replace(torrent.DownloadURL, protocol), + Title = CleanReleaseName(torrent.ReleaseName), + InfoHash = torrent.InfoHash, + Size = torrent.Size, + Seeders = torrent.Seeders, + Peers = torrent.Leechers + torrent.Seeders, + PublishDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).ToUniversalTime().AddSeconds(torrent.Time), + Origin = torrent.Origin, + Source = torrent.Source, + Container = torrent.Container, + Codec = torrent.Codec, + Resolution = torrent.Resolution + }; - torrentInfo.Guid = string.Format("BTN-{0}", torrent.TorrentID); - torrentInfo.Title = CleanReleaseName(torrent.ReleaseName); - torrentInfo.Size = torrent.Size; - torrentInfo.DownloadUrl = RegexProtocol.Replace(torrent.DownloadURL, protocol); - torrentInfo.InfoUrl = string.Format("{0}//broadcasthe.net/torrents.php?id={1}&torrentid={2}", protocol, torrent.GroupID, torrent.TorrentID); - - // torrentInfo.CommentUrl = - if (torrent.TvdbID.HasValue) + if (torrent.TvdbID is > 0) { torrentInfo.TvdbId = torrent.TvdbID.Value; } - if (torrent.TvrageID.HasValue) + if (torrent.TvrageID is > 0) { torrentInfo.TvRageId = torrent.TvrageID.Value; } - torrentInfo.PublishDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).ToUniversalTime().AddSeconds(torrent.Time); - - // torrentInfo.MagnetUrl = - torrentInfo.InfoHash = torrent.InfoHash; - torrentInfo.Seeders = torrent.Seeders; - torrentInfo.Peers = torrent.Leechers + torrent.Seeders; - - torrentInfo.Origin = torrent.Origin; - torrentInfo.Source = torrent.Source; - torrentInfo.Container = torrent.Container; - torrentInfo.Codec = torrent.Codec; - torrentInfo.Resolution = torrent.Resolution; - results.Add(torrentInfo); } @@ -99,9 +102,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet private string CleanReleaseName(string releaseName) { - releaseName = releaseName.Replace("\\", ""); - - return releaseName; + return releaseName.Replace("\\", ""); } } } diff --git a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetRequestGenerator.cs b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetRequestGenerator.cs index dc887b5a9..b68ea1376 100644 --- a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetRequestGenerator.cs @@ -11,7 +11,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet public int PageSize { get; set; } public BroadcastheNetSettings Settings { get; set; } - public int? LastRecentTorrentID { get; set; } + public int? LastRecentTorrentId { get; set; } public BroadcastheNetRequestGenerator() { @@ -23,15 +23,15 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet { var pageableRequests = new IndexerPageableRequestChain(); - if (LastRecentTorrentID.HasValue) + if (LastRecentTorrentId is > 0) { - pageableRequests.Add(GetPagedRequests(MaxPages, new BroadcastheNetTorrentQuery() + pageableRequests.Add(GetPagedRequests(MaxPages, new BroadcastheNetTorrentQuery { - Id = ">=" + (LastRecentTorrentID.Value - 100) + Id = ">=" + (LastRecentTorrentId.Value - 100) })); } - pageableRequests.AddTier(GetPagedRequests(MaxPages, new BroadcastheNetTorrentQuery() + pageableRequests.AddTier(GetPagedRequests(MaxPages, new BroadcastheNetTorrentQuery { Age = "<=86400" })); @@ -51,7 +51,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet parameters = parameters.Clone(); parameters.Category = "Episode"; - parameters.Name = string.Format("S{0:00}%E{1:00}%", episode.SeasonNumber, episode.EpisodeNumber); + parameters.Name = $"S{episode.SeasonNumber:00}%E{episode.EpisodeNumber:00}%"; pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); } @@ -70,14 +70,14 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet foreach (var seasonNumber in searchCriteria.Episodes.Select(v => v.SeasonNumber).Distinct()) { parameters.Category = "Season"; - parameters.Name = string.Format("Season {0}%", seasonNumber); + parameters.Name = $"Season {seasonNumber}%"; pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); parameters = parameters.Clone(); parameters.Category = "Episode"; - parameters.Name = string.Format("S{0:00}E%", seasonNumber); + parameters.Name = $"S{seasonNumber:00}E%"; pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); } @@ -94,7 +94,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet if (AddSeriesSearchParameters(parameters, searchCriteria)) { parameters.Category = "Episode"; - parameters.Name = string.Format("{0:yyyy}.{0:MM}.{0:dd}", searchCriteria.AirDate); + parameters.Name = searchCriteria.AirDate.ToString("yyyy.MM.dd"); pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); @@ -105,7 +105,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet parameters = parameters.Clone(); parameters.Category = "Episode"; - parameters.Name = string.Format("S{0:00}E{1:00}", episode.SeasonNumber, episode.EpisodeNumber); + parameters.Name = $"S{episode.SeasonNumber:00}E{episode.EpisodeNumber:00}"; pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); } @@ -122,7 +122,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet if (AddSeriesSearchParameters(parameters, searchCriteria)) { parameters.Category = "Episode"; - parameters.Name = string.Format("{0}%", searchCriteria.Year); + parameters.Name = $"{searchCriteria.Year}%"; pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); @@ -133,7 +133,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet parameters = parameters.Clone(); parameters.Category = "Episode"; - parameters.Name = string.Format("S{0:00}E{1:00}", episode.SeasonNumber, episode.EpisodeNumber); + parameters.Name = $"S{episode.SeasonNumber:00}E{episode.EpisodeNumber:00}"; pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); } @@ -154,7 +154,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet parameters = parameters.Clone(); parameters.Category = "Episode"; - parameters.Name = string.Format("S{0:00}E{1:00}", episode.SeasonNumber, episode.EpisodeNumber); + parameters.Name = $"S{episode.SeasonNumber:00}E{episode.EpisodeNumber:00}"; pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); } @@ -164,7 +164,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet parameters = parameters.Clone(); parameters.Category = "Season"; - parameters.Name = string.Format("Season {0}%", seasonNumber); + parameters.Name = $"Season {seasonNumber}%"; pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); } @@ -183,14 +183,14 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet foreach (var seasonNumber in searchCriteria.Episodes.Select(v => v.SeasonNumber).Distinct()) { parameters.Category = "Season"; - parameters.Name = string.Format("Season {0}%", seasonNumber); + parameters.Name = $"Season {seasonNumber}%"; pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); parameters = parameters.Clone(); parameters.Category = "Episode"; - parameters.Name = string.Format("S{0:00}E%", seasonNumber); + parameters.Name = $"S{seasonNumber:00}E%"; pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); } @@ -207,15 +207,15 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet if (AddSeriesSearchParameters(parameters, searchCriteria)) { var episodeQueryTitle = searchCriteria.Episodes.Where(e => !string.IsNullOrWhiteSpace(e.Title)) - .Select(e => SearchCriteriaBase.GetCleanSceneTitle(e.Title)) - .ToArray(); + .Select(e => SearchCriteriaBase.GetCleanSceneTitle(e.Title)) + .ToArray(); foreach (var queryTitle in episodeQueryTitle) { parameters = parameters.Clone(); parameters.Category = "Episode"; - parameters.Name = "%" + queryTitle + "%"; + parameters.Name = $"%{queryTitle}%"; pageableRequests.Add(GetPagedRequests(MaxPages, parameters)); } @@ -228,13 +228,13 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet { if (searchCriteria.Series.TvdbId != 0) { - parameters.Tvdb = string.Format("{0}", searchCriteria.Series.TvdbId); + parameters.Tvdb = $"{searchCriteria.Series.TvdbId}"; return true; } if (searchCriteria.Series.TvRageId != 0) { - parameters.Tvrage = string.Format("{0}", searchCriteria.Series.TvRageId); + parameters.Tvrage = $"{searchCriteria.Series.TvRageId}"; return true; } diff --git a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetSettings.cs b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetSettings.cs index 4adf2745b..00c153ceb 100644 --- a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetSettings.cs +++ b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetSettings.cs @@ -17,7 +17,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet public class BroadcastheNetSettings : ITorrentIndexerSettings { - private static readonly BroadcastheNetSettingsValidator Validator = new BroadcastheNetSettingsValidator(); + private static readonly BroadcastheNetSettingsValidator Validator = new (); public BroadcastheNetSettings() { @@ -35,7 +35,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet public int MinimumSeeders { get; set; } [FieldDefinition(3)] - public SeedCriteriaSettings SeedCriteria { get; set; } = new SeedCriteriaSettings(); + public SeedCriteriaSettings SeedCriteria { get; set; } = new (); [FieldDefinition(4, Type = FieldType.Checkbox, Label = "Reject Blocklisted Torrent Hashes While Grabbing", HelpText = "If a torrent is blocked by hash it may not properly be rejected during RSS/Search for some indexers, enabling this will allow it to be rejected after the torrent is grabbed, but before it is sent to the client.", Advanced = true)] public bool RejectBlocklistedTorrentHashesWhileGrabbing { get; set; } diff --git a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetTorrent.cs b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetTorrent.cs index fd33c3bac..86bab0231 100644 --- a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetTorrent.cs +++ b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetTorrent.cs @@ -1,4 +1,4 @@ -namespace NzbDrone.Core.Indexers.BroadcastheNet +namespace NzbDrone.Core.Indexers.BroadcastheNet { public class BroadcastheNetTorrent { diff --git a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetTorrentQuery.cs b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetTorrentQuery.cs index 1180f9b63..370694101 100644 --- a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetTorrentQuery.cs +++ b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetTorrentQuery.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using System.Collections.Generic; +using Newtonsoft.Json; namespace NzbDrone.Core.Indexers.BroadcastheNet { @@ -13,15 +14,15 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string Search { get; set; } [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] - public string Codec { get; set; } + public IEnumerable Codec { get; set; } [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] - public string Container { get; set; } + public IEnumerable Container { get; set; } [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] - public string Source { get; set; } + public IEnumerable Source { get; set; } [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] - public string Resolution { get; set; } + public IEnumerable Resolution { get; set; } [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] - public string Origin { get; set; } + public IEnumerable Origin { get; set; } [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string Hash { get; set; } [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] diff --git a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetTorrents.cs b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetTorrents.cs index f9329e7ea..3c2e9d30d 100644 --- a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetTorrents.cs +++ b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetTorrents.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; namespace NzbDrone.Core.Indexers.BroadcastheNet {