public override IEnumerable <Game> ImportGames(LibraryImportGamesArgs args)
        {
            var importedGames = new List <Game>();

            InitializeStatuses();
            if (string.IsNullOrEmpty(settings.Settings.AccountAccessCode))
            {
                PlayniteApi.Notifications.Add(new NotificationMessage(
                                                  dbImportMessageId,
                                                  ResourceProvider.GetString("LOCImporter_For_Anilist_NotificationMessageAccessCodeNotConfigured"),
                                                  NotificationType.Error));
            }
            else
            {
                var accountApi = new AnilistAccountClient(PlayniteApi, settings.Settings.AccountAccessCode);
                if (string.IsNullOrEmpty(accountApi.anilistUsername))
                {
                    //Username could not be obtained
                    PlayniteApi.Notifications.Add(new NotificationMessage(
                                                      dbImportMessageId,
                                                      ResourceProvider.GetString("LOCImporter_For_Anilist_NotificationMessageAniListUsernameNotObtained"),
                                                      NotificationType.Error));
                }
                else
                {
                    logger.Info($"AniList username: {accountApi.anilistUsername}");
                    if (settings.Settings.ImportAnimeLibrary == true)
                    {
                        var animeEntries = accountApi.GetEntries("ANIME");
                        logger.Debug($"Found {animeEntries.Count} Anime items");
                        foreach (var entry in animeEntries)
                        {
                            var existingEntry = PlayniteApi.Database.Games.FirstOrDefault(a => a.PluginId == Id && a.GameId == entry.Media.Id.ToString());
                            if (existingEntry != null)
                            {
                                UpdateExistingEntry(entry, existingEntry);
                            }
                            else
                            {
                                importedGames.Add(PlayniteApi.Database.ImportGame(EntryToGameMetadata(entry), this));
                            }
                        }
                    }

                    if (settings.Settings.ImportMangaLibrary == true)
                    {
                        var mangaEntries = accountApi.GetEntries("MANGA");
                        logger.Debug($"Found {mangaEntries.Count} Manga items");
                        foreach (var entry in mangaEntries)
                        {
                            var existingEntry = PlayniteApi.Database.Games.FirstOrDefault(a => a.PluginId == Id && a.GameId == entry.Media.Id.ToString());
                            if (existingEntry != null)
                            {
                                UpdateExistingEntry(entry, existingEntry);
                            }
                            else
                            {
                                importedGames.Add(PlayniteApi.Database.ImportGame(EntryToGameMetadata(entry), this));
                            }
                        }
                    }
                }
            }

            return(importedGames);
        }
Ejemplo n.º 2
0
        public override IEnumerable <GameMetadata> GetGames(LibraryGetGamesArgs args)
        {
            var gamesList = new List <GameMetadata>()
            {
            };

            if (string.IsNullOrEmpty(settings.Settings.AccountAccessCode))
            {
                PlayniteApi.Notifications.Add(new NotificationMessage(
                                                  dbImportMessageId,
                                                  "AniList access code has not been configured in the library settings",
                                                  NotificationType.Error));
            }
            else
            {
                string propertiesPrefix = settings.Settings.PropertiesPrefix;
                if (!string.IsNullOrEmpty(propertiesPrefix))
                {
                    propertiesPrefix = string.Format("{0} ", propertiesPrefix);
                }

                var accountApi = new AnilistAccountClient(PlayniteApi, settings.Settings.AccountAccessCode);
                if (string.IsNullOrEmpty(accountApi.anilistUsername))
                {
                    //Username could not be obtained
                    PlayniteApi.Notifications.Add(new NotificationMessage(
                                                      dbImportMessageId,
                                                      "Could not obtain AniList username. Verify that the configured access code is valid",
                                                      NotificationType.Error));
                }
                else
                {
                    logger.Info($"AniList username: {accountApi.anilistUsername}");
                    if (settings.Settings.ImportAnimeLibrary == true)
                    {
                        var animeEntries = accountApi.GetEntries("ANIME");
                        logger.Debug($"Found {animeEntries.Count} Anime items");
                        foreach (var entry in animeEntries)
                        {
                            var gameInfo = EntryToGameMetadata(entry, propertiesPrefix);
                            gamesList.Add(gameInfo);
                            overrideGameProperties(gameInfo);
                        }
                    }

                    if (settings.Settings.ImportMangaLibrary == true)
                    {
                        var mangaEntries = accountApi.GetEntries("MANGA");
                        logger.Debug($"Found {mangaEntries.Count} Manga items");
                        foreach (var entry in mangaEntries)
                        {
                            var gameInfo = EntryToGameMetadata(entry, propertiesPrefix);
                            gamesList.Add(gameInfo);
                            overrideGameProperties(gameInfo);
                        }
                    }
                }
            }

            return(gamesList);
        }