Пример #1
0
        public GameMetadata GetMetadata(string gameId)
        {
            var          game  = GetParsedGame(ulong.Parse(gameId));
            MetadataFile image = null;

            if (!string.IsNullOrEmpty(game.CoverImage))
            {
                var name = Path.GetFileName(game.CoverImage);
                image = new MetadataFile($"images/custom/{name}", name, HttpDownloader.DownloadData(game.CoverImage));
            }

            return(new GameMetadata(game, null, image, string.Empty));
        }
Пример #2
0
 public static GameLocalDataResponse GetGameLocalData(string gameId)
 {
     try
     {
         var url        = string.Format(@"https://api1.origin.com/ecommerce2/public/{0}/en_US", gameId);
         var stringData = Encoding.UTF8.GetString(HttpDownloader.DownloadData(url));
         return(JsonConvert.DeserializeObject <GameLocalDataResponse>(stringData));
     }
     catch (Exception e)
     {
         logger.Error(e, "Failed to get local game Origin manifest.");
         return(null);
     }
 }
Пример #3
0
        internal GogGameMetadata DownloadGameMetadata(string id, string storeUrl = null)
        {
            var metadata   = new GogGameMetadata();
            var gameDetail = apiClient.GetGameDetails(id);

            metadata.GameDetails = gameDetail;

            if (gameDetail != null)
            {
                if (gameDetail.links.product_card != @"https://www.gog.com/" && !string.IsNullOrEmpty(gameDetail.links.product_card))
                {
                    metadata.StoreDetails = apiClient.GetGameStoreData(gameDetail.links.product_card);
                }
                else if (!string.IsNullOrEmpty(storeUrl))
                {
                    metadata.StoreDetails = apiClient.GetGameStoreData(storeUrl);
                }

                var icon     = HttpDownloader.DownloadData("http:" + gameDetail.images.icon);
                var iconName = Path.GetFileName(new Uri(gameDetail.images.icon).AbsolutePath);
                metadata.Icon = new MetadataFile(iconName, icon);

                if (metadata.StoreDetails != null)
                {
                    var imageUrl  = metadata.StoreDetails.image + "_product_card_v2_mobile_slider_639.jpg";
                    var image     = HttpDownloader.DownloadData(imageUrl);
                    var imageName = Path.GetFileName(new Uri(imageUrl).AbsolutePath);
                    metadata.Image = new MetadataFile(imageName, image);
                }
                else
                {
                    var image     = HttpDownloader.DownloadData("http:" + gameDetail.images.logo2x);
                    var imageName = Path.GetFileName(new Uri(gameDetail.images.logo2x).AbsolutePath);
                    metadata.Image = new MetadataFile(imageName, image);
                }

                if (metadata.StoreDetails != null)
                {
                    var url = metadata.StoreDetails.galaxyBackgroundImage ?? metadata.StoreDetails.backgroundImage;
                    metadata.BackgroundImage = url.Replace(".jpg", "_bg_crop_1920x655.jpg");
                }
                else
                {
                    metadata.BackgroundImage = "http:" + gameDetail.images.background;
                }
            }

            return(metadata);
        }
 public static StorePageMetadata GetStoreMetadata(string offerPath)
 {
     // Remove edition from offer path, offer path is: /<franchise>/<game>/<edition>
     var match = Regex.Match(offerPath, @"(\/(.+?)\/(.+?))\/");
     var offer = match.Groups[1].Value.ToString();
     var url = string.Format(@"https://data3.origin.com/ocd{0}.en-us.irl.ocd", offer);
     if (HttpDownloader.GetResponseCode(url) == System.Net.HttpStatusCode.OK)
     {
         var stringData = Encoding.UTF8.GetString(HttpDownloader.DownloadData(url));
         return JsonConvert.DeserializeObject<StorePageMetadata>(stringData);
     }
     else
     {
         return null;
     }
 }
Пример #5
0
        public OriginGameMetadata DownloadGameMetadata(string id)
        {
            var data = new OriginGameMetadata()
            {
                StoreDetails = WebApiClient.GetGameStoreData(id)
            };

            var imageUrl  = data.StoreDetails.imageServer + data.StoreDetails.i18n.packArtLarge;
            var imageData = HttpDownloader.DownloadData(imageUrl);
            var imageName = Guid.NewGuid() + Path.GetExtension(new Uri(imageUrl).AbsolutePath);

            data.Image = new MetadataFile(
                string.Format("images/origin/{0}/{1}", id.Replace(":", ""), imageName),
                imageName,
                imageData
                );

            return(data);
        }
Пример #6
0
        public GogGameMetadata DownloadGameMetadata(string id, string storeUrl = null)
        {
            var metadata   = new GogGameMetadata();
            var gameDetail = WebApiClient.GetGameDetails(id);

            metadata.GameDetails = gameDetail;

            if (gameDetail != null)
            {
                if (gameDetail.links.product_card != @"https://www.gog.com/" && !string.IsNullOrEmpty(gameDetail.links.product_card))
                {
                    metadata.StoreDetails = WebApiClient.GetGameStoreData(gameDetail.links.product_card);
                }
                else if (!string.IsNullOrEmpty(storeUrl))
                {
                    metadata.StoreDetails = WebApiClient.GetGameStoreData(storeUrl);
                }

                var icon      = HttpDownloader.DownloadData("http:" + gameDetail.images.icon);
                var iconName  = Path.GetFileName(new Uri(gameDetail.images.icon).AbsolutePath);
                var image     = HttpDownloader.DownloadData("http:" + gameDetail.images.logo2x);
                var imageName = Path.GetFileName(new Uri(gameDetail.images.logo2x).AbsolutePath);

                metadata.Icon = new MetadataFile(
                    string.Format("images/gog/{0}/{1}", id, iconName),
                    iconName,
                    icon
                    );

                metadata.Image = new MetadataFile(
                    string.Format("images/gog/{0}/{1}", id, imageName),
                    imageName,
                    image
                    );

                metadata.BackgroundImage = "http:" + gameDetail.images.background;
            }

            return(metadata);
        }
Пример #7
0
        internal SteamGameMetadata DownloadGameMetadata(uint appId, BackgroundSource backgroundSource)
        {
            var metadata    = new SteamGameMetadata();
            var productInfo = GetAppInfo(appId);

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

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

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

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

            byte[] imageData = null;

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

            if (imageData != null)
            {
                var imageName = Path.GetFileName(new Uri(imageUrl).AbsolutePath);
                metadata.Image = new MetadataFile(imageName, imageData);
            }

            // Background Image
            switch (backgroundSource)
            {
            case BackgroundSource.Image:
                metadata.BackgroundImage = GetGameBackground(appId);
                break;

            case BackgroundSource.StoreScreenshot:
                metadata.BackgroundImage = Regex.Replace(metadata.StoreDetails.screenshots.First().path_full, "\\?.*$", "");
                break;

            case BackgroundSource.StoreBackground:
                metadata.BackgroundImage = string.Format(@"https://steamcdn-a.akamaihd.net/steam/apps/{0}/page_bg_generated_v6b.jpg", appId);
                break;

            default:
                break;
            }

            return(metadata);
        }
Пример #8
0
        public GameMetadata GetMetadata(Game game)
        {
            var gameData = new Game()
            {
                Links  = new ObservableCollection <Link>(),
                Tags   = new ComparableList <string>(),
                Genres = new ComparableList <string>()
            };

            var metadata = new GameMetadata
            {
                GameData = gameData
            };

            var itchGame = butler.GetGame(Convert.ToInt32(game.GameId));

            // Cover image
            if (!string.IsNullOrEmpty(itchGame.coverUrl))
            {
                var cover     = HttpDownloader.DownloadData(itchGame.coverUrl);
                var coverFile = Path.GetFileName(itchGame.coverUrl);
                metadata.Image = new MetadataFile(coverFile, cover);
            }

            if (!string.IsNullOrEmpty(itchGame.url))
            {
                gameData.Links.Add(new Link("Store", itchGame.url));
                var gamePageSrc = HttpDownloader.DownloadString(itchGame.url);
                var parser      = new HtmlParser();
                var gamePage    = parser.Parse(gamePageSrc);

                // Description
                gameData.Description = gamePage.QuerySelector(".formatted_description").InnerHtml;

                // Background
                var gameTheme = gamePage.QuerySelector("#game_theme").InnerHtml;
                var bckMatch  = Regex.Match(gameTheme, @"background-image:\surl\((.+?)\)");
                if (bckMatch.Success)
                {
                    metadata.BackgroundImage = bckMatch.Groups[1].Value;
                    gameData.BackgroundImage = bckMatch.Groups[1].Value;
                }

                // Other info
                var infoPanel = gamePage.QuerySelector(".game_info_panel_widget");
                var fields    = infoPanel.QuerySelectorAll("tr");
                foreach (var field in fields)
                {
                    var name = field.QuerySelectorAll("td")[0].TextContent;
                    if (name == "Genre")
                    {
                        foreach (var item in field.QuerySelectorAll("a"))
                        {
                            gameData.Genres.Add(item.TextContent);
                        }

                        continue;
                    }

                    if (name == "Tags")
                    {
                        foreach (var item in field.QuerySelectorAll("a"))
                        {
                            gameData.Tags.Add(item.TextContent);
                        }

                        continue;
                    }

                    if (name == "Links")
                    {
                        foreach (var item in field.QuerySelectorAll("a"))
                        {
                            gameData.Links.Add(new Link(item.TextContent, item.Attributes["href"].Value));
                        }

                        continue;
                    }

                    if (name == "Author")
                    {
                        gameData.Developers = new ComparableList <string> {
                            field.ChildNodes[1].TextContent
                        };
                    }

                    if (name == "Release date")
                    {
                        var strDate = field.QuerySelector("abbr").Attributes["title"].Value.Split('@')[0].Trim();
                        if (DateTime.TryParseExact(strDate, "d MMMM yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out var dateTime))
                        {
                            gameData.ReleaseDate = dateTime;
                        }
                    }
                }
            }

            return(metadata);
        }
Пример #9
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 = HttpDownloader.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 = HttpDownloader.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 = HttpDownloader.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);
        }
 public static GameStoreDataResponse GetGameStoreData(string gameId)
 {
     var url = string.Format(@"https://api2.origin.com/ecommerce2/public/supercat/{0}/en_IE?country=IE", gameId);
     var stringData = Encoding.UTF8.GetString(HttpDownloader.DownloadData(url));
     return JsonConvert.DeserializeObject<GameStoreDataResponse>(stringData);
 }