public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(
            SeriesInfo info, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"[DOUBAN FRODO INFO] Searching \"{info.Name}\"");

            var results = new List <RemoteSearchResult>();

            var searchResults = new List <Response.SearchTarget>();

            string sid = info.GetProviderId(ProviderID);

            if (!string.IsNullOrEmpty(sid))
            {
                searchResults.Add(FrodoUtils.MapSubjectToSearchTarget(await GetFrodoSubject(sid, "tv", cancellationToken)));
            }
            else
            {
                searchResults = await SearchFrodoByName(info.Name, "tv", cancellationToken).
                                ConfigureAwait(false);
            }

            foreach (Response.SearchTarget searchTarget in searchResults)
            {
                var searchResult = new RemoteSearchResult()
                {
                    Name           = searchTarget?.Title,
                    ImageUrl       = searchTarget?.Cover_Url,
                    ProductionYear = int.Parse(searchTarget?.Year)
                };
                searchResult.SetProviderId(ProviderID, searchTarget.Id);
                results.Add(searchResult);
            }

            return(results);
        }
示例#2
0
        protected async Task <MetadataResult <T> > GetMetaFromFrodo <T>(string sid,
                                                                        string type, CancellationToken cancellationToken)
            where T : BaseItem, new()
        {
            var result = new MetadataResult <T>();

            var subject = await GetFrodoSubject(sid, type, cancellationToken);

            result.Item = FrodoUtils.MapSubjectToItem <T>(subject);
            result.Item.SetProviderId(ProviderID, sid);
            FrodoUtils.MapCrewToPersons(subject.Directors, PersonType.Director).ForEach(result.AddPerson);
            FrodoUtils.MapCrewToPersons(subject.Actors, PersonType.Actor).ForEach(result.AddPerson);

            result.QueriedById = true;
            result.HasMetadata = true;


            return(result);
        }
示例#3
0
        public async Task <string> RequestFrodo(string api, Dictionary <string, string> queryParams, CancellationToken cancellationToken)
        {
            string ts  = FrodoUtils.GetTsParam();
            string sig = FrodoUtils.GetSigParam(api, ts);

            queryParams.Add("_ts", ts);
            queryParams.Add("_sig", sig);
            queryParams.Add("apikey", FrodoUtils.ApiKey);

            string query = FrodoUtils.FormatQueryString(queryParams);
            string url   = $"{FrodoUtils.BaseDoubanUrl}{api}{query}";

            var options = new HttpRequestOptions
            {
                Url = url,
                CancellationToken = cancellationToken,
                BufferContent     = true,
                UserAgent         = FrodoUtils.UserAgent,
            };

            try
            {
                _logger.LogInformation($"[DOUBAN FRODO INFO] Requesting {url}");

                using var response = await _httpClient.GetResponse(options).ConfigureAwait(false);

                using var reader = new StreamReader(response.Content);
                string content = reader.ReadToEnd();

                _logger.LogInformation($"[DOUBAN FRODO INFO] Request successfully!");
                return(content);
            }
            catch (Exception e)
            {
                _logger.LogError($"[DOUBAN FRODO ERR] Request failed, {e.Message}");
                throw e;
            }
        }