Example #1
0
        public async Task Execute(CancellationToken cancellationToken, IProgress <double> progress)
        {
            await Task.Yield();

            progress?.Report(0);

            var items = this.libraryManager.GetItemList(new InternalItemsQuery()).Where(o => o.ProviderIds.ContainsKey(Plugin.Instance.Name)).ToList();

            foreach (var(idx, item) in items.WithIndex())
            {
                progress?.Report((double)idx / items.Count * 100);

                if (item.Genres != null && item.Genres.Any())
                {
                    var genres = Genres.Cleanup(item.Genres, item.Name);

                    if (!item.Genres.SequenceEqual(genres, StringComparer.Ordinal))
                    {
                        Logger.Debug($"Genres cleaned in \"{item.Name}\"");
                        item.Genres = genres;

#if __EMBY__
                        this.libraryManager.UpdateItem(item, item, ItemUpdateType.MetadataEdit);
#else
                        await this.libraryManager.UpdateItemAsync(item, item, ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false);
#endif
                    }
                }
            }

            progress?.Report(100);
        }
Example #2
0
        public async Task <MetadataResult <Movie> > GetMetadata(MovieInfo info, CancellationToken cancellationToken)
        {
            var result = new MetadataResult <Movie>
            {
                HasMetadata = false,
                Item        = new Movie(),
            };

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

            DateTime?premiereDateObj = null;

            if (info.PremiereDate.HasValue)
            {
#if __EMBY__
                premiereDateObj = info.PremiereDate.Value.DateTime;
#else
                premiereDateObj = info.PremiereDate.Value;
#endif
            }

            string[] curID   = null;
            var      sceneID = info.ProviderIds;
            if (sceneID.TryGetValue(this.Name, out var externalID))
            {
                curID = externalID.Split('#');
            }

            if ((!sceneID.ContainsKey(this.Name) || curID == null || curID.Length < 3) && !Plugin.Instance.Configuration.DisableAutoIdentify)
            {
                var searchResults = await this.GetSearchResults(info, cancellationToken).ConfigureAwait(false);

                if (searchResults.Any())
                {
                    var first = searchResults.First();

                    sceneID = first.ProviderIds;

                    sceneID.TryGetValue(this.Name, out externalID);
                    curID = externalID.Split('#');

                    if (first.PremiereDate.HasValue)
                    {
#if __EMBY__
                        premiereDateObj = first.PremiereDate.Value.DateTime;
#else
                        premiereDateObj = first.PremiereDate.Value;
#endif
                    }
                }
            }

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

            var siteNum = new int[2] {
                int.Parse(curID[0], CultureInfo.InvariantCulture), int.Parse(curID[1], CultureInfo.InvariantCulture)
            };

            var provider = Helper.GetProviderBySiteID(siteNum[0]);
            if (provider != null)
            {
                Logger.Info($"PhoenixAdult ID: {externalID}");

                try
                {
                    result = await provider.Update(siteNum, curID.Skip(2).ToArray(), cancellationToken).ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    Logger.Error($"Update error: \"{e}\"");

                    await Analitycs.Send(string.Join("#", curID.Skip(2)), siteNum, Helper.GetSearchSiteName(siteNum), info.Name, premiereDateObj, provider.ToString(), e, cancellationToken).ConfigureAwait(false);
                }

                if (!string.IsNullOrEmpty(result.Item.Name))
                {
                    result.HasMetadata         = true;
                    result.Item.OfficialRating = "XXX";
                    result.Item.ProviderIds.Update(this.Name, sceneID[this.Name]);

                    result.Item.Name = HttpUtility.HtmlDecode(result.Item.Name).Trim();

                    if (!string.IsNullOrEmpty(result.Item.Overview))
                    {
                        result.Item.Overview = HttpUtility.HtmlDecode(result.Item.Overview).Trim();
                    }

                    var newStudios = new List <string>();
                    foreach (var studio in result.Item.Studios)
                    {
                        var studioName = studio.Trim();
                        studioName = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(studioName);

                        if (!newStudios.Contains(studioName))
                        {
                            newStudios.Add(studioName);
                        }
                    }

                    result.Item.Studios = newStudios.ToArray();

                    if (!result.Item.PremiereDate.HasValue)
                    {
                        result.Item.PremiereDate = premiereDateObj;
                    }

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

                    if (result.People != null && result.People.Any())
                    {
                        result.People = Actors.Cleanup(result);
                    }

                    if (result.Item.Genres != null && result.Item.Genres.Any())
                    {
                        result.Item.Genres = Genres.Cleanup(result.Item.Genres, result.Item.Name, result.People);
                    }

                    if (!string.IsNullOrEmpty(result.Item.ExternalId))
                    {
                        result.Item.ProviderIds.Update(this.Name + "URL", result.Item.ExternalId);
                    }
                }
            }

            return(result);
        }