Ejemplo n.º 1
0
        private async Task FillMetadata(ChannelItemInfo item, List<TrailerMetadata> metadataList, CancellationToken cancellationToken)
        {
            var imdbId = item.GetProviderId(MetadataProviders.Imdb);
            TrailerMetadata metadata = null;

            if (!string.IsNullOrWhiteSpace(imdbId))
            {
                metadata = metadataList.FirstOrDefault(i => string.Equals(imdbId, i.GetProviderId(MetadataProviders.Imdb), StringComparison.OrdinalIgnoreCase));
            }

            if (metadata == null)
            {
                var tmdbId = item.GetProviderId(MetadataProviders.Tmdb);

                if (!string.IsNullOrWhiteSpace(tmdbId))
                {
                    metadata = metadataList.FirstOrDefault(i => string.Equals(tmdbId, i.GetProviderId(MetadataProviders.Tmdb), StringComparison.OrdinalIgnoreCase));
                }
            }

            if (metadata == null)
            {
                var searchResults =
                    await _providerManager.GetRemoteSearchResults<Movie, MovieInfo>(new RemoteSearchQuery<MovieInfo>
                    {
                        IncludeDisabledProviders = true,
                        SearchInfo = new MovieInfo
                        {
                            Name = item.Name,
                            Year = item.ProductionYear,
                            ProviderIds = item.ProviderIds
                        }

                    }, cancellationToken).ConfigureAwait(false);

                var result = searchResults.FirstOrDefault();

                if (result != null)
                {
                    metadata = new TrailerMetadata
                    {
                        Name = result.Name,
                        PremiereDate = result.PremiereDate,
                        ProductionYear = result.ProductionYear,
                        ProviderIds = result.ProviderIds
                    };

                    metadataList.Add(metadata);
                }
            }

            if (metadata != null)
            {
                item.Name = metadata.Name ?? item.Name;
                item.ProductionYear = metadata.ProductionYear ?? item.ProductionYear;
                item.PremiereDate = metadata.PremiereDate ?? item.PremiereDate;

                // Merge provider id's
                foreach (var id in metadata.ProviderIds)
                {
                    item.SetProviderId(id.Key, id.Value);
                }
            }
        }
Ejemplo n.º 2
0
        private async Task<ChannelItemInfo> GetTrailerFromUrl(string url, TrailerType type, CancellationToken cancellationToken)
        {
            var html = await EntryPoint.Instance.GetAndCacheResponse(url, TimeSpan.FromDays(14), cancellationToken)
                        .ConfigureAwait(false);

            var document = new HtmlDocument();
            document.LoadHtml(html);

            var titleElement = document.DocumentNode.SelectSingleNode("//title");
            var name = titleElement == null ? string.Empty : (titleElement.InnerText ?? string.Empty);
            name = name.Replace("Movie Trailer", string.Empty, StringComparison.OrdinalIgnoreCase)
                .Replace("Movie-List.com", string.Empty, StringComparison.OrdinalIgnoreCase)
                .Replace("Movie-List", string.Empty, StringComparison.OrdinalIgnoreCase)
                .Replace("|", string.Empty, StringComparison.OrdinalIgnoreCase)
                .Trim();

            var posterElement = document.DocumentNode.SelectSingleNode("//a[@rel='prettyPhoto[posters]']//img");
            if (posterElement == null)
            {
                posterElement = document.DocumentNode.SelectSingleNode("//section[@class='content-box']//img");
            }
            var imageSrc = posterElement == null ? null : posterElement.GetAttributeValue("src", null);

            var links = document.DocumentNode.SelectNodes("//a");
            var linksList = links == null ? new List<HtmlNode>() : links.ToList();

            var info = new ChannelItemInfo
            {
                ContentType = ChannelMediaContentType.MovieExtra,
                ExtraType = ExtraType.Trailer,
                TrailerTypes = new List<TrailerType> { type },
                Id = url,
                MediaType = ChannelMediaType.Video,
                Type = ChannelItemType.Media,
                Name = name,
                ImageUrl = string.IsNullOrWhiteSpace(imageSrc) ? null : (BaseUrl + imageSrc.TrimStart('/')),
                MediaSources = GetMediaInfo(linksList, html),
                DateCreated = DateTime.UtcNow
            };

            // For older trailers just rely on core image providers
            if (TrailerType != TrailerType.ComingSoonToTheaters)
            {
                info.ImageUrl = null;
            }

            var metadataElements = document.DocumentNode.SelectNodes("//*[contains(@class,'cast-meta')]");
            if (metadataElements != null)
            {
                foreach (var elem in metadataElements)
                {
                    FillMetadataFromElement(elem, info);
                }
            }

            var imdbId = GetImdbId(linksList);

            if (!string.IsNullOrWhiteSpace(imdbId))
            {
                info.SetProviderId(MetadataProviders.Imdb, imdbId);
            }

            return info;
        }