Example #1
0
        public List <GameInfo> GetLibraryGames()
        {
            var token = GetAuthToken();

            if (token.IsNullOrEmpty())
            {
                throw new Exception("Authentication is required.");
            }


            var games        = new List <GameInfo>();
            var entitlements = AmazonEntitlementClient.GetAccountEntitlements(token);

            foreach (var item in entitlements)
            {
                if (item.product.productLine != "Twitch:FuelGame")
                {
                    continue;
                }

                var game = new GameInfo()
                {
                    Source = "Twitch",
                    GameId = item.product.id,
                    Name   = item.product.title
                };

                games.Add(game);
            }

            return(games);
        }
Example #2
0
        public TwitchMetadataProvider(TwitchLibrary library)
        {
            this.library = library;
            var token = library.GetAuthToken();

            if (!token.IsNullOrEmpty())
            {
                try
                {
                    entitlements = AmazonEntitlementClient.GetAccountEntitlements(token);
                }
                catch (Exception e)
                {
                    logger.Error(e, "Failed to get entitlements for Twitch metadata.");
                }
            }
        }
Example #3
0
        public List <Game> GetLibraryGames()
        {
            var login = LoginData;

            if (login == null)
            {
                throw new Exception("User is not logged in.");
            }

            var games = new List <Game>();
            List <GoodsItem> libraryGames = null;

            try
            {
                libraryGames = AmazonEntitlementClient.GetAccountEntitlements(login.AccountId, login.AccessToken);
            }
            catch (WebException libExc)
            {
                // Token renew doesn't properly based on expiration date, so try always to renew token for now until it's fixed.
                logger.Warn(libExc, "Failed to download Twitch library at first attempt.");
                try
                {
                    var client = new TwitchAccountClient(null, TokensPath);
                    client.RenewTokens(login.AuthenticationToken, login.AccountId);
                    login = LoginData;
                }
                catch (Exception renewExc)
                {
                    logger.Error(renewExc, "Failed to renew Twitch authentication.");
                }

                try
                {
                    libraryGames = AmazonEntitlementClient.GetAccountEntitlements(login.AccountId, login.AccessToken);
                }
                catch (Exception e)
                {
                    logger.Error(e, "Failed to download Twitch library.");
                    throw new Exception("Authentication is required.");
                }
            }

            foreach (var item in libraryGames)
            {
                if (item.product.productLine != "Twitch:FuelGame")
                {
                    continue;
                }

                var game = new Game()
                {
                    PluginId = Id,
                    Source   = "Twitch",
                    GameId   = item.product.id,
                    Name     = item.product.productTitle
                };

                games.Add(game);
            }

            return(games);
        }
        public override GameMetadata GetMetadata(Game game)
        {
            if (entitlements == null)
            {
                var token = library.GetAuthToken();
                if (!token.IsNullOrEmpty())
                {
                    try
                    {
                        entitlements = AmazonEntitlementClient.GetAccountEntitlements(token);
                    }
                    catch (Exception e)
                    {
                        entitlements = new List <Entitlement>();
                        logger.Error(e, "Failed to get entitlements for Twitch metadata.");
                    }
                }
            }

            var gameInfo = new GameInfo
            {
                Links = new List <Link>()
            };

            var metadata = new GameMetadata()
            {
                GameInfo = gameInfo
            };

            gameInfo.Links.Add(new Link("PCGamingWiki", @"http://pcgamingwiki.com/w/index.php?search=" + game.Name));

            var program = Twitch.GetUninstallRecord(game.GameId);

            if (program != null)
            {
                gameInfo.Name = StringExtensions.NormalizeGameName(program.DisplayName);
                if (!string.IsNullOrEmpty(program.DisplayIcon) && File.Exists(program.DisplayIcon))
                {
                    var iconPath = program.DisplayIcon;
                    if (iconPath.EndsWith("ico", StringComparison.OrdinalIgnoreCase))
                    {
                        metadata.Icon = new MetadataFile(program.DisplayIcon);
                    }
                    else
                    {
                        var exeIcon = IconExtension.ExtractIconFromExe(iconPath, true);
                        if (exeIcon != null)
                        {
                            var iconName = Guid.NewGuid() + ".png";
                            metadata.Icon = new MetadataFile(iconName, exeIcon.ToByteArray(System.Drawing.Imaging.ImageFormat.Png));
                        }
                    }
                }
            }

            if (entitlements?.Any() == true)
            {
                var entitlement = entitlements.FirstOrDefault(a => a.product.id == game.GameId);
                if (entitlement != null)
                {
                    if (entitlement.product.productDetail?.iconUrl != null)
                    {
                        metadata.CoverImage = new MetadataFile(entitlement.product.productDetail.iconUrl);
                    }

                    // Ignore Getting Over It background, which is set if the publisher didn't assigned any
                    // https://github.com/JosefNemec/Playnite/issues/1376
                    var backgroundUrl = entitlement.product.productDetail?.details?.backgroundUrl2;
                    if (!backgroundUrl.IsNullOrEmpty() && backgroundUrl != "https://images-na.ssl-images-amazon.com/images/I/A1VAra5JJvL.jpg")
                    {
                        metadata.BackgroundImage = new MetadataFile(entitlement.product.productDetail.details.backgroundUrl2);
                    }
                }
            }

            return(metadata);
        }