public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(BoxSetInfo searchInfo, CancellationToken cancellationToken)
        {
            var result = new List <RemoteSearchResult>();

            if (searchInfo == null || string.IsNullOrEmpty(Plugin.Instance.Configuration.MetadataAPIToken))
            {
                return(result);
            }

            var data = await MetadataAPI.SiteSearch(searchInfo.Name, cancellationToken).ConfigureAwait(false);

            if (data == null)
            {
                return(result);
            }

            foreach (var searchResult in data)
            {
                result.Add(new RemoteSearchResult
                {
                    ProviderIds = { { Plugin.Instance.Name, (string)searchResult["id"] } },
                    Name        = (string)searchResult["name"],
                    ImageUrl    = (string)searchResult["poster"],
                });
            }

            return(result);
        }
示例#2
0
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken)
#endif
        {
            IEnumerable <RemoteImageInfo> images = new List <RemoteImageInfo>();

            if (item == null || !item.ProviderIds.TryGetValue(this.Name, out var curID))
            {
                return(images);
            }

            try
            {
                images = await MetadataAPI.PeopleImages(curID, cancellationToken).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                Logger.Error($"GetImages error: \"{e}\"");
            }

            if (images.Any())
            {
                foreach (var image in images)
                {
                    image.ProviderName = Plugin.Instance.Name;
                }
            }

            return(images);
        }
        public async Task <MetadataResult <Person> > GetMetadata(PersonLookupInfo info, CancellationToken cancellationToken)
        {
            var result = new MetadataResult <Person>()
            {
                HasMetadata = false,
                Item        = new Person(),
            };

            if (info == null)
            {
                return(result);
            }

            info.ProviderIds.TryGetValue(this.Name, out var curID);

            if (string.IsNullOrEmpty(curID))
            {
                var searchResults = await this.GetSearchResults(info, cancellationToken).ConfigureAwait(false);

                if (searchResults.Any())
                {
                    searchResults.First().ProviderIds.TryGetValue(this.Name, out curID);
                }
            }

            if (string.IsNullOrEmpty(curID))
            {
                return(result);
            }

            try
            {
                result = await MetadataAPI.PeopleUpdate(curID, cancellationToken).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                Logger.Error($"Actor Update error: \"{e}\"");
            }

            if (result.HasMetadata)
            {
                result.Item.ProviderIds.Add(Plugin.Instance.Name, curID);

                if (result.Item.PremiereDate.HasValue)
                {
                    result.Item.ProductionYear = result.Item.PremiereDate.Value.Year;
                }
            }

            return(result);
        }
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken)
#endif
        {
            IList <RemoteImageInfo> images = new List <RemoteImageInfo>();

            if (item == null || !item.ProviderIds.TryGetValue(this.Name, out var curID))
            {
                return(images);
            }

            JObject siteData = null;

            try
            {
                siteData = await MetadataAPI.SiteUpdate(int.Parse(curID), cancellationToken).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                Logger.Error($"GetImages error: \"{e}\"");
            }

            var imgs = new Dictionary <ImageType, string>();

            if (siteData != null)
            {
                imgs.Add(ImageType.Primary, (string)siteData["poster"]);
                imgs.Add(ImageType.Logo, (string)siteData["logo"]);
                imgs.Add(ImageType.Disc, (string)siteData["favicon"]);
            }

            foreach (var image in imgs)
            {
                if (!string.IsNullOrEmpty(image.Value))
                {
                    var res = new RemoteImageInfo
                    {
                        ProviderName = Plugin.Instance.Name,
                        Url          = image.Value,
                        Type         = image.Key,
                    };

                    images.Add(res);
                }
            }

            return(images);
        }
示例#5
0
        public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken)
        {
            var result = new List <RemoteSearchResult>();

            if (searchInfo == null || string.IsNullOrEmpty(Plugin.Instance.Configuration.MetadataAPIToken))
            {
                return(result);
            }

            var curID = searchInfo.Name.GetAttributeValue("theporndbid");

            if (string.IsNullOrEmpty(curID))
            {
                searchInfo.ProviderIds.TryGetValue(this.Name, out curID);
            }

            if (!string.IsNullOrEmpty(curID))
            {
                var sceneData = new MetadataResult <Movie>()
                {
                    HasMetadata = false,
                    Item        = new Movie(),
                    People      = new List <PersonInfo>(),
                };

                var sceneImages = new List <RemoteImageInfo>();

                try
                {
                    sceneData = await MetadataAPI.SceneUpdate(curID, cancellationToken).ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    Logger.Error($"Update error: \"{e}\"");
                }

                try
                {
                    sceneImages = (List <RemoteImageInfo>) await MetadataAPI.SceneImages(curID, cancellationToken).ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    Logger.Error($"GetImages error: \"{e}\"");
                }

                if (sceneData.HasMetadata)
                {
                    result.Add(new RemoteSearchResult
                    {
                        ProviderIds  = { { Plugin.Instance.Name, curID } },
                        Name         = sceneData.Item.Name,
                        ImageUrl     = sceneImages?.Where(o => o.Type == ImageType.Primary).FirstOrDefault()?.Url,
                        PremiereDate = sceneData.Item.PremiereDate,
                    });

                    return(result);
                }
            }

            if (string.IsNullOrEmpty(searchInfo.Name))
            {
                return(result);
            }

            string searchTitle = searchInfo.Name,
                   oshash      = string.Empty;

#if __EMBY__
#else
            if (!string.IsNullOrEmpty(searchInfo.Path) && Plugin.Instance.Configuration.UseFilePath)
            {
                searchTitle = searchInfo.Path;
            }

            if (!string.IsNullOrEmpty(searchInfo.Path) && Plugin.Instance.Configuration.UseOSHash)
            {
                oshash = OpenSubtitlesHash.ComputeHash(searchInfo.Path);
            }
#endif

            try
            {
                result = await MetadataAPI.SceneSearch(searchTitle, oshash, cancellationToken).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                Logger.Error($"Search error: \"{e}\"");
            }

            if (result.Any())
            {
                foreach (var scene in result)
                {
                    if (scene.PremiereDate.HasValue)
                    {
                        scene.ProductionYear = scene.PremiereDate.Value.Year;
                    }
                }
            }

            return(result);
        }
示例#6
0
        public async Task <MetadataResult <Movie> > GetMetadata(MovieInfo info, CancellationToken cancellationToken)
        {
            var result = new MetadataResult <Movie>()
            {
                HasMetadata = true,
                Item        = new Movie(),
                People      = new List <PersonInfo>(),
            };

            if (Plugin.Instance.Configuration.UseUnmatchedTag && !string.IsNullOrEmpty(Plugin.Instance.Configuration.UnmatchedTag))
            {
                result.Item.Genres = new string[] { Plugin.Instance.Configuration.UnmatchedTag };
            }

            if (info == null)
            {
                return(result);
            }

            info.ProviderIds.TryGetValue(this.Name, out var curID);

            if (string.IsNullOrEmpty(curID))
            {
                var searchResults = await this.GetSearchResults(info, cancellationToken).ConfigureAwait(false);

                if (searchResults.Any())
                {
                    searchResults.First().ProviderIds.TryGetValue(this.Name, out curID);
                }
            }

            if (string.IsNullOrEmpty(curID))
            {
                return(result);
            }

            result.HasMetadata = false;
            try
            {
                result = await MetadataAPI.SceneUpdate(curID, cancellationToken).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                Logger.Error($"Update error: \"{e}\"");
            }

            if (result.HasMetadata)
            {
                result.Item.ProviderIds.Add(Plugin.Instance.Name, curID);
                result.Item.OfficialRating = "XXX";

                if (result.Item.PremiereDate.HasValue)
                {
                    result.Item.ProductionYear = result.Item.PremiereDate.Value.Year;
                }

                if (result.Item.Studios.Any())
                {
                    var studios = new List <string>();

                    foreach (var studioLink in result.Item.Studios)
                    {
                        var studioName = studioLink;
                        if (studioLink.ToLower().Equals(studioLink, StringComparison.Ordinal))
                        {
                            studioName = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(studioLink);
                        }

                        studios.Add(studioName);
                    }

                    result.Item.Studios = studios.Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
                }

                if (result.Item.Genres.Any())
                {
                    var genres = new List <string>();

                    foreach (var genreLink in result.Item.Genres)
                    {
                        var genreName = genreLink;
                        if (genreLink.ToLower().Equals(genreLink, StringComparison.Ordinal))
                        {
                            genreName = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(genreLink);
                        }

                        genres.Add(genreName);
                    }

                    result.Item.Genres = genres.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(o => o).ToArray();
                }

                if (result.People.Any())
                {
                    foreach (var actorLink in result.People)
                    {
                        actorLink.Type = PersonType.Actor;
                    }

                    var people = result.People.Where(o => o.ProviderIds.ContainsKey(this.Name) && !string.IsNullOrEmpty(o.ProviderIds[this.Name]));
                    var other  = result.People.Where(o => !o.ProviderIds.ContainsKey(this.Name) || string.IsNullOrEmpty(o.ProviderIds[this.Name]));

                    result.People = people
                                    .DistinctBy(o => o.ProviderIds[this.Name], StringComparer.OrdinalIgnoreCase)
                                    .OrderBy(o => string.IsNullOrEmpty(o.Role))
                                    .ThenBy(o => o.Role?.Equals("Male", StringComparison.OrdinalIgnoreCase))
                                    .ThenBy(o => o.Name)
                                    .ToList();
                    result.People.AddRange(other.OrderBy(o => o.Name));
                }

                if (Plugin.Instance.Configuration.UseCustomTitle && !string.IsNullOrEmpty(Plugin.Instance.Configuration.CustomTitle))
                {
                    var parameters = new Dictionary <string, object>()
                    {
                        { "{title}", result.Item.Name },
                        { "{studio}", result.Item.Studios.First() },
                        { "{studios}", string.Join(", ", result.Item.Studios) },
                        { "{actors}", string.Join(", ", result.People.Select(o => o.Name)) },
#if __EMBY__
                        { "{release_date}", result.Item.PremiereDate.HasValue ? result.Item.PremiereDate.Value.DateTime.ToString("yyyy-MM-dd") : string.Empty },
#else
                        { "{release_date}", result.Item.PremiereDate.HasValue ? result.Item.PremiereDate.Value.ToString("yyyy-MM-dd") : string.Empty },
#endif
                    };

                    result.Item.Name = parameters.Aggregate(Plugin.Instance.Configuration.CustomTitle, (current, parameter) => current.Replace(parameter.Key, parameter.Value.ToString()));
                    result.Item.Name = string.Join(" ", result.Item.Name.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
                }
            }
            else
            {
                result.HasMetadata = true;
            }

            return(result);
        }
        public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(PersonLookupInfo searchInfo, CancellationToken cancellationToken)
        {
            var result = new List <RemoteSearchResult>();

            if (searchInfo == null)
            {
                return(result);
            }

            if (searchInfo.ProviderIds.TryGetValue(this.Name, out var curID) && !string.IsNullOrEmpty(curID))
            {
                var actorData = new MetadataResult <Person>()
                {
                    HasMetadata = false,
                    Item        = new Person(),
                };

                IEnumerable <RemoteImageInfo> sceneImages = new List <RemoteImageInfo>();

                try
                {
                    actorData = await MetadataAPI.PeopleUpdate(curID, cancellationToken).ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    Logger.Error($"Update error: \"{e}\"");
                }

                try
                {
                    sceneImages = await MetadataAPI.PeopleImages(curID, cancellationToken).ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    Logger.Error($"GetImages error: \"{e}\"");
                }

                if (actorData.HasMetadata)
                {
                    result.Add(new RemoteSearchResult
                    {
                        ProviderIds  = { { Plugin.Instance.Name, curID } },
                        Name         = actorData.Item.ExternalId,
                        ImageUrl     = sceneImages?.Where(o => o.Type == ImageType.Primary).FirstOrDefault()?.Url,
                        PremiereDate = actorData.Item.PremiereDate,
                    });
                }
            }

            if (searchInfo.ProviderIds.Any(o => !string.IsNullOrEmpty(o.Value)))
            {
                return(result);
            }

            try
            {
                result = await MetadataAPI.PeopleSearch(searchInfo.Name, cancellationToken).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                Logger.Error($"Actor Search error: \"{e}\"");
            }

            return(result);
        }