Exemplo n.º 1
0
        /// <summary>
        /// Gets the data for a specific game.
        /// </summary>
        /// <param name="ID">The game ID to return data for</param>
        /// <returns>A Game-object containing all the data about the game, or null if no game was found</returns>
        public static GDBNETGame GetGame(int ID)
        {
            WebOps wo = new WebOps();

            wo.Params  = "/GetGame.php?id=" + ID;
            wo.Timeout = 30000;
            string result = wo.ApiCall();

            // save to xml locally
            //GamesLibraryScrapedContent glsc = new Classes.GamesLibraryScrapedContent();
            //glsc.CreateFolderStructure(ID);
            //File.WriteAllText(System.AppDomain.CurrentDomain.BaseDirectory + @"\Data\Graphics\thegamesdb\" + ID + @"\" + ID  + "-external.xml", result);

            /*
             * wo.GDBApiCall();
             * if (wo.BodyAsString == null)
             * {
             *  // no body returned within the specified timeout periods
             *  return null;
             * }
             */

            // string returned
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(result);

            /*
             * XmlDocument doc = new XmlDocument();
             * try
             * {
             *  doc.Load(@"http://thegamesdb.net/api/GetGame.php?id=" + ID);
             * }
             *
             * catch (Exception ex)
             * {
             *  return new GDBNETGame();
             * }
             * finally { }
             */

            XmlNode     root  = doc.DocumentElement;
            IEnumerator ienum = root.GetEnumerator();

            XmlNode    platformNode = root.FirstChild.NextSibling;
            GDBNETGame game         = new GDBNETGame();

            IEnumerator ienumGame = platformNode.GetEnumerator();
            XmlNode     attributeNode;

            while (ienumGame.MoveNext())
            {
                attributeNode = (XmlNode)ienumGame.Current;

                // Iterate through all platform attributes
                switch (attributeNode.Name)
                {
                case "id":
                    int.TryParse(attributeNode.InnerText, out game.ID);
                    break;

                case "Overview":
                    game.Overview = attributeNode.InnerText;
                    break;

                case "GameTitle":
                    game.Title = attributeNode.InnerText;
                    break;

                case "Platform":
                    game.Platform = attributeNode.InnerText;
                    break;

                case "ReleaseDate":
                    game.ReleaseDate = attributeNode.InnerText;
                    break;

                case "overview":
                    game.Overview = attributeNode.InnerText;
                    break;

                case "ESRB":
                    game.ESRB = attributeNode.InnerText;
                    break;

                case "Players":
                    game.Players = attributeNode.InnerText;
                    break;

                case "Co-op":
                    game.Coop = attributeNode.InnerText;
                    break;

                case "Publisher":
                    game.Publisher = attributeNode.InnerText;
                    break;

                case "Developer":
                    game.Developer = attributeNode.InnerText;
                    break;

                case "Rating":
                    //double.TryParse(attributeNode.InnerText, out game.Rating);
                    game.Rating = attributeNode.InnerText;
                    break;

                case "AlternateTitles":
                    IEnumerator ienumAlternateTitles = attributeNode.GetEnumerator();
                    while (ienumAlternateTitles.MoveNext())
                    {
                        game.AlternateTitles.Add(((XmlNode)ienumAlternateTitles.Current).InnerText);
                    }
                    break;

                case "Genres":
                    IEnumerator ienumGenres = attributeNode.GetEnumerator();
                    while (ienumGenres.MoveNext())
                    {
                        game.Genres.Add(((XmlNode)ienumGenres.Current).InnerText);
                    }
                    break;

                case "Images":
                    game.Images.FromXmlNode(attributeNode);
                    break;
                }
            }

            return(game);
        }
Exemplo n.º 2
0
        public static ScrapedGameObjectWeb ScrapeGame(ScrapedGameObjectWeb o, ScraperOrder order, ProgressDialogController controller, ScraperMaster masterrecord, string message)
        {
            bool priority;

            message = message + "Downloading information for: " + masterrecord.TGDBData.GamesDBTitle + "\n(" + masterrecord.TGDBData.GamesDBPlatformName + ")";
            if (order == ScraperOrder.Primary)
            {
                message = "Primary Scraping (thegamesdb)\n" + message;
            }
            else
            {
                message = "Secondary Scraping (thegamesdb)\n" + message;
            }
            string BaseImgUrl = "http://thegamesdb.net/banners/";

            GlobalSettings gs = GlobalSettings.GetGlobals();

            if (order == ScraperOrder.Primary)
            {
                controller.SetMessage(message);
                priority         = true; // primary
                message          =
                    o.Data.Title = masterrecord.TGDBData.GamesDBTitle;
                o.Data.Platform  = masterrecord.TGDBData.GamesDBPlatformName;
            }
            else
            {
                // GDB is secondary scraper
                controller.SetMessage(message);
                priority = false;    // primary
                if (o.Data.Title == null)
                {
                    o.Data.Title = masterrecord.TGDBData.GamesDBTitle;
                }
                if (o.Data.Platform == null)
                {
                    o.Data.Platform = masterrecord.TGDBData.GamesDBPlatformName;
                }
            }

            if (priority == true)
            {
                /* Primary Scraping */

                // get the text data from thegamesdb.net
                GDBNETGame g = new GDBNETGame();
                g = GDBNETGamesDB.GetGame(o.GdbId);

                if (g == null)
                {
                    // Nothing was returned
                    return(o);
                }

                o.Data.AlternateTitles = g.AlternateTitles;
                o.Data.Coop            = g.Coop;
                o.Data.Developer       = g.Developer;
                o.Data.ESRB            = g.ESRB;
                o.Data.Genres          = g.Genres;
                o.Data.Overview        = g.Overview;
                o.Data.Players         = g.Players;
                o.Data.Publisher       = g.Publisher;
                o.Data.Released        = g.ReleaseDate;
                if (gs.scrapeBoxart == true)
                {
                    if (g.Images.BoxartBack != null)
                    {
                        o.BackCovers.Add(BaseImgUrl + g.Images.BoxartBack.Path);
                    }
                    if (g.Images.BoxartFront != null)
                    {
                        o.FrontCovers.Add(BaseImgUrl + g.Images.BoxartFront.Path);
                    }
                }
                if (gs.scrapeBanners == true)
                {
                    foreach (var s in g.Images.Banners)
                    {
                        o.Banners.Add(BaseImgUrl + s.Path);
                    }
                }
                if (gs.scrapeFanart == true)
                {
                    int co = 0;
                    foreach (var s in g.Images.Fanart)
                    {
                        if (co >= gs.maxFanarts)
                        {
                            break;
                        }
                        o.FanArts.Add(BaseImgUrl + s.Path);
                        co++;
                    }
                }
                if (gs.scrapeScreenshots == true)
                {
                    int co = 0;
                    foreach (var s in g.Images.Screenshots)
                    {
                        if (co >= gs.maxScreenshots)
                        {
                            break;
                        }
                        o.Screenshots.Add(BaseImgUrl + s.Path);
                        co++;
                    }
                }
            }
            else
            {
                /* secondary scraping */

                // get the text data from thegamesdb.net
                GDBNETGame g = new GDBNETGame();
                g = GDBNETGamesDB.GetGame(o.GdbId);

                if (g == null)
                {
                    // Nothing was returned
                    return(o);
                }

                if (o.Data.AlternateTitles == null && g.AlternateTitles.Count > 0)
                {
                    o.Data.AlternateTitles = new List <string>();
                    o.Data.AlternateTitles.AddRange(g.AlternateTitles);
                }

                if (o.Data.Coop == null && g.Coop != null)
                {
                    o.Data.Coop = g.Coop;
                }
                if (o.Data.Developer == null && g.Developer != null)
                {
                    o.Data.Developer = g.Developer;
                }
                if (o.Data.ESRB == null && g.ESRB != null)
                {
                    o.Data.ESRB = g.ESRB;
                }
                if (o.Data.Genres == null && g.Genres != null)
                {
                    o.Data.Genres = new List <string>();
                    o.Data.Genres.AddRange(g.Genres);
                }

                if (o.Data.Overview == null)
                {
                    o.Data.Overview = g.Overview;
                }
                if (o.Data.Players == null)
                {
                    o.Data.Players = g.Players;
                }
                if (o.Data.Publisher == null)
                {
                    o.Data.Publisher = g.Publisher;
                }
                if (o.Data.Released == null)
                {
                    o.Data.Released = g.ReleaseDate;
                }
                if (gs.scrapeBoxart == true)
                {
                    if (o.BackCovers.Count == 0 && g.Images.BoxartBack != null)
                    {
                        o.BackCovers.Add(BaseImgUrl + g.Images.BoxartBack.Path);
                    }
                    if (o.FrontCovers.Count == 0 && g.Images.BoxartFront != null)
                    {
                        o.FrontCovers.Add(BaseImgUrl + g.Images.BoxartFront.Path);
                    }
                }
                if (gs.scrapeBanners == true)
                {
                    if (o.Banners.Count == 0 && g.Images.Banners != null)
                    {
                        foreach (var s in g.Images.Banners)
                        {
                            o.Banners.Add(BaseImgUrl + s.Path);
                        }
                    }
                }
                if (gs.scrapeFanart == true)
                {
                    if (o.FanArts.Count == 0 && g.Images.Fanart != null)
                    {
                        int co = 0;
                        foreach (var s in g.Images.Fanart)
                        {
                            if (co >= gs.maxFanarts)
                            {
                                break;
                            }
                            o.FanArts.Add(BaseImgUrl + s.Path);
                            co++;
                        }
                    }
                }
                if (gs.scrapeScreenshots == true && g.Images.Screenshots != null)
                {
                    int co = 0;
                    foreach (var s in g.Images.Screenshots)
                    {
                        if (co >= gs.maxScreenshots)
                        {
                            break;
                        }
                        o.Screenshots.Add(BaseImgUrl + s.Path);
                        co++;
                    }
                }

                // remove duplicates
                //o.Data.AlternateTitles.Distinct();
                o.Data.Genres.Distinct();
                o.Screenshots.Distinct();
                o.FanArts.Distinct();
                o.Banners.Distinct();
                o.BackCovers.Distinct();
                o.FrontCovers.Distinct();
            }

            return(o);
        }
Exemplo n.º 3
0
        public static GDBNETGame GetGame(string xmlString)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xmlString);
            XmlNode     root  = doc.DocumentElement;
            IEnumerator ienum = root.GetEnumerator();

            XmlNode    platformNode = root.FirstChild.NextSibling;
            GDBNETGame game         = new GDBNETGame();

            IEnumerator ienumGame = platformNode.GetEnumerator();
            XmlNode     attributeNode;

            while (ienumGame.MoveNext())
            {
                attributeNode = (XmlNode)ienumGame.Current;

                // Iterate through all platform attributes
                switch (attributeNode.Name)
                {
                case "id":
                    int.TryParse(attributeNode.InnerText, out game.ID);
                    break;

                case "Overview":
                    game.Overview = attributeNode.InnerText;
                    break;

                case "GameTitle":
                    game.Title = attributeNode.InnerText;
                    break;

                case "Platform":
                    game.Platform = attributeNode.InnerText;
                    break;

                case "ReleaseDate":
                    game.ReleaseDate = attributeNode.InnerText;
                    break;

                case "overview":
                    game.Overview = attributeNode.InnerText;
                    break;

                case "ESRB":
                    game.ESRB = attributeNode.InnerText;
                    break;

                case "Players":
                    game.Players = attributeNode.InnerText;
                    break;

                case "Co-op":
                    game.Coop = attributeNode.InnerText;
                    break;

                case "Publisher":
                    game.Publisher = attributeNode.InnerText;
                    break;

                case "Developer":
                    game.Developer = attributeNode.InnerText;
                    break;

                case "Rating":
                    //double.TryParse(attributeNode.InnerText, out game.Rating);
                    game.Rating = attributeNode.InnerText;
                    break;

                case "AlternateTitles":
                    IEnumerator ienumAlternateTitles = attributeNode.GetEnumerator();
                    while (ienumAlternateTitles.MoveNext())
                    {
                        game.AlternateTitles.Add(((XmlNode)ienumAlternateTitles.Current).InnerText);
                    }
                    break;

                case "Genres":
                    IEnumerator ienumGenres = attributeNode.GetEnumerator();
                    while (ienumGenres.MoveNext())
                    {
                        game.Genres.Add(((XmlNode)ienumGenres.Current).InnerText);
                    }
                    break;

                case "Images":
                    game.Images.FromXmlNode(attributeNode);
                    break;
                }
            }

            return(game);
        }