Ejemplo n.º 1
0
        public List <ScraperData> GetGameInformation(string MD5, string SHA1, string romName, GameSystems system, string romTitle = null)
        {
            List <ScraperData> gamesList    = new List <ScraperData>();
            string             responseJson = string.Empty;

            using (HttpClient httpClient = new HttpClient())
            {
                string platform = string.Empty;
                switch (system)
                {
                case GameSystems.SegaMegaDrive:
                    platform = "1";
                    break;

                case GameSystems.SegaMasterSystem:
                    platform = "2";
                    break;

                case GameSystems.Sega32X:
                    platform = "19";
                    break;

                case GameSystems.SegaCD:
                    platform = "20";
                    break;
                }

                StringReader cdata          = new StringReader(Encoding.Default.GetString(Properties.Resources.ss));
                string       devId          = cdata.ReadLine();
                string       devPwd         = cdata.ReadLine();
                string       gamesDbRequest = $"https://www.screenscraper.fr/api/jeuInfos.php?devid={devId}&devpassword={devPwd}&softname=ProjectLunar1.0&output=json&md5={MD5}&sha1={SHA1}&systemeid={platform}";
                responseJson = httpClient.GetStringAsync(new Uri(gamesDbRequest)).Result;

                if (responseJson.ToLower().Contains("erreur") && !responseJson.ToLower().Contains("header") && !responseJson.ToLower().Contains("response"))
                {
                    //attempt to get by rom name
                    gamesDbRequest = $"https://www.screenscraper.fr/api/jeuInfos.php?devid={devId}&devpassword={devPwd}&softname=ProjectLunar1.0&output=json&romnom={romName}&systemeid={platform}";
                    responseJson   = httpClient.GetStringAsync(new Uri(gamesDbRequest)).Result;
                }
                string gameName = string.Empty;
                if (responseJson.ToLower().Contains("erreur") && !responseJson.ToLower().Contains("header") && !responseJson.ToLower().Contains("response"))
                {
                    //attempt to distill game name
                    gameName = Path.GetFileNameWithoutExtension(romName).Replace("_", " ");
                    if (gameName.Contains("(") || gameName.Contains("("))
                    {
                        gameName = gameName.Substring(0, gameName.IndexOfAny(new char[] { '[', '(' }) - 1);
                    }

                    gamesDbRequest = $"https://www.screenscraper.fr/api/jeuInfos.php?devid={devId}&devpassword={devPwd}&softname=ProjectLunar1.0&output=json&romnom={gameName}&systemeid={platform}";
                    responseJson   = httpClient.GetStringAsync(new Uri(gamesDbRequest)).Result;
                }
                if (responseJson.ToLower().Contains("erreur") && !responseJson.ToLower().Contains("header") && !responseJson.ToLower().Contains("response"))
                {
                    //Try using the typed title as a ROM name
                    gamesDbRequest = $"https://www.screenscraper.fr/api/jeuInfos.php?devid={devId}&devpassword={devPwd}&softname=ProjectLunar1.0&output=json&romnom={romTitle}&systemeid={platform}";
                    responseJson   = httpClient.GetStringAsync(new Uri(gamesDbRequest)).Result;
                }

                if (responseJson.ToLower().Contains("erreur") && !responseJson.ToLower().Contains("header") && !responseJson.ToLower().Contains("response"))
                {
                    throw new AggregateException($"Could not find game information in the ScreenScraper database. \r\nYour ROM hash {MD5}, the ROM name \"{romName}\", the distilled ROM name \"{gameName}\", and ROM title \"{romTitle}\" don't match any records.", new Exception(responseJson));
                }
            }

            if (responseJson.Contains("The maximum threads allowed to leecher users is already used"))
            {
                throw new Exception($"ScreenScraper did not respond with game information.\r\nDetails: {responseJson}");
            }

            JObject scrapedGames = null;

            try
            {
                scrapedGames = JObject.Parse(responseJson);
            }
            catch (Exception ex)
            {
                throw new AggregateException("Could not find game information. Your ROM hash is not in the ScreenScraper database, or the ROM name doesn't match any records.", new Exception(responseJson), ex);
            }

            ScraperData gameEntry = new ScraperData();

            gameEntry.ScrapedGameData = scrapedGames;

            JToken game = scrapedGames["response"]["jeu"];
            string some = game.ToString();

            gameEntry.System = game["systemenom"].ToString();

            string name_Def = "nom_us";

            if (game["noms"]["nom_us"] == null)
            {
                if (game["noms"]["nom_wor"] == null)
                {
                    name_Def = "nom_ss";
                }
                else
                {
                    name_Def = "nom_wor";
                }
            }

            gameEntry.Name.Add("jp", (game["noms"]["nom_jp"] == null ? game["noms"][name_Def].ToString()
                                                                     : game["noms"]["nom_jp"].ToString()));
            gameEntry.Name.Add("en", (game["noms"]["nom_us"] == null ? game["noms"][name_Def].ToString()
                                                                     : game["noms"]["nom_us"].ToString()));
            gameEntry.Name.Add("fr", (game["noms"]["nom_eu"] == null ? game["noms"][name_Def].ToString()
                                                                     : game["noms"]["nom_eu"].ToString()));
            gameEntry.Name.Add("it", (game["noms"]["nom_eu"] == null ? game["noms"][name_Def].ToString()
                                                                     : game["noms"]["nom_eu"].ToString()));
            gameEntry.Name.Add("de", (game["noms"]["nom_eu"] == null ? game["noms"][name_Def].ToString()
                                                                     : game["noms"]["nom_eu"].ToString()));
            gameEntry.Name.Add("es", (game["noms"]["nom_eu"] == null ? game["noms"][name_Def].ToString()
                                                                     : game["noms"]["nom_eu"].ToString()));
            gameEntry.Name.Add("cn", (game["noms"]["nom_cn"] == null ? game["noms"][name_Def].ToString()
                                                                     : game["noms"]["nom_cn"].ToString()));
            gameEntry.Name.Add("kr", (game["noms"]["nom_kr"] == null ? game["noms"][name_Def].ToString()
                                                                     : game["noms"]["nom_kr"].ToString()));

            string default_descr = "synopsis_en";

            if (game["synopsis"]["synopsis_en"] == null)
            {
                default_descr = ((JProperty)game["synopsis"].First()).Name;
            }

            if (game["synopsis"] != null)
            {
                gameEntry.Description.Add("jp", (game["synopsis"]["synopsis_jp"] == null ? HttpUtility.HtmlDecode(game["synopsis"][default_descr].ToString())
                                                                                         : HttpUtility.HtmlDecode(game["synopsis"]["synopsis_jp"].ToString())));
                gameEntry.Description.Add("en", (game["synopsis"]["synopsis_en"] == null ? HttpUtility.HtmlDecode(game["synopsis"][default_descr].ToString())
                                                                                         : HttpUtility.HtmlDecode(game["synopsis"]["synopsis_en"].ToString())));
                gameEntry.Description.Add("fr", (game["synopsis"]["synopsis_fr"] == null ? HttpUtility.HtmlDecode(game["synopsis"][default_descr].ToString())
                                                                                         : HttpUtility.HtmlDecode(game["synopsis"]["synopsis_fr"].ToString())));
                gameEntry.Description.Add("it", (game["synopsis"]["synopsis_it"] == null ? HttpUtility.HtmlDecode(game["synopsis"][default_descr].ToString())
                                                                                         : HttpUtility.HtmlDecode(game["synopsis"]["synopsis_it"].ToString())));
                gameEntry.Description.Add("de", (game["synopsis"]["synopsis_de"] == null ? HttpUtility.HtmlDecode(game["synopsis"][default_descr].ToString())
                                                                                         : HttpUtility.HtmlDecode(game["synopsis"]["synopsis_de"].ToString())));
                gameEntry.Description.Add("es", (game["synopsis"]["synopsis_es"] == null ? HttpUtility.HtmlDecode(game["synopsis"][default_descr].ToString())
                                                                                         : HttpUtility.HtmlDecode(game["synopsis"]["synopsis_es"].ToString())));
                gameEntry.Description.Add("cn", (game["synopsis"]["synopsis_cn"] == null ? HttpUtility.HtmlDecode(game["synopsis"][default_descr].ToString())
                                                                                         : HttpUtility.HtmlDecode(game["synopsis"]["synopsis_cn"].ToString())));
                gameEntry.Description.Add("kr", (game["synopsis"]["synopsis_kr"] == null ? HttpUtility.HtmlDecode(game["synopsis"][default_descr].ToString())
                                                                                         : HttpUtility.HtmlDecode(game["synopsis"]["synopsis_kr"].ToString())));
            }
            else
            {
                gameEntry.Description.Add("jp", "No description available.");
                gameEntry.Description.Add("en", "No description available.");
                gameEntry.Description.Add("fr", "No description available.");
                gameEntry.Description.Add("it", "No description available.");
                gameEntry.Description.Add("de", "No description available.");
                gameEntry.Description.Add("es", "No description available.");
                gameEntry.Description.Add("cn", "No description available.");
                gameEntry.Description.Add("kr", "No description available.");
            }

            gameEntry.Copyright = (game["editeur"] == null ? string.Empty : game["editeur"].ToString());
            try
            {
                gameEntry.PlayerNum = playerNumMapping[Assign <string>(game["joueurs"])];
            }
            catch
            {
                gameEntry.PlayerNum = 0;
            }
            if (game["genres"] != null)
            {
                try
                {
                    gameEntry.Genre = genreMapping[Assign <string>(game["genres"]["genres_en"][0]).ToLower()];
                }
                catch
                {
                    gameEntry.Genre = 0;
                }
            }

            gameEntry.Region      = "ss";
            gameEntry.ReleaseDate = GetReleaseDate(game, "jp");
            gamesList.Add(gameEntry);

            if (game["medias"]["media_boxs"] == null || game["medias"]["media_boxs"]["media_boxs2d"] == null)
            {
                return(gamesList);
            }

            List <JToken> covers = game["medias"]["media_boxs"]["media_boxs2d"].Children()
                                   .Where(c => ((JProperty)c).Name.Split('_').Count().Equals(3)).ToList();

            if (covers.Count > 1)
            {
                foreach (var cover in covers)
                {
                    string coverName   = ((JProperty)cover).Name;
                    string coverRegion = coverName.Substring(coverName.LastIndexOf("_") + 1);
                    if (coverRegion.Equals("ss"))
                    {
                        continue;
                    }

                    gameEntry.ReleaseDate = GetReleaseDate(game, coverRegion);

                    gamesList.Add(new ScraperData()
                    {
                        Name            = gameEntry.Name,
                        Description     = gameEntry.Description,
                        Copyright       = gameEntry.Copyright,
                        Genre           = gameEntry.Genre,
                        PlayerNum       = gameEntry.PlayerNum,
                        ReleaseDate     = gameEntry.ReleaseDate,
                        ScrapedGameData = gameEntry.ScrapedGameData,
                        System          = gameEntry.System,
                        Region          = coverRegion
                    });
                }
            }

            return(gamesList);
        }
        public List <ScraperData> GetGameInformation(string gameName, GameSystems system)
        {
            string             apiKey       = Encoding.ASCII.GetString(Properties.Resources.tgdb);
            List <ScraperData> gamesList    = new List <ScraperData>();
            string             responseJson = string.Empty;

            using (HttpClient httpClient = new HttpClient())
            {
                gameName = Uri.EscapeUriString(gameName);
                string platform       = (system.Equals(GameSystems.SegaMasterSystem) ? "35" : "18%2C36");
                string gamesDbRequest = $"https://api.thegamesdb.net/Games/ByGameName?apikey={apiKey}&name={gameName}&fields=players%2Cpublishers%2Cgenres%2Coverview%2Cplatform&filter%5Bplatform%5D={platform}&include=boxart%2Cplatform";

                responseJson = httpClient.GetStringAsync(new Uri(gamesDbRequest)).Result;
            }
            //string responseJson = "{\"code\":200,\"status\":\"Success\",\"data\":{\"count\":7,\"games\":[{\"id\":691,\"game_title\":\"Sonic the Hedgehog 3\",\"release_date\":\"1994-02-02\",\"platform\":18,\"players\":2,\"overview\":\"Swing from vines, launch new attacks, survive deadly traps and summon Tails to airlift Sonic out of danger. Discover hidden rooms and passageways in the mega-sized Zones. Transform into Super Sonic and experience the ultimate in speed and ultra-sonic power. Save your progress using the new Game Save Feature.\",\"developers\":[7979],\"genres\":[2],\"publishers\":[15]},{\"id\":5569,\"game_title\":\"Sonic the Hedgehog 3\",\"release_date\":\"1994-02-02\",\"platform\":36,\"players\":2,\"overview\":\"In single player mode, the player can choose to play solo, as either Sonic or Tails, or as a team, controlling Sonic, with the AI controlling Tails, which is the default configuration. Another player may take control of Tails at any time by using a controller plugged into port 2. The object of the game is to progress through the levels. In order to completely finish the game, seven Chaos Emeralds must also be collected from the special stages.\",\"developers\":[7979],\"genres\":[15],\"publishers\":[15]},{\"id\":39170,\"game_title\":\"Sonic & Knuckles + Sonic the Hedgehog 3\",\"release_date\":\"1994-10-18\",\"platform\":36,\"players\":1,\"overview\":\"Dr. Eggmans (AKA Dr. Robotniks) Death Egg was once again blasted by Sonic, crash-landing on the peak of a volcano on the Floating Island.\\r\\n\\r\\nDr. Eggman is still at large, and Sonic cant allow him to get his hands on the Master Emerald and repair the Death Egg. Sonic must also keep Knuckles off his back but Knuckles has problems too. As guardian of the Floating Island and all the Emeralds, Knuckles must do his part to keep the island safe. While theyre going the rounds with each other, who will stop Dr. Eggman?\",\"developers\":[7549],\"genres\":[15],\"publishers\":[15]},{\"id\":114,\"game_title\":\"Sonic the Hedgehog\",\"release_date\":\"1991-06-23\",\"platform\":18,\"players\":1,\"overview\":\"Super Speed! Bust the video game speed barrier wide open with Sonic the Hedgehog. Blaze by in a blur using the super sonic spin attack. Loop the loop by defying gravity. Plummet down tunnels. Then dash to safety with Sonic's power sneakers. All at a frenzied pace. Super Graphics! Help Sonic escape bubbling molten lava. Swim through turbulent waterfalls. Scale glistening green mountains. And soar past shimmering city lights. There's even a 360 degree rotating maze. You've never seen anything like it. Supper Attitude! Sonic has an attitude that just won't quit. He's flip and funny, yet tough as nails as he fights to free his friends from evil. So just wait. Sonic may be the world's next SUPER hero...\",\"developers\":[7979],\"genres\":[1,15],\"publishers\":[15]},{\"id\":5544,\"game_title\":\"Sonic the Hedgehog\",\"release_date\":\"1991-06-23\",\"platform\":36,\"players\":1,\"overview\":\"When Dr. Eggman was hatching his plans for a global takeover, there was one little thing he didn't count on - Sonic The Hedgehog! Our blue hero zips, flips, and spins through the levels at lightning speed to collect the Chaos Emerald and restore World Order.\",\"developers\":[7549],\"genres\":[1,15],\"publishers\":[15]},{\"id\":142,\"game_title\":\"Sonic the Hedgehog 2\",\"release_date\":\"1992-11-21\",\"platform\":18,\"players\":2,\"overview\":\"Super Speed! Sonic's back and better than ever. He's a blur in blue! A blaze of action! With his new Super Spin Dash. And a new, fabulous friend, \\\"Tails\\\" the Fox. You won't believe it 'til you see it. And when you play, you won't stop. Super Play! Defy gravity in hair-raising loop-de-loops. Grab Power Sneakers and race like lightning through the mazes. Dash in a dizzying whirl across corkscrew speedway. Bounce like a pinball through the bumpers and springs of the amazing Zones. All at break-neck speed! Super Power! Sonic's attitude is can-do. The mad scientist Dr. Robotnik is planning a world takeover. Sonic gets tough in the fight to save his friends and squash Robotnik for good!\",\"developers\":[7979],\"genres\":[1,15],\"publishers\":[15]},{\"id\":7504,\"game_title\":\"Sonic the Hedgehog 2\",\"release_date\":\"1992-11-20\",\"platform\":36,\"players\":2,\"overview\":\"The gameplay of Sonic the Hedgehog 2 builds upon the basic set-up of the original Sonic the Hedgehog game. The player finishes each level, generally moving from left to right, within a time limit of 10 minutes.  Along the way, rings are collected and Badniks are defeated. Star posts serve as checkpoints, where if the player was to lose a life then he or she would return to one.  When the player has collected at least 50 rings, star posts can be run past for an optional Special Stage.  At the end of the last act of each zone (with the exception of Sky Chase Zone which does not have a boss), Sonic confronts Dr. Robotnik.\",\"developers\":[7549],\"genres\":[1,15],\"publishers\":[15]}]},\"include\":{\"boxart\":{\"base_url\":{\"original\":\"https:\\/\\/cdn.thegamesdb.net\\/images\\/original\\/\",\"small\":\"https:\\/\\/cdn.thegamesdb.net\\/images\\/small\\/\",\"thumb\":\"https:\\/\\/cdn.thegamesdb.net\\/images\\/thumb\\/\",\"cropped_center_thumb\":\"https:\\/\\/cdn.thegamesdb.net\\/images\\/cropped_center_thumb\\/\",\"medium\":\"https:\\/\\/cdn.thegamesdb.net\\/images\\/medium\\/\",\"large\":\"https:\\/\\/cdn.thegamesdb.net\\/images\\/large\\/\"},\"data\":{\"114\":[{\"id\":1447,\"type\":\"boxart\",\"side\":\"back\",\"filename\":\"boxart\\/back\\/114-1.jpg\",\"resolution\":\"903x1271\"},{\"id\":211263,\"type\":\"boxart\",\"side\":\"front\",\"filename\":\"boxart\\/front\\/114-1.jpg\",\"resolution\":null}],\"142\":[{\"id\":19386,\"type\":\"boxart\",\"side\":\"front\",\"filename\":\"boxart\\/front\\/142-2.jpg\",\"resolution\":\"1529x2100\"},{\"id\":19387,\"type\":\"boxart\",\"side\":\"back\",\"filename\":\"boxart\\/back\\/142-1.jpg\",\"resolution\":\"1530x2100\"}],\"691\":[{\"id\":8174,\"type\":\"boxart\",\"side\":\"front\",\"filename\":\"boxart\\/front\\/691-2.jpg\",\"resolution\":\"1443x2036\"},{\"id\":8177,\"type\":\"boxart\",\"side\":\"back\",\"filename\":\"boxart\\/back\\/691-2.jpg\",\"resolution\":\"1416x2036\"}],\"5544\":[{\"id\":14405,\"type\":\"boxart\",\"side\":\"back\",\"filename\":\"boxart\\/back\\/5544-1.jpg\",\"resolution\":\"741x1008\"},{\"id\":132939,\"type\":\"boxart\",\"side\":\"front\",\"filename\":\"boxart\\/front\\/5544-1.jpg\",\"resolution\":\"1445x2035\"}],\"5569\":[{\"id\":14402,\"type\":\"boxart\",\"side\":\"back\",\"filename\":\"boxart\\/back\\/5569-1.jpg\",\"resolution\":\"1354x1872\"},{\"id\":14404,\"type\":\"boxart\",\"side\":\"front\",\"filename\":\"boxart\\/front\\/5569-1.jpg\",\"resolution\":\"1353x1872\"}],\"7504\":[{\"id\":19389,\"type\":\"boxart\",\"side\":\"front\",\"filename\":\"boxart\\/front\\/7504-1.jpg\",\"resolution\":\"1529x2085\"},{\"id\":19391,\"type\":\"boxart\",\"side\":\"back\",\"filename\":\"boxart\\/back\\/7504-1.jpg\",\"resolution\":\"1530x2085\"}],\"39170\":[{\"id\":108372,\"type\":\"boxart\",\"side\":\"front\",\"filename\":\"boxart\\/front\\/39170-1.jpg\",\"resolution\":\"1435x1990\"}]}},\"platform\":{\"18\":{\"id\":18,\"name\":\"Sega Genesis\",\"alias\":\"sega-genesis\"},\"36\":{\"id\":36,\"name\":\"Sega Mega Drive\",\"alias\":\"sega-mega-drive\"}}},\"pages\":{\"previous\":null,\"current\":\"https:\\/\\/api.thegamesdb.net\\/Games\\/ByGameName?apikey={apiKey}&name=Sonic+the+Hedgehog+3&fields=players%2Cpublishers%2Cgenres%2Coverview%2Cplatform&filter%5Bplatform%5D=18%2C36&include=boxart%2Cplatform&page=1\",\"next\":null},\"remaining_monthly_allowance\":1496,\"extra_allowance\":0,\"allowance_refresh_timer\":2536674}";
            JObject scrapedGames = JObject.Parse(responseJson);

            List <string> lstScrapeItems = new List <string>();

            foreach (var game in scrapedGames["data"]["games"])
            {
                ScraperData gameEntry = new ScraperData();

                int    platformNum  = (int)game["platform"];
                string platformName = (platformNum == 18 ? "Genesis" : (platformNum == 36 ? "Mega Drive" : (platformNum == 35 ? "Master System" : "unknown")));
                lstScrapeItems.Add($"{game["game_title"].ToString()} ({platformName})");

                gameEntry.System = platformName;

                string title = game["game_title"].ToString();
                gameEntry.Name.Add("jp", title);
                gameEntry.Name.Add("en", title);
                gameEntry.Name.Add("fr", title);
                gameEntry.Name.Add("it", title);
                gameEntry.Name.Add("de", title);
                gameEntry.Name.Add("es", title);
                gameEntry.Name.Add("cn", title);
                gameEntry.Name.Add("kr", title);

                gameEntry.ReleaseDate = Assign <DateTime>(game["release_date"]);

                string desc = game["overview"].ToString();
                gameEntry.Description.Add("jp", desc);
                gameEntry.Description.Add("en", desc);
                gameEntry.Description.Add("fr", desc);
                gameEntry.Description.Add("it", desc);
                gameEntry.Description.Add("de", desc);
                gameEntry.Description.Add("es", desc);
                gameEntry.Description.Add("cn", desc);
                gameEntry.Description.Add("kr", desc);

                List <string> publisherNames = new List <string>();
                if (game["publishers"].Count() > 0)
                {
                    foreach (var publisher in game["publishers"])
                    {
                        publisherNames.Add(allPublishers["data"]["publishers"][publisher.ToString()]["name"].ToString().ToUpper());
                    }
                }
                gameEntry.Copyright = string.Join(",", publisherNames);

                string boxBaseUrl = Assign <string>(scrapedGames["include"]["boxart"]["base_url"]["thumb"]);
                string boxName    = string.Empty;
                string gameId     = Assign <string>(game["id"]);
                if (scrapedGames["include"]["boxart"]["data"][gameId] != null)
                {
                    boxName = Assign <string>(scrapedGames["include"]["boxart"]["data"][gameId]
                                              .Where(c => c["side"].ToString().Equals("front"))
                                              .FirstOrDefault()["filename"]);
                }

                int numPlayers = Assign <int>(game["players"]);
                gameEntry.PlayerNum = (numPlayers > 0 ? numPlayers - 1 : 0);
                if (!game["genres"].ToString().Equals(string.Empty))
                {
                    gameEntry.Genre = genreMapping[Assign <int>(game["genres"][0])];
                }

                if (boxName.Equals(string.Empty))
                {
                    continue;
                }

                try
                {
                    Stream boxArtData = null;
                    using (HttpClient httpClient = new HttpClient())
                    {
                        boxArtData = httpClient.GetStreamAsync($"{boxBaseUrl}{boxName}").Result;
                    }

                    gameEntry.CoverFront = new Bitmap(boxArtData);


                    Stream clearLogoData = null;
                    using (HttpClient httpClient = new HttpClient())
                    {
                        string logoJson = httpClient.GetStringAsync($"https://api.thegamesdb.net/Games/Images?apikey={apiKey}&games_id={gameId}&filter%5Btype%5D=clearlogo").Result;
                        //string logoJson = "{\"code\":200,\"status\":\"Success\",\"data\":{\"count\":1,\"base_url\":{\"original\":\"https://cdn.thegamesdb.net/images/original/\",\"small\":\"https://cdn.thegamesdb.net/images/small/\",\"thumb\":\"https://cdn.thegamesdb.net/images/thumb/\",\"cropped_center_thumb\":\"https://cdn.thegamesdb.net/images/cropped_center_thumb/\",\"medium\":\"https://cdn.thegamesdb.net/images/medium/\",\"large\":\"https://cdn.thegamesdb.net/images/large/\"},\"images\":{\"691\":[{\"id\":45225,\"type\":\"clearlogo\",\"side\":null,\"filename\":\"clearlogo/691.png\",\"resolution\":\"400x159\"}]}},\"pages\":{\"previous\":null,\"current\":\"https://api.thegamesdb.net/Games/Images?apikey={apiKey}&games_id=691&filter%5Btype%5D=clearlogo&page=1\",\"next\":null},\"remaining_monthly_allowance\":1473,\"extra_allowance\":0,\"allowance_refresh_timer\":2441138}";

                        JObject logoObject = JObject.Parse(logoJson);

                        string spineBaseUrl = logoObject["data"]["base_url"]["original"].ToString();

                        if (logoObject["data"]["images"].Count() > 0)
                        {
                            string spineName = logoObject["data"]["images"][gameId][0]["filename"].ToString();
                            clearLogoData = httpClient.GetStreamAsync($"{spineBaseUrl}{spineName}").Result;
                        }
                    }

                    if (clearLogoData != null)
                    {
                        Bitmap logoBmp = new Bitmap(clearLogoData);
                    }
                }
                catch { }

                gamesList.Add(gameEntry);
            }

            if (gamesList.Count == 0)
            {
                throw new KeyNotFoundException("No games found. Try using less keywords.");
            }

            return(gamesList);
        }
Ejemplo n.º 3
0
 public Bitmap GetGameImage(ScraperData gameEntry, string region, GameImageType imageType)
 {
     return(GetGameImage(gameEntry.ScrapedGameData, region, imageType));
 }
Ejemplo n.º 4
0
        public Bitmap GetGameImage(ScraperData gameEntry, string region, GameImageType imageType)
        {
            JObject scrapedGames = gameEntry.ScrapedGameData;

            string platformId = GetPlatformId(gameEntry.System);

            JToken game = scrapedGames["data"]["games"].Where(c => c["game_title"].ToString().Equals(gameEntry.Name["en"]) &&
                                                              c["platform"].ToString().Equals(platformId))
                          .FirstOrDefault();

            string gameId = Assign <string>(game["id"]);

            switch (imageType)
            {
            case GameImageType.CoverFront:
                string boxBaseUrl = Assign <string>(scrapedGames["include"]["boxart"]["base_url"]["thumb"]);
                string boxName    = string.Empty;
                if (scrapedGames["include"]["boxart"]["data"][gameId] != null)
                {
                    boxName = Assign <string>(scrapedGames["include"]["boxart"]["data"][gameId]
                                              .Where(c => c["side"].ToString().Equals("front"))
                                              .FirstOrDefault()["filename"]);
                }
                if (boxName.Equals(string.Empty))
                {
                    return(null);
                }
                try
                {
                    Stream boxArtData = null;
                    using (HttpClient httpClient = new HttpClient())
                    {
                        boxArtData = httpClient.GetStreamAsync($"{boxBaseUrl}{boxName}").Result;
                    }

                    return(new Bitmap(boxArtData));
                }
                catch { }
                break;

            case GameImageType.CoverSpine:
                return(null);

            case GameImageType.CoverBack:
                return(null);

            case GameImageType.ClearLogo:
                try
                {
                    Stream clearLogoData = null;
                    using (HttpClient httpClient = new HttpClient())
                    {
                        string apiKey   = Encoding.ASCII.GetString(Scraper.Properties.Resources.tgdb);
                        string logoJson = httpClient.GetStringAsync($"https://api.thegamesdb.net/v1/Games/Images?apikey={apiKey}&games_id={gameId}&filter%5Btype%5D=clearlogo").Result;
                        //string logoJson = "{\"code\":200,\"status\":\"Success\",\"data\":{\"count\":1,\"base_url\":{\"original\":\"https://cdn.thegamesdb.net/images/original/\",\"small\":\"https://cdn.thegamesdb.net/images/small/\",\"thumb\":\"https://cdn.thegamesdb.net/images/thumb/\",\"cropped_center_thumb\":\"https://cdn.thegamesdb.net/images/cropped_center_thumb/\",\"medium\":\"https://cdn.thegamesdb.net/images/medium/\",\"large\":\"https://cdn.thegamesdb.net/images/large/\"},\"images\":{\"691\":[{\"id\":45225,\"type\":\"clearlogo\",\"side\":null,\"filename\":\"clearlogo/691.png\",\"resolution\":\"400x159\"}]}},\"pages\":{\"previous\":null,\"current\":\"https://api.thegamesdb.net/Games/Images?apikey={apiKey}&games_id=691&filter%5Btype%5D=clearlogo&page=1\",\"next\":null},\"remaining_monthly_allowance\":1473,\"extra_allowance\":0,\"allowance_refresh_timer\":2441138}";

                        JObject logoObject = JObject.Parse(logoJson);

                        string spineBaseUrl = logoObject["data"]["base_url"]["original"].ToString();

                        if (logoObject["data"]["images"].Count() > 0)
                        {
                            string spineName = logoObject["data"]["images"][gameId][0]["filename"].ToString();
                            clearLogoData = httpClient.GetStreamAsync($"{spineBaseUrl}{spineName}").Result;
                        }
                    }

                    if (clearLogoData != null)
                    {
                        return(new Bitmap(clearLogoData));
                    }
                }
                catch { }
                break;

            case GameImageType.TitleScreen:
                return(null);
            }

            return(null);
        }