Example #1
0
        public SteamGameMetadata DownloadGameMetadata(int id)
        {
            var metadata    = new SteamGameMetadata();
            var productInfo = SteamApiClient.GetProductInfo(id).GetAwaiter().GetResult();

            metadata.ProductDetails = productInfo;

            // Steam may return 429 if we put too many request
            for (int i = 0; i < 10; i++)
            {
                try
                {
                    metadata.StoreDetails = WebApiClient.GetStoreAppDetail(id);
                    break;
                }
                catch (WebException e)
                {
                    if (i + 1 == 10)
                    {
                        throw;
                    }

                    if (e.Message.Contains("429"))
                    {
                        Thread.Sleep(2500);
                        continue;
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            // Icon
            var iconRoot = @"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/{0}/{1}.ico";
            var icon     = productInfo["common"]["clienticon"];
            var iconUrl  = string.Empty;

            if (icon.Name != null)
            {
                iconUrl = string.Format(iconRoot, id, icon.Value);
            }
            else
            {
                var newIcon = productInfo["common"]["icon"];
                if (newIcon.Name != null)
                {
                    iconRoot = @"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/{0}/{1}.jpg";
                    iconUrl  = string.Format(iconRoot, id, newIcon.Value);
                }
            }

            // There might be no icon assigned to game
            if (!string.IsNullOrEmpty(iconUrl))
            {
                var iconName = Path.GetFileName(new Uri(iconUrl).AbsolutePath);
                var iconData = Web.DownloadData(iconUrl);
                metadata.Icon = new FileDefinition(

                    string.Format("images/steam/{0}/{1}", id.ToString(), iconName),
                    iconName,
                    iconData
                    );
            }


            // Image
            var imageRoot = @"http://cdn.akamai.steamstatic.com/steam/apps/{0}/header.jpg";
            var imageUrl  = string.Format(imageRoot, id);

            byte[] imageData = null;

            try
            {
                imageData = Web.DownloadData(imageUrl);
            }
            catch (WebException e)
            {
                var response = (HttpWebResponse)e.Response;
                if (response.StatusCode == HttpStatusCode.NotFound)
                {
                    imageRoot = @"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/{0}/{1}.jpg";
                    var image = productInfo["common"]["logo"];
                    if (image.Name != null)
                    {
                        imageUrl  = string.Format(imageRoot, id, image.Value);
                        imageData = Web.DownloadData(imageUrl);
                    }
                }
                else
                {
                    throw;
                }
            }

            if (imageData != null)
            {
                var imageName = Path.GetFileName(new Uri(imageUrl).AbsolutePath);
                metadata.Image = new FileDefinition(
                    string.Format("images/steam/{0}/{1}", id.ToString(), imageName),
                    imageName,
                    imageData
                    );
            }

            // Background Image
            metadata.BackgroundImage = string.Format(@"https://steamcdn-a.akamaihd.net/steam/apps/{0}/page_bg_generated_v6b.jpg", id);

            return(metadata);
        }
Example #2
0
        public SteamGameMetadata DownloadGameMetadata(int id, bool screenAsBackground)
        {
            var metadata    = new SteamGameMetadata();
            var productInfo = GetAppInfo(id);

            metadata.ProductDetails = productInfo;
            metadata.StoreDetails   = GetStoreData(id);

            // Icon
            var iconRoot = @"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/{0}/{1}.ico";
            var icon     = productInfo["common"]["clienticon"];
            var iconUrl  = string.Empty;

            if (icon.Name != null)
            {
                iconUrl = string.Format(iconRoot, id, icon.Value);
            }
            else
            {
                var newIcon = productInfo["common"]["icon"];
                if (newIcon.Name != null)
                {
                    iconRoot = @"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/{0}/{1}.jpg";
                    iconUrl  = string.Format(iconRoot, id, newIcon.Value);
                }
            }

            // There might be no icon assigned to game
            if (!string.IsNullOrEmpty(iconUrl))
            {
                var iconName = Path.GetFileName(new Uri(iconUrl).AbsolutePath);
                var iconData = Web.DownloadData(iconUrl);
                metadata.Icon = new FileDefinition(

                    string.Format("images/steam/{0}/{1}", id.ToString(), iconName),
                    iconName,
                    iconData
                    );
            }


            // Image
            var imageRoot = @"http://cdn.akamai.steamstatic.com/steam/apps/{0}/header.jpg";
            var imageUrl  = string.Format(imageRoot, id);

            byte[] imageData = null;

            try
            {
                imageData = Web.DownloadData(imageUrl);
            }
            catch (WebException e)
            {
                var response = (HttpWebResponse)e.Response;
                if (response.StatusCode == HttpStatusCode.NotFound)
                {
                    imageRoot = @"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/apps/{0}/{1}.jpg";
                    var image = productInfo["common"]["logo"];
                    if (image.Name != null)
                    {
                        imageUrl  = string.Format(imageRoot, id, image.Value);
                        imageData = Web.DownloadData(imageUrl);
                    }
                }
                else
                {
                    throw;
                }
            }

            if (imageData != null)
            {
                var imageName = Path.GetFileName(new Uri(imageUrl).AbsolutePath);
                metadata.Image = new FileDefinition(
                    string.Format("images/steam/{0}/{1}", id.ToString(), imageName),
                    imageName,
                    imageData
                    );
            }

            // Background Image
            if (screenAsBackground)
            {
                if (metadata.StoreDetails?.screenshots?.Any() == true)
                {
                    metadata.BackgroundImage = Regex.Replace(metadata.StoreDetails.screenshots.First().path_full, "\\?.*$", "");
                }
            }
            else
            {
                metadata.BackgroundImage = string.Format(@"https://steamcdn-a.akamaihd.net/steam/apps/{0}/page_bg_generated_v6b.jpg", id);
            }

            return(metadata);
        }