Use string interpolation for Newznab request generation

This commit is contained in:
Mark McDowall 2022-11-16 19:02:05 -08:00
parent ae306274be
commit ba9651b241
1 changed files with 25 additions and 57 deletions

View File

@ -179,9 +179,7 @@ namespace NzbDrone.Core.Indexers.Newznab
AddTvIdPageableRequests(pageableRequests, AddTvIdPageableRequests(pageableRequests,
Settings.Categories, Settings.Categories,
searchCriteria, searchCriteria,
string.Format("&season={0}&ep={1}", $"&season={NewznabifySeasonNumber(searchCriteria.SeasonNumber)}&ep={searchCriteria.EpisodeNumber}");
NewznabifySeasonNumber(searchCriteria.SeasonNumber),
searchCriteria.EpisodeNumber));
} }
if (searchCriteria.SearchMode.HasFlag(SearchMode.SearchTitle)) if (searchCriteria.SearchMode.HasFlag(SearchMode.SearchTitle))
@ -189,9 +187,7 @@ namespace NzbDrone.Core.Indexers.Newznab
AddTitlePageableRequests(pageableRequests, AddTitlePageableRequests(pageableRequests,
Settings.Categories, Settings.Categories,
searchCriteria, searchCriteria,
string.Format("&season={0}&ep={1}", $"&season={NewznabifySeasonNumber(searchCriteria.SeasonNumber)}&ep={searchCriteria.EpisodeNumber}");
NewznabifySeasonNumber(searchCriteria.SeasonNumber),
searchCriteria.EpisodeNumber));
} }
pageableRequests.AddTier(); pageableRequests.AddTier();
@ -201,9 +197,7 @@ namespace NzbDrone.Core.Indexers.Newznab
AddTitlePageableRequests(pageableRequests, AddTitlePageableRequests(pageableRequests,
Settings.Categories, Settings.Categories,
searchCriteria, searchCriteria,
string.Format("&season={0}&ep={1}", $"&season={NewznabifySeasonNumber(searchCriteria.SeasonNumber)}&ep={searchCriteria.EpisodeNumber}");
NewznabifySeasonNumber(searchCriteria.SeasonNumber),
searchCriteria.EpisodeNumber));
} }
return pageableRequests; return pageableRequests;
@ -223,8 +217,7 @@ namespace NzbDrone.Core.Indexers.Newznab
AddTvIdPageableRequests(pageableRequests, AddTvIdPageableRequests(pageableRequests,
Settings.Categories, Settings.Categories,
searchCriteria, searchCriteria,
string.Format("&season={0}", $"&season={NewznabifySeasonNumber(searchCriteria.SeasonNumber)}");
NewznabifySeasonNumber(searchCriteria.SeasonNumber)));
} }
if (searchCriteria.SearchMode.HasFlag(SearchMode.SearchTitle)) if (searchCriteria.SearchMode.HasFlag(SearchMode.SearchTitle))
@ -232,8 +225,7 @@ namespace NzbDrone.Core.Indexers.Newznab
AddTitlePageableRequests(pageableRequests, AddTitlePageableRequests(pageableRequests,
Settings.Categories, Settings.Categories,
searchCriteria, searchCriteria,
string.Format("&season={0}", $"&season={NewznabifySeasonNumber(searchCriteria.SeasonNumber)}");
NewznabifySeasonNumber(searchCriteria.SeasonNumber)));
} }
pageableRequests.AddTier(); pageableRequests.AddTier();
@ -243,8 +235,7 @@ namespace NzbDrone.Core.Indexers.Newznab
AddTitlePageableRequests(pageableRequests, AddTitlePageableRequests(pageableRequests,
Settings.Categories, Settings.Categories,
searchCriteria, searchCriteria,
string.Format("&season={0}", $"&season={NewznabifySeasonNumber(searchCriteria.SeasonNumber)}");
NewznabifySeasonNumber(searchCriteria.SeasonNumber)));
} }
return pageableRequests; return pageableRequests;
@ -264,8 +255,7 @@ namespace NzbDrone.Core.Indexers.Newznab
AddTvIdPageableRequests(pageableRequests, AddTvIdPageableRequests(pageableRequests,
Settings.Categories, Settings.Categories,
searchCriteria, searchCriteria,
string.Format("&season={0:yyyy}&ep={0:MM}/{0:dd}", $"&season={searchCriteria.AirDate:yyyy}&ep={searchCriteria.AirDate:MM}/{searchCriteria.AirDate:dd}");
searchCriteria.AirDate));
} }
if (searchCriteria.SearchMode.HasFlag(SearchMode.SearchTitle)) if (searchCriteria.SearchMode.HasFlag(SearchMode.SearchTitle))
@ -273,8 +263,7 @@ namespace NzbDrone.Core.Indexers.Newznab
AddTitlePageableRequests(pageableRequests, AddTitlePageableRequests(pageableRequests,
Settings.Categories, Settings.Categories,
searchCriteria, searchCriteria,
string.Format("&season={0:yyyy}&ep={0:MM}/{0:dd}", $"&season={searchCriteria.AirDate:yyyy}&ep={searchCriteria.AirDate:MM}/{searchCriteria.AirDate:dd}");
searchCriteria.AirDate));
} }
pageableRequests.AddTier(); pageableRequests.AddTier();
@ -284,8 +273,7 @@ namespace NzbDrone.Core.Indexers.Newznab
AddTitlePageableRequests(pageableRequests, AddTitlePageableRequests(pageableRequests,
Settings.Categories, Settings.Categories,
searchCriteria, searchCriteria,
string.Format("&season={0:yyyy}&ep={0:MM}/{0:dd}", $"&season={searchCriteria.AirDate:yyyy}&ep={searchCriteria.AirDate:MM}/{searchCriteria.AirDate:dd}");
searchCriteria.AirDate));
} }
return pageableRequests; return pageableRequests;
@ -305,8 +293,7 @@ namespace NzbDrone.Core.Indexers.Newznab
AddTvIdPageableRequests(pageableRequests, AddTvIdPageableRequests(pageableRequests,
Settings.Categories, Settings.Categories,
searchCriteria, searchCriteria,
string.Format("&season={0}", $"&season={searchCriteria.Year}");
searchCriteria.Year));
} }
if (searchCriteria.SearchMode.HasFlag(SearchMode.SearchTitle)) if (searchCriteria.SearchMode.HasFlag(SearchMode.SearchTitle))
@ -314,8 +301,7 @@ namespace NzbDrone.Core.Indexers.Newznab
AddTitlePageableRequests(pageableRequests, AddTitlePageableRequests(pageableRequests,
Settings.Categories, Settings.Categories,
searchCriteria, searchCriteria,
string.Format("&season={0}", $"&season={searchCriteria.Year}");
searchCriteria.Year));
} }
pageableRequests.AddTier(); pageableRequests.AddTier();
@ -325,8 +311,7 @@ namespace NzbDrone.Core.Indexers.Newznab
AddTitlePageableRequests(pageableRequests, AddTitlePageableRequests(pageableRequests,
Settings.Categories, Settings.Categories,
searchCriteria, searchCriteria,
string.Format("&season={0}", $"&season={searchCriteria.Year}");
searchCriteria.Year));
} }
return pageableRequests; return pageableRequests;
@ -344,19 +329,14 @@ namespace NzbDrone.Core.Indexers.Newznab
pageableRequests.Add(GetPagedRequests(MaxPages, pageableRequests.Add(GetPagedRequests(MaxPages,
Settings.AnimeCategories, Settings.AnimeCategories,
"search", "search",
string.Format("&q={0}+{1:00}", $"&q={NewsnabifyTitle(queryTitle)}+{searchCriteria.AbsoluteEpisodeNumber:00}"));
NewsnabifyTitle(queryTitle),
searchCriteria.AbsoluteEpisodeNumber)));
if (Settings.AnimeStandardFormatSearch && searchCriteria.SeasonNumber > 0 && searchCriteria.EpisodeNumber > 0) if (Settings.AnimeStandardFormatSearch && searchCriteria.SeasonNumber > 0 && searchCriteria.EpisodeNumber > 0)
{ {
pageableRequests.Add(GetPagedRequests(MaxPages, pageableRequests.Add(GetPagedRequests(MaxPages,
Settings.AnimeCategories, Settings.AnimeCategories,
"tvsearch", "tvsearch",
string.Format("&q={0}&season={1}&ep={2}", $"&q={NewsnabifyTitle(queryTitle)}&season={NewznabifySeasonNumber(searchCriteria.SeasonNumber)}&ep={searchCriteria.EpisodeNumber}"));
NewsnabifyTitle(queryTitle),
searchCriteria.SeasonNumber,
searchCriteria.EpisodeNumber)));
} }
} }
} }
@ -378,8 +358,7 @@ namespace NzbDrone.Core.Indexers.Newznab
pageableRequests.Add(GetPagedRequests(MaxPages, pageableRequests.Add(GetPagedRequests(MaxPages,
Settings.Categories.Concat(Settings.AnimeCategories), Settings.Categories.Concat(Settings.AnimeCategories),
"search", "search",
string.Format("&q={0}", $"&q={query}"));
query)));
} }
} }
@ -426,36 +405,28 @@ namespace NzbDrone.Core.Indexers.Newznab
chain.Add(GetPagedRequests(MaxPages, chain.Add(GetPagedRequests(MaxPages,
categories, categories,
"tvsearch", "tvsearch",
string.Format("&tvdbid={0}{1}", $"&tvdbid={searchCriteria.Series.TvdbId}{parameters}"));
searchCriteria.Series.TvdbId,
parameters)));
} }
else if (includeImdbSearch) else if (includeImdbSearch)
{ {
chain.Add(GetPagedRequests(MaxPages, chain.Add(GetPagedRequests(MaxPages,
categories, categories,
"tvsearch", "tvsearch",
string.Format("&imdbid={0}{1}", $"&imdbid={searchCriteria.Series.ImdbId}{parameters}"));
searchCriteria.Series.ImdbId,
parameters)));
} }
else if (includeTvRageSearch) else if (includeTvRageSearch)
{ {
chain.Add(GetPagedRequests(MaxPages, chain.Add(GetPagedRequests(MaxPages,
categories, categories,
"tvsearch", "tvsearch",
string.Format("&rid={0}{1}", $"&rid={searchCriteria.Series.TvRageId}{parameters}"));
searchCriteria.Series.TvRageId,
parameters)));
} }
else if (includeTvMazeSearch) else if (includeTvMazeSearch)
{ {
chain.Add(GetPagedRequests(MaxPages, chain.Add(GetPagedRequests(MaxPages,
categories, categories,
"tvsearch", "tvsearch",
string.Format("&tvmazeid={0}{1}", $"&tvmazeid={searchCriteria.Series.TvMazeId}{parameters}"));
searchCriteria.Series.TvMazeId,
parameters)));
} }
} }
} }
@ -469,9 +440,7 @@ namespace NzbDrone.Core.Indexers.Newznab
chain.Add(GetPagedRequests(MaxPages, chain.Add(GetPagedRequests(MaxPages,
Settings.Categories, Settings.Categories,
"tvsearch", "tvsearch",
string.Format("&title={0}{1}", $"&title={Uri.EscapeDataString(searchTerm)}{parameters}"));
Uri.EscapeDataString(searchTerm),
parameters)));
} }
} }
else if (SupportsTvSearch) else if (SupportsTvSearch)
@ -482,9 +451,7 @@ namespace NzbDrone.Core.Indexers.Newznab
chain.Add(GetPagedRequests(MaxPages, chain.Add(GetPagedRequests(MaxPages,
Settings.Categories, Settings.Categories,
"tvsearch", "tvsearch",
string.Format("&q={0}{1}", $"&q={NewsnabifyTitle(queryTitle)}{parameters}"));
NewsnabifyTitle(queryTitle),
parameters)));
} }
} }
} }
@ -498,7 +465,8 @@ namespace NzbDrone.Core.Indexers.Newznab
var categoriesQuery = string.Join(",", categories.Distinct()); var categoriesQuery = string.Join(",", categories.Distinct());
var baseUrl = string.Format("{0}{1}?t={2}&cat={3}&extended=1{4}", Settings.BaseUrl.TrimEnd('/'), Settings.ApiPath.TrimEnd('/'), searchType, categoriesQuery, Settings.AdditionalParameters); var baseUrl =
$"{Settings.BaseUrl.TrimEnd('/')}{Settings.ApiPath.TrimEnd('/')}?t={searchType}&cat={categoriesQuery}&extended=1{Settings.AdditionalParameters}";
if (Settings.ApiKey.IsNotNullOrWhiteSpace()) if (Settings.ApiKey.IsNotNullOrWhiteSpace())
{ {
@ -507,13 +475,13 @@ namespace NzbDrone.Core.Indexers.Newznab
if (PageSize == 0) if (PageSize == 0)
{ {
yield return new IndexerRequest(string.Format("{0}{1}", baseUrl, parameters), HttpAccept.Rss); yield return new IndexerRequest($"{baseUrl}{parameters}", HttpAccept.Rss);
} }
else else
{ {
for (var page = 0; page < maxPages; page++) for (var page = 0; page < maxPages; page++)
{ {
yield return new IndexerRequest(string.Format("{0}&offset={1}&limit={2}{3}", baseUrl, page * PageSize, PageSize, parameters), HttpAccept.Rss); yield return new IndexerRequest($"{baseUrl}&offset={page * PageSize}&limit={PageSize}{parameters}", HttpAccept.Rss);
} }
} }
} }