Example #1
0
        public OmdbProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient)
        {
            _jsonSerializer = jsonSerializer;
            _httpClient = httpClient;

            Current = this;
        }
Example #2
0
        public OmdbProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient)
        {
            _jsonSerializer = jsonSerializer;
            _httpClient     = httpClient;

            Current = this;
        }
Example #3
0
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken)
        {
            var imdbId = item.GetProviderId(MetadataProviders.Imdb);

            var list = new List <RemoteImageInfo>();

            var provider = new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _appHost, _configurationManager);

            if (!string.IsNullOrWhiteSpace(imdbId))
            {
                OmdbProvider.RootObject rootObject = await provider.GetRootObject(imdbId, cancellationToken).ConfigureAwait(false);

                if (!string.IsNullOrEmpty(rootObject.Poster))
                {
                    if (item is Episode)
                    {
                        // img.omdbapi.com is returning 404's
                        list.Add(new RemoteImageInfo
                        {
                            ProviderName = Name,
                            Url          = rootObject.Poster
                        });
                    }
                    else
                    {
                        list.Add(new RemoteImageInfo
                        {
                            ProviderName = Name,
                            Url          = string.Format("https://img.omdbapi.com/?i={0}&apikey=fe53f97e", imdbId)
                        });
                    }
                }
            }

            return(list);
        }
Example #4
0
        public async Task<IEnumerable<RemoteImageInfo>> GetImages(IHasImages item, CancellationToken cancellationToken)
        {
            var imdbId = item.GetProviderId(MetadataProviders.Imdb);

            var list = new List<RemoteImageInfo>();

            var provider = new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _configurationManager);

            if (!string.IsNullOrWhiteSpace(imdbId))
            {
                OmdbProvider.RootObject rootObject = await provider.GetRootObject(imdbId, cancellationToken).ConfigureAwait(false);

                if (!string.IsNullOrEmpty(rootObject.Poster))
                {
                    list.Add(new RemoteImageInfo
                    {
                        ProviderName = Name,
                        Url = string.Format("https://img.omdbapi.com/?i={0}&apikey=82e83907", imdbId)
                    });
                }
            }

            return list;
        }
Example #5
0
        private async Task <IEnumerable <RemoteSearchResult> > GetSearchResultsInternal(ItemLookupInfo searchInfo, string type, bool isSearch, CancellationToken cancellationToken)
        {
            var episodeSearchInfo = searchInfo as EpisodeInfo;

            var imdbId = searchInfo.GetProviderId(MetadataProviders.Imdb);

            var urlQuery = "plot=full&r=json";

            if (type == "episode" && episodeSearchInfo != null)
            {
                episodeSearchInfo.SeriesProviderIds.TryGetValue(MetadataProviders.Imdb.ToString(), out imdbId);
            }

            var name = searchInfo.Name;
            var year = searchInfo.Year;

            if (!string.IsNullOrWhiteSpace(name))
            {
                var parsedName = _libraryManager.ParseName(name);
                var yearInName = parsedName.Year;
                name = parsedName.Name;
                year = year ?? yearInName;
            }

            if (string.IsNullOrWhiteSpace(imdbId))
            {
                if (year.HasValue)
                {
                    urlQuery += "&y=" + year.Value.ToString(CultureInfo.InvariantCulture);
                }

                // &s means search and returns a list of results as opposed to t
                if (isSearch)
                {
                    urlQuery += "&s=" + WebUtility.UrlEncode(name);
                }
                else
                {
                    urlQuery += "&t=" + WebUtility.UrlEncode(name);
                }
                urlQuery += "&type=" + type;
            }
            else
            {
                urlQuery += "&i=" + imdbId;
                isSearch  = false;
            }

            if (type == "episode")
            {
                if (searchInfo.IndexNumber.HasValue)
                {
                    urlQuery += string.Format(CultureInfo.InvariantCulture, "&Episode={0}", searchInfo.IndexNumber);
                }
                if (searchInfo.ParentIndexNumber.HasValue)
                {
                    urlQuery += string.Format(CultureInfo.InvariantCulture, "&Season={0}", searchInfo.ParentIndexNumber);
                }
            }

            var url = OmdbProvider.GetOmdbUrl(urlQuery, cancellationToken);

            using (var response = await OmdbProvider.GetOmdbResponse(_httpClient, url, cancellationToken).ConfigureAwait(false))
            {
                using (var stream = response.Content)
                {
                    var resultList = new List <SearchResult>();

                    if (isSearch)
                    {
                        var searchResultList = _jsonSerializer.DeserializeFromStream <SearchResultList>(stream);
                        if (searchResultList != null && searchResultList.Search != null)
                        {
                            resultList.AddRange(searchResultList.Search);
                        }
                    }
                    else
                    {
                        var result = _jsonSerializer.DeserializeFromStream <SearchResult>(stream);
                        if (string.Equals(result.Response, "true", StringComparison.OrdinalIgnoreCase))
                        {
                            resultList.Add(result);
                        }
                    }

                    return(resultList.Select(result =>
                    {
                        var item = new RemoteSearchResult
                        {
                            IndexNumber = searchInfo.IndexNumber,
                            Name = result.Title,
                            ParentIndexNumber = searchInfo.ParentIndexNumber,
                            SearchProviderName = Name
                        };

                        if (episodeSearchInfo != null && episodeSearchInfo.IndexNumberEnd.HasValue)
                        {
                            item.IndexNumberEnd = episodeSearchInfo.IndexNumberEnd.Value;
                        }

                        item.SetProviderId(MetadataProviders.Imdb, result.imdbID);

                        int parsedYear;
                        if (result.Year.Length > 0 &&
                            int.TryParse(result.Year.Substring(0, Math.Min(result.Year.Length, 4)), NumberStyles.Any, CultureInfo.InvariantCulture, out parsedYear))
                        {
                            item.ProductionYear = parsedYear;
                        }

                        DateTime released;
                        if (!string.IsNullOrEmpty(result.Released) &&
                            DateTime.TryParse(result.Released, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out released))
                        {
                            item.PremiereDate = released;
                        }

                        if (!string.IsNullOrWhiteSpace(result.Poster) && !string.Equals(result.Poster, "N/A", StringComparison.OrdinalIgnoreCase))
                        {
                            item.ImageUrl = result.Poster;
                        }

                        return item;
                    }));
                }
            }
        }