TizzyT

Archive.org Gamecube Collection Downloader -TizzyT

Dec 4th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.60 KB | None | 0 0
  1. using System;
  2. using System.Net;
  3.  
  4. namespace GameCubeDownloader
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string href = "<td><a href=\"";
  11.             string slashA = "</a>";
  12.             string delimiter = "\">";
  13.             string URL = "https://archive.org/download/GamecubeCollectionByGhostware/";
  14.             string Root = System.IO.Directory.GetCurrentDirectory();
  15.  
  16.             string downloadFolder = "/Downloaded/";
  17.             string temporaryFolder = "/temp/";
  18.  
  19.             string[] source;
  20.             using (WebClient client = new WebClient())
  21.                 source = client.DownloadString(URL).Split(new string[] { href }, StringSplitOptions.RemoveEmptyEntries);
  22.  
  23.             if (!System.IO.Directory.Exists(Root + downloadFolder)) System.IO.Directory.CreateDirectory(Root + downloadFolder);
  24.             if (!System.IO.Directory.Exists(Root + temporaryFolder)) System.IO.Directory.CreateDirectory(Root + temporaryFolder);
  25.  
  26.             foreach (string snippet in source)
  27.             {
  28.                 string file = "N/A";
  29.                 try
  30.                 {
  31.                     string[] important = snippet.Split(new string[] { slashA }, StringSplitOptions.RemoveEmptyEntries)[0].Split(new string[] { delimiter }, StringSplitOptions.RemoveEmptyEntries);
  32.                     if (important.Length == 2)
  33.                     {
  34.                         file = important[1];
  35.                         if (important[0].EndsWith(".iso"))
  36.                         {
  37.                             if (System.IO.File.Exists(Root + downloadFolder + important[1]))
  38.                             {
  39.                                 Console.WriteLine("Already downloaded: " + important[1] + ", Skipping");
  40.                                 continue;
  41.                             }
  42.                             while (true)
  43.                             {
  44.                                 if (System.IO.File.Exists(Root + temporaryFolder + important[0]))
  45.                                 {
  46.                                     System.IO.File.Delete(temporaryFolder + important[1]);
  47.                                     Console.WriteLine("Retrying Download: " + important[1]);
  48.                                 }
  49.                                 else
  50.                                 {
  51.                                     Console.WriteLine("Downloading: " + important[1]);
  52.                                 }
  53.                                 using (WebClient client = new WebClient())
  54.                                     client.DownloadFile(URL + important[0], Root + temporaryFolder + important[1]);
  55.                                 if (new System.IO.FileInfo(Root + temporaryFolder + important[1]).Length > 1)
  56.                                 {
  57.                                     System.IO.File.Move(Root + temporaryFolder + important[1], Root + downloadFolder + important[1]);
  58.                                     Console.WriteLine("Finshished downloading: " + important[1]);
  59.                                     break;
  60.                                 }
  61.                                 else
  62.                                 {
  63.                                     Console.WriteLine("Download Unsucessful: " + important[1]);
  64.                                 }
  65.                             }
  66.                         }
  67.                     }
  68.                 }
  69.                 catch (Exception ex)
  70.                 {
  71.                     System.IO.File.AppendAllText(Root + "/Log.txt", "[" + DateTime.Now.ToShortTimeString() + "] " + file + " : " + ex.Message);
  72.                 }
  73.             }
  74.         }
  75.     }
  76. }
Add Comment
Please, Sign In to add comment