Beispiel #1
0
        private IEnumerable <IndexerRequest> GetRequest(string term, int[] categories, string imdbId = null, int?tmdbId = null, int?tvdbId = null)
        {
            var requestBuilder = new HttpRequestBuilder(Settings.BaseUrl)
                                 .Resource("/pubapi_v2.php")
                                 .Accept(HttpAccept.Json);

            if (Settings.CaptchaToken.IsNotNullOrWhiteSpace())
            {
                requestBuilder.UseSimplifiedUserAgent = true;
                requestBuilder.SetCookie("cf_clearance", Settings.CaptchaToken);
            }

            requestBuilder.AddQueryParam("mode", "search");

            if (imdbId.IsNotNullOrWhiteSpace())
            {
                requestBuilder.AddQueryParam("search_imdb", imdbId);
            }
            else if (tmdbId.HasValue && tmdbId > 0)
            {
                requestBuilder.AddQueryParam("search_themoviedb", tmdbId);
            }
            else if (tvdbId.HasValue && tmdbId > 0)
            {
                requestBuilder.AddQueryParam("search_tvdb", tvdbId);
            }

            if (term.IsNotNullOrWhiteSpace())
            {
                requestBuilder.AddQueryParam("search_string", $"{term}");
            }

            if (!Settings.RankedOnly)
            {
                requestBuilder.AddQueryParam("ranked", "0");
            }

            var cats = Categories.MapTorznabCapsToTrackers(categories);

            if (cats != null && cats.Count > 0)
            {
                var categoryParam = string.Join(";", cats.Distinct());
                requestBuilder.AddQueryParam("category", categoryParam);
            }

            requestBuilder.AddQueryParam("limit", "100");
            requestBuilder.AddQueryParam("token", _tokenProvider.GetToken(Settings, Settings.BaseUrl));
            requestBuilder.AddQueryParam("format", "json_extended");
            requestBuilder.AddQueryParam("app_id", BuildInfo.AppName);

            yield return(new IndexerRequest(requestBuilder.Build()));
        }