/* METHODS */ /// <summary> /// saves scraped data object to json in the gamedata directory /// </summary> /// <param name="o"></param> public static void SaveJson(ScrapedGameObjectWeb o) { string gPath = AppDomain.CurrentDomain.BaseDirectory + @"Data\Games\" + o.GdbId.ToString() + @"\" + o.GdbId.ToString() + ".json"; string json = JsonConvert.SerializeObject(o, Formatting.Indented); File.WriteAllText(gPath, json); }
/// <summary> /// Takes a finished ScrapedGameObject and downloads all media present in it /// </summary> /// <param name="o"></param> /// <param name="controller"></param> public static void ContentDownloadManager(ScrapedGameObjectWeb o, ProgressDialogController controller, string message) { string baseDir = ScrapeDB.BaseContentDirectory + @"\" + o.GdbId.ToString() + @"\"; int total; int count; // screenshots if (o.Screenshots != null && o.Screenshots.Count > 0) { total = o.Screenshots.Count; count = 1; controller.SetMessage(message + "Downloading Screenshots for: " + o.Data.Title); foreach (string s in o.Screenshots) { controller.SetMessage(message + "Downloading content for: " + o.Data.Title + "\nScreenshot: " + count + " of " + total + "\n(" + s + ")"); DownloadFile(s, baseDir + "Screenshots"); count++; } } // fanart if (o.FanArts != null && o.FanArts.Count > 0) { total = o.FanArts.Count; count = 1; controller.SetMessage(message + "Downloading FanArt for: " + o.Data.Title); foreach (string s in o.FanArts) { controller.SetMessage(message + "Downloading content for: " + o.Data.Title + "\nFanart: " + count + " of " + total + "\n(" + s + ")"); DownloadFile(s, baseDir + "FanArt"); count++; } } // medias if (o.Medias != null && o.Medias.Count > 0) { total = o.Medias.Count; count = 1; controller.SetMessage(message + "Downloading Media for: " + o.Data.Title); foreach (string s in o.Medias) { controller.SetMessage(message + "Downloading content for: " + o.Data.Title + "\nMedia: " + count + " of " + total + "\n(" + s + ")"); DownloadFile(s, baseDir + "Media"); count++; } } // front boxart if (o.FrontCovers != null && o.FrontCovers.Count > 0) { total = o.FrontCovers.Count; count = 1; controller.SetMessage(message + "Downloading Front Box Art for: " + o.Data.Title); foreach (string s in o.FrontCovers) { controller.SetMessage(message + "Downloading content for: " + o.Data.Title + "\nFront Cover: " + count + " of " + total + "\n(" + s + ")"); DownloadFile(s, baseDir + "FrontCover"); count++; } } // back boxart if (o.BackCovers != null && o.BackCovers.Count > 0) { controller.SetMessage(message + "Downloading Back Box Art for: " + o.Data.Title); total = o.BackCovers.Count; count = 1; foreach (string s in o.BackCovers) { controller.SetMessage(message + "Downloading content for: " + o.Data.Title + "\nBack Cover: " + count + " of " + total + "\n(" + s + ")"); DownloadFile(s, baseDir + "BackCover"); count++; } } // banners if (o.Banners != null && o.Banners.Count > 0) { total = o.Banners.Count; count = 1; controller.SetMessage(message + "Downloading Banners for: " + o.Data.Title); foreach (string s in o.Banners) { controller.SetMessage(message + "Downloading content for: " + o.Data.Title + "\nBanner: " + count + " of " + total + "\n(" + s + ")"); DownloadFile(s, baseDir + "Banners"); count++; } } // manuals if (o.Manuals != null && o.Manuals.Count > 0) { total = o.Manuals.Count; count = 1; controller.SetMessage(message + "Downloading Manuals for: " + o.Data.Title); foreach (string s in o.Manuals) { controller.SetMessage(message + "Downloading content for: " + o.Data.Title + "\nManual: " + count + " of " + total + "\n(" + s + ")"); DownloadFile(s, baseDir + "Manual"); count++; } } }
/// <summary> /// Game scraping logic /// </summary> /// <param name="controller"></param> public ScrapedGameObjectWeb ScrapeGameInspector(ProgressDialogController controller) { string message = ""; // create data object for results that are returned //ScrapeDB glsc = new ScrapeDB(); ScrapedGameData gameData = new ScrapedGameData(); ScrapedGameObjectWeb gameObject = new ScrapedGameObjectWeb(); gameObject.Data = gameData; gameObject.GdbId = MasterRecord.gid; // check for manuals if (_GlobalSettings.scrapeManuals == true) { if (gameObject.Manuals == null) { gameObject.Manuals = new List <string>(); } gameObject.Manuals = MasterRecord.Game_Docs; } // enumerate globalsettings switch (_GlobalSettings.primaryScraper) { case 1: // gamesdb.net is primary scraper GDBScraper.ScrapeGame(gameObject, ScraperOrder.Primary, controller, MasterRecord, message); if (_GlobalSettings.enabledSecondaryScraper == true) { MobyScraper.ScrapeGame(gameObject, ScraperOrder.Secondary, controller, MasterRecord, message); } break; case 2: // moby is primary scraper MobyScraper.ScrapeGame(gameObject, ScraperOrder.Primary, controller, MasterRecord, message); if (_GlobalSettings.enabledSecondaryScraper == true) { GDBScraper.ScrapeGame(gameObject, ScraperOrder.Secondary, controller, MasterRecord, message); } break; } if (controller.IsCanceled == true) { controller.CloseAsync(); return(null); } // gameObject should now be populated - create folder structure on disk if it does not already exist controller.SetMessage(message + "Determining local folder structure"); ScrapeDB.CreateFolderStructure(gameObject.GdbId); // save the object to json controller.SetMessage(message + "Saving game information"); ScrapeDB.SaveJson(gameObject); // Download all the files if (_GlobalSettings.scrapeBanners == true || _GlobalSettings.scrapeBoxart == true || _GlobalSettings.scrapeFanart == true || _GlobalSettings.scrapeManuals == true || _GlobalSettings.scrapeMedia == true || _GlobalSettings.scrapeScreenshots == true) { controller.SetMessage(message + "Downloading media"); ContentDownloadManager(gameObject, controller, message + "Downloading media...\n"); } // Return data return(gameObject); //PopulateLibraryData(GameId, gameObject.GdbId); //CreateDatabaseLink(GameId, gameObject.GdbId); }
/// <summary> /// looks up and returns scrapeddataobject based on Internal GameId (not gamesdb id) /// </summary> /// <param name="GameId"></param> /// <param name="GdbId"></param> /// <returns></returns> public static ScrapedGameObject GetScrapedGameObject(int GameId, int GdbId) { //Game link = Game.GetGame(GameId); // we have a link record - proceed and generate object ScrapedGameObject sgo = new ScrapedGameObject(); if (GdbId < 1) { return(null); } sgo.GdbId = GdbId; // attempt to load game data json string gPath = AppDomain.CurrentDomain.BaseDirectory + @"Data\Games\" + sgo.GdbId.ToString() + @"\" + sgo.GdbId.ToString() + ".json"; if (File.Exists(gPath)) { ScrapedGameObjectWeb sgoweb = new ScrapedGameObjectWeb(); ScrapedGameData sg = new ScrapedGameData(); string jsonString = File.ReadAllText(gPath); try { sgoweb = JsonConvert.DeserializeObject <ScrapedGameObjectWeb>(jsonString); } catch (Exception e) { // there was a problem with the file - do nothing Console.WriteLine(e); } finally { sgo.Data = sgoweb.Data; if (sgo.Data.AlternateTitles == null) { sgo.Data.AlternateTitles = new List <string>(); } if (sgo.Data.Genres == null) { sgo.Data.AlternateTitles = new List <string>(); } } } else { sgo.Data = new ScrapedGameData(); } // populate lists in object string baseGameDir = AppDomain.CurrentDomain.BaseDirectory + @"Data\Games\" + sgo.GdbId.ToString(); sgo.BackCovers = GetAllFolderFiles(baseGameDir + @"\BackCover"); sgo.Banners = GetAllFolderFiles(baseGameDir + @"\Banners"); sgo.FanArts = GetAllFolderFiles(baseGameDir + @"\FanArt"); sgo.FrontCovers = GetAllFolderFiles(baseGameDir + @"\FrontCover"); sgo.Manuals = GetAllFolderFiles(baseGameDir + @"\Manual"); sgo.Medias = GetAllFolderFiles(baseGameDir + @"\Media"); sgo.Screenshots = GetAllFolderFiles(baseGameDir + @"\Screenshots"); // return object return(sgo); }