示例#1
0
 //Function to get a collection of HTML nodes with the different pages indexes
 public void romIndexesFetcher(HtmlNode platformUri, int page)
 {
     this.listRoms = UriContentFetcher.getContent(@"https://www.retrostic.com" + platformUri.Attributes["href"].Value + "/page/" + page,
                                                  "//td[@class='d-block d-sm-none text-center']/a[contains(@href,'/roms/')]",
                                                  true);
     page++;
 }
        //Function to get a HTML site and start downloading the resource (a batch of ROMs or a single one)
        public void romDownloader(HtmlNode node, string platform, string platformDirectory)
        {
            //Variable to contain the URL of the ROM to be downloaded
            string uri = node.Attributes["href"].Value;
            //Variable to contain the data to make a request to the server and get access to the download page
            var sessionData = UriContentFetcher.getContent(@"https://www.retrostic.com" + uri, "//input[@type='hidden']", true);
            //Variable to contain the name of the file as it is downloaded
            var fileNameFetcher = UriContentFetcher.getContent(@"https://www.retrostic.com" + uri, "//td[contains(text(), '.zip') or contains(text(), '.bin')]", false);

            //We check if the ROM is already in such directory (library)
            if (checkFileInDirectory(node, platformDirectory))
            {
                try{
                    //Variable that contains the final site to extract the URL. We should pull a request with data gathered previously and contained in sessionData variable (nodes)
                    string romDownloadPageContent = pullRequest(@"https://www.retrostic.com" + uri + "/download", sessionData[0].Attributes["value"].Value, sessionData[1].Attributes["value"].Value, sessionData[2].Attributes["value"].Value);
                    //Variable that contains the whole script that we will use to extract the URL to download the ROM
                    string romScript = getScript(romDownloadPageContent);
                    //Variable that contains the URL to download the ROM
                    string urlDownload = getDownloadUrl(romScript);

                    //Once we have the URL we create a temp WebClient object to download in sync mode
                    //NOTE: To avoid scraping alert from their server, I rather prefer to download the ROMs in sync mode
                    using (var wClient = new WebClient()){
                        Uri    uriRom   = new Uri(urlDownload);
                        string root     = DirectoryFetcher.currentDirectory + "/roms/" + platform + "/";
                        string fileName = @root + fileNameFetcher.InnerText;

                        try{
                            wClient.DownloadFile(@uriRom, fileName);
                            Thread.Sleep(1000);
                            WriteLine($"Downloading roms for: {platform}");
                            WriteLine($"--- {node.InnerText}");
                            WriteLine($"Downloaded!\n");
                            //Update of the variable to track the number of downloads
                            totalRomsDownloaded++;
                        }
                        catch (Exception e) {
                            WriteLine($"Rom: {node.InnerText} - Download Failed // Error: {e.Message}\n");
                        }
                    }
                }
                catch {
                    WriteLine($"Rom '{node.InnerText}' not available\n");
                }
            }
            else
            {
                WriteLine($"{node.InnerText} exist already in your library\n");
            }
        }
示例#3
0
 //Function to get a collection of HTML nodes with the different ROMs searching results
 public void romSearchListFetcher(string uri)
 {
     this.listRoms = UriContentFetcher.getContent(uri,
                                                  "//td[@class='d-block d-sm-none text-center']/a[contains(@href,'/roms/')]",
                                                  true);
 }
示例#4
0
 //Function to get a collection of HTML nodes with the different platforms links
 public RomPlatformFetcher(string uri)
 {
     this.listMenuLinks = UriContentFetcher.getContent(uri,
                                                       "//td[@class='d-block d-sm-none text-center']/a[contains(@href,'/roms/')]",
                                                       true);
 }