示例#1
0
        public int ScrapeBanner()
        {
            using (WebClient webclient = new WebClient())
            {
                if (!File.Exists(BannerPath))
                {
                    if (BannerURL != null)
                    {
                        Reporter.Report("Getting banner for LB release " + Title + "...");

                        if (webclient.DownloadFileFromDB(BannerURL, BannerPath))
                        {
                            Reporter.ReportInline("success!");
                            OnPropertyChanged("BannerPath");
                        }
                        else
                        {
                            Reporter.ReportInline("dammit!");
                            return(-1);
                        }
                    }

                    else
                    {
                        Reporter.Report("No banner URL exists for LB release " + Title);
                    }
                }

                else
                {
                    Reporter.Report("File already exists.");
                }
            }
            return(0);
        }
示例#2
0
        public int ScrapeMarquee()
        {
            using (WebClient webclient = new WebClient())
            {
                if (!File.Exists(MarqueePath))
                {
                    if (MarqueeURL != null)
                    {
                        Reporter.Report("Getting marquee art for LB Release " + Title + "...");

                        if (webclient.DownloadFileFromDB(MarqueeURL, MarqueePath))
                        {
                            Reporter.ReportInline("success!");
                            OnPropertyChanged("MarqueePath");
                        }
                        else
                        {
                            Reporter.ReportInline("dammit!");
                            return(-1);
                        }
                    }

                    else
                    {
                        Reporter.Report("No marquee art URL exists for LB release" + Title);
                    }
                }

                else
                {
                    Reporter.Report("File already exists.");
                }
            }
            return(0);
        }
示例#3
0
        public int ScrapeScreen()
        {
            using (WebClient webclient = new WebClient())
            {
                if (!File.Exists(ScreenPath))
                {
                    if (ScreenURL != null)
                    {
                        Reporter.Report("Getting screen shot for LB Release " + Title + "...");

                        if (webclient.DownloadFileFromDB(ScreenURL, ScreenPath))
                        {
                            Reporter.ReportInline("success!");
                            OnPropertyChanged("ScreenPath");
                        }
                        else
                        {
                            Reporter.ReportInline("dammit!");
                            return(-1);
                        }
                    }

                    else
                    {
                        Reporter.Report("No screen shot URL exists for LB release" + Title);
                    }
                }

                else
                {
                    Reporter.Report("File already exists.");
                }
            }
            return(0);
        }
示例#4
0
        public int ScrapeControlPanel()
        {
            using (WebClient webclient = new WebClient())
            {
                if (!File.Exists(ControlPanelPath))
                {
                    if (ControlPanelURL != null)
                    {
                        Reporter.Report("Getting control panel art for LB Release " + Title + "...");

                        if (webclient.DownloadFileFromDB(ControlPanelURL, ControlPanelPath))
                        {
                            Reporter.ReportInline("success!");
                            OnPropertyChanged("ControlPanelPath");
                        }
                        else
                        {
                            Reporter.ReportInline("dammit!");
                            return(-1);
                        }
                    }

                    else
                    {
                        Reporter.Report("No control panel art URL exists for LB release" + Title);
                    }
                }

                else
                {
                    Reporter.Report("File already exists.");
                }
            }
            return(0);
        }
示例#5
0
        public int ScrapeLogo()
        {
            using (WebClient webclient = new WebClient())
            {
                if (!File.Exists(LogoPath))
                {
                    if (BoxFrontURL != null)
                    {
                        Reporter.Report("Getting clear logo for LB Release " + Title + "...");

                        if (webclient.DownloadFileFromDB(LogoURL, LogoPath))
                        {
                            Reporter.ReportInline("success!");
                            OnPropertyChanged("LogoPath");
                        }
                        else
                        {
                            Reporter.ReportInline("dammit!");
                            return(-1);
                        }
                    }

                    else
                    {
                        Reporter.Report("No clear logo URL exists for LB release" + Title);
                    }
                }

                else
                {
                    Reporter.Report("File already exists.");
                }
            }
            return(0);
        }
        public int ScrapeBoxBack()
        {
            using (WebClient webclient = new WebClient())
            {
                if (!File.Exists(BoxBackPath))
                {
                    if (BoxFrontURL != null)
                    {
                        Reporter.Report("Getting front box art for OVGRelease " + Title + "...");

                        if (webclient.DownloadFileFromDB(BoxBackURL, BoxBackPath))
                        {
                            Reporter.ReportInline("success!");
                            OnPropertyChanged("BoxBackPath");
                        }
                        else
                        {
                            Reporter.ReportInline("dammit!");
                            return(-1);
                        }
                    }

                    else
                    {
                        Reporter.Report("No back box art URL exists.");
                    }
                }

                else
                {
                    Reporter.Report("File already exists.");
                }
            }
            return(0);
        }
示例#7
0
        public int ScrapeCart3D()
        {
            using (WebClient webclient = new WebClient())
            {
                if (!File.Exists(Cart3DPath))
                {
                    if (BoxFrontURL != null)
                    {
                        Reporter.Report("Getting 3D cartridge art for LB release " + Title + "...");

                        if (webclient.DownloadFileFromDB(Cart3DURL, Cart3DPath))
                        {
                            Reporter.ReportInline("success!");
                            OnPropertyChanged("Cart3DPath");
                        }
                        else
                        {
                            Reporter.ReportInline("dammit!");
                            return(-1);
                        }
                    }

                    else
                    {
                        Reporter.Report("No 3D cartridge art URL exists for LB release" + Title);
                    }
                }

                else
                {
                    Reporter.Report("File already exists.");
                }
            }
            return(0);
        }
        /// <summary>
        /// SUb function to scrape art based on strings computed elsewhere.
        /// </summary>
        /// <param name="url">URL to scrape art from.</param>
        /// <param name="filePath">Path to download art to.</param>
        /// <param name="property">Property of this release to notify PropertyChanged if art is downloaded.</param>
        /// <param name="description">String describing the art to download.</param>
        /// <returns>Returns -1 if artwork to indicate the scrape attempt could be tried again, or 0 if the scrape attempt is successfull.</returns>
        int Scrape(string url, string filePath, string property, string description)
        {
            using (WebClient webclient = new WebClient())
            {
                if (!File.Exists(filePath))
                {
                    if (url != null)
                    {
                        Reporter.Report($"Getting {description} art for {Title}...");

                        if (webclient.DownloadFileFromDB(url, filePath))
                        {
                            Reporter.ReportInline("success!");
                            if (property == "BoxFrontPath")
                            {
                                CreateThumbnail();
                            }
                            OnPropertyChanged(property);
                            Game.OnPropertyChanged2(property);
                        }
                        else
                        {
                            Reporter.ReportInline("dammit!");
                            return(-1);
                        }
                    }
                }
            }

            return(0);
        }
 public void CopyData()
 {
     // TODO: Does this function even work? Is it even hooked-up to a button?
     Reporter.Report("Getting data...");
     foreach (Release release in R.Data.Releases)
     {
         release.CopyData();
     }
     Reporter.ReportInline("finished.");
 }
        async void GetAllData()
        {
            // TODO: make this good for any idbobject and add get selected data command
            Stopwatch Watch  = Stopwatch.StartNew();
            Stopwatch Watch1 = Stopwatch.StartNew();

            int j = 0;

            await Task.Run(() =>
            {
                Reporter.Report("Opening local cache...");

                R.Data.GBReleases.Load();
                R.Data.GDBReleases.Load();
                R.Data.OVGReleases.Load();
                R.Data.LBReleases.Include(x => x.LBGame).Load();
                Reporter.ReportInline(Watch.Elapsed.ToString("ss") + " s");
                Watch.Restart();

                int count = R.Data.Releases.Count();
                foreach (Release release in R.Data.Releases)
                {
                    if (j++ % (count / 10) == 0)
                    {
                        Reporter.Report("Copying " + j + @" / " + count + " " + Watch.Elapsed.ToString(@"m\:ss") + " elapsed.");
                        Watch.Restart();
                    }
                    release.CopyData();
                }
            });

            Datomatic datomatic = new Datomatic();

            datomatic.ReportUpdates(true);
            R.Data.Save(false);
        }
示例#11
0
        /// <summary>
        /// Implement IDB.CachePlatfomrReleases(). Go out to giantbomb.com and cache all known releases for the specified platform. Update the list of releases and store metadata for each one.
        /// </summary>
        /// <param name="platform">Robin.Platform associated with the GBPlatform to cache.</param>
        public void CachePlatformReleases(Platform platform, bool reset = false)
        {
            using (WebClient webClient = new WebClient())
            {
                GBPlatform gbPlatform = platform.GBPlatform;
                string     startDate  = reset ? @"1900-01-01 01:01:01" : gbPlatform.CacheDate.ToString(DATEFORMAT);
                string     endDate    = DateTime.Now.ToString(DATEFORMAT);

                int       N_results;
                bool      haveResults;
                XDocument xdoc;
                Reporter.Report($"Checking GiantBomb for {gbPlatform.Title} releases...");

                string url = $"http://www.giantbomb.com/api/releases/?api_key={Keys.GiantBomb}&filter=date_last_updated:{startDate}|{endDate},platform:{gbPlatform.ID}&field_list=id&sort=id:asc";

                if (webClient.SafeDownloadStringDB(url, out string downloadText))
                {
                    xdoc        = XDocument.Parse(downloadText);
                    haveResults = int.TryParse(xdoc.SafeGetB("number_of_total_results"), out N_results);
                }
                else
                {
                    Reporter.Warn("Error communicating with GiantBomb.");
                    return;
                }

                // If there are results, go through them
                if (haveResults && N_results != 0)
                {
                    Dictionary <long, GBRelease> existingGbReleaseDict = R.Data.GBReleases.ToDictionary(x => x.ID);
                    ILookup <long?, Release>     releaseLookupByGB_ID  = R.Data.Releases.Where(x => x.ID_GB != null).ToLookup(x => x.ID_GB);
                    HashSet <GBRelease>          newGbReleases         = new HashSet <GBRelease>();

                    int N_pages = N_results / 100;
                    Reporter.Report($"Found {N_results} {gbPlatform.Title} releases in GiantBomb");

                    // Just do the first page again to save code then go through the rest of the results
                    Reporter.Report("Loading sheet ");
                    for (int i = 0; i <= N_pages; i++)
                    {
                        Reporter.ReportInline(" " + i);
                        url = $"http://www.giantbomb.com/api/releases/?api_key={Keys.GiantBomb}&filter=date_last_updated:{startDate}|{endDate}platform:{gbPlatform.ID}&offset={i * 100}&field_list=id,deck,game,image,region,name,maximum_players,release_date&sort=id:asc";

                        // Put results into the GB Cache database
                        if (webClient.SafeDownloadStringDB(url, out downloadText))
                        {
                            xdoc = XDocument.Parse(downloadText);

                            foreach (XElement element in xdoc.Root.Element("results").Elements("release"))
                            {
                                // If the ID XML value was found
                                if (int.TryParse(element.SafeGetA("id"), out int id))
                                {
                                    // Don't create this game if the title is null
                                    string title = element.SafeGetA("name");
                                    if (string.IsNullOrEmpty(title))
                                    {
                                        continue;
                                    }

                                    // Check if GBRelease is in database prior to this update, else add it
                                    if (!existingGbReleaseDict.TryGetValue(id, out GBRelease gbRelease))
                                    {
                                        gbRelease = new GBRelease {
                                            ID = id, GBPlatform = platform.GBPlatform
                                        };
                                        newGbReleases.Add(gbRelease);
                                    }

                                    // If a release has changed platforms, catch it and zero out match
                                    if (gbRelease.GBPlatform_ID != gbPlatform.ID)
                                    {
                                        gbRelease.GBPlatform_ID = gbPlatform.ID;

                                        if (releaseLookupByGB_ID[gbRelease.ID].Any())
                                        {
                                            foreach (Release release in releaseLookupByGB_ID[gbRelease.ID])
                                            {
                                                release.ID_GB = null;
                                            }
                                        }
                                    }

                                    gbRelease.Title    = title;
                                    gbRelease.Overview = element.SafeGetA("deck");
                                    if (int.TryParse(element.SafeGetA("game", "id"), out id))
                                    {
                                        gbRelease.GBGame_ID = id;
                                    }
                                    if (int.TryParse(element.SafeGetA("maximum_players"), out id))
                                    {
                                        gbRelease.Players = id.ToString();
                                    }

                                    gbRelease.GBPlatform_ID = gbPlatform.ID;
                                    if (int.TryParse(element.SafeGetA("region", "id"), out id))
                                    {
                                        gbRelease.Region = R.Data.Regions.FirstOrDefault(x => x.ID_GB == id) ?? R.Data.Regions.FirstOrDefault(x => x.Title.Contains("Unk"));
                                    }

                                    gbRelease.Date      = DateTimeRoutines.SafeGetDate(element.SafeGetA("release_date"));
                                    gbRelease.BoxURL    = element.SafeGetA("image", "medium_url");
                                    gbRelease.ScreenURL = element.SafeGetA("image", "screen_url");
                                }
                            }
                        }
                        else
                        {
                            Reporter.Warn("Failure connecting to GiantBomb");
                            return;
                        }
                    }
                    R.Data.GBReleases.AddRange(newGbReleases);
                    Reporter.ReportInline("Finished.");
                }
                else
                {
                    Reporter.Report("No releases returned by GiantBomb");
                    return;
                }
            }            // end using webclient
        }
示例#12
0
        public void CachePlatformGames(Platform platform, bool reset = false)
        {
            GBPlatform gbPlatform = platform.GBPlatform;
            string     startDate  = reset ? @"1900-01-01 01:01:01" : gbPlatform.CacheDate.ToString(DATEFORMAT);
            string     endDate    = DateTime.Now.ToString(DATEFORMAT);

            using (WebClient webClient = new WebClient())
            {
                int       N_results;
                bool      haveResults;
                XDocument xdoc;
                Reporter.Report("Checking GiantBomb for " + platform.Title + " games");

                var url = $"http://www.giantbomb.com/api/games/?api_key={Keys.GiantBomb}&filter=date_last_updated:{startDate}|{endDate},platforms:{gbPlatform.ID}&field_list=id&sort=id:asc";


                if (webClient.SafeDownloadStringDB(url, out var downloadText))
                {
                    xdoc        = XDocument.Parse(downloadText);
                    haveResults = int.TryParse(xdoc.SafeGetB("number_of_total_results"), out N_results);
                }
                else
                {
                    Reporter.Report("Error communicating with GiantBomb.");
                    return;
                }

                // If there are results, go through them
                if (haveResults && N_results != 0)
                {
                    int N_pages = N_results / 100;
                    Reporter.Report("Found " + N_results + " games in GiantBomb");

                    Reporter.Report("Loading sheet ");
                    // Just do the first page again to save code then go through the rest of the results
                    for (int i = 0; i <= N_pages; i++)
                    {
                        Reporter.ReportInline(i + " ");

                        url = $"http://www.giantbomb.com/api/games/?api_key={Keys.GiantBomb}&filter=date_last_updated:{startDate}|{endDate},platforms:{gbPlatform.ID}&offset={i * 100}&field_list=id,deck,developers,publishers,genres,image,name,release_date&sort=id:asc";

                        // Put results into the GB Cache database
                        if (webClient.SafeDownloadStringDB(url, out downloadText))
                        {
                            xdoc = XDocument.Parse(downloadText);
                            foreach (XElement element in xdoc.Root.Element("results").Elements("game"))
                            {
                                // If the ID XML value was found
                                if (int.TryParse(element.SafeGetA("id"), out var intCatcher))
                                {
                                    GBGame gbGame = R.Data.GBGames.FirstOrDefault(x => x.ID == intCatcher);

                                    if (gbGame == null)
                                    {
                                        gbGame = new GBGame {
                                            ID = intCatcher
                                        };
                                        gbPlatform.GBGames.Add(gbGame);
                                    }

                                    gbGame.Title         = element.SafeGetA("name");
                                    gbGame.Overview      = element.SafeGetA("deck");
                                    gbGame.GBPlatform_ID = gbPlatform.ID;
                                    gbGame.Date          = DateTimeRoutines.SafeGetDate(element.SafeGetA("release_date"));
                                    gbGame.BoxFrontURL   = element.SafeGetA("image", "medium_url");
                                    gbGame.ScreenURL     = element.SafeGetA("image", "screen_url");
                                }
                            }
                        }
                        else
                        {
                            Reporter.Warn("Failure connecting to GiantBomb");
                            return;
                        }
                    }

                    Reporter.Report("Finished.");
                }
                else
                {
                    Reporter.Report("No results returned by GiantBomb");
                    return;
                }
            }            // end using webclient
        }