Created
November 14, 2018 04:49
-
-
Save TheBuzzSaw/5c90a0a850d2d73899edd92fd6cfe5bc to your computer and use it in GitHub Desktop.
Smash Ultimate Fighter Image Grabber
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.IO; | |
| using System.Net.Http; | |
| using System.Threading.Tasks; | |
| namespace SmashImageGrabber | |
| { | |
| class Program | |
| { | |
| static readonly string[] Fighters = new string[] | |
| { | |
| "bayonetta", | |
| "bowser", | |
| "bowser_jr", | |
| "captain_falcon", | |
| "chrom", | |
| "cloud", | |
| "corrin", | |
| "daisy", | |
| "dark_pit", | |
| "dark_samus", | |
| "diddy_kong", | |
| "donkey_kong", | |
| "dr_mario", | |
| "duck_hunt", | |
| "falco", | |
| "fox", | |
| "ganondorf", | |
| "greninja", | |
| "ice_climbers", | |
| "ike", | |
| "incineroar", | |
| "inkling", | |
| "isabelle", | |
| "jigglypuff", | |
| "ken", | |
| "king_dedede", | |
| "king_k_rool", | |
| "kirby", | |
| "link", | |
| "little_mac", | |
| "lucario", | |
| "lucas", | |
| "lucina", | |
| "luigi", | |
| "mario", | |
| "marth", | |
| "mega_man", | |
| "meta_knight", | |
| "mewtwo", | |
| "mii_fighter", | |
| "mr_game_and_watch", | |
| "ness", | |
| "olimar", | |
| "pac_man", | |
| "palutena", | |
| "peach", | |
| "pichu", | |
| "pikachu", | |
| "piranha_plant", | |
| "pit", | |
| "pokemon_trainer", | |
| "richter", | |
| "ridley", | |
| "rob", | |
| "robin", | |
| "rosalina_and_luma", | |
| "roy", | |
| "ryu", | |
| "samus", | |
| "sheik", | |
| "shulk", | |
| "simon", | |
| "snake", | |
| "sonic", | |
| "toon_link", | |
| "villager", | |
| "wario", | |
| "wii_fit_trainer", | |
| "wolf", | |
| "yoshi", | |
| "young_link", | |
| "zelda", | |
| "zero_suit_samus" | |
| }; | |
| static async Task Download(HttpClient client, string fighter) | |
| { | |
| try | |
| { | |
| var url = $"https://www.smashbros.com/assets_v2/img/fighter/{fighter}/main.png"; | |
| var file = $"{fighter}.png"; | |
| Console.WriteLine(url); | |
| var response = await client.GetAsync(url); | |
| response.EnsureSuccessStatusCode(); | |
| var body = await response.Content.ReadAsByteArrayAsync(); | |
| await File.WriteAllBytesAsync(file, body); | |
| } | |
| catch (Exception ex) | |
| { | |
| for (var e = ex; e != null; e = e.InnerException) | |
| { | |
| var output = string.Concat( | |
| e.GetType().ToString(), | |
| Environment.NewLine, | |
| e.Message, | |
| Environment.NewLine, | |
| e.StackTrace, | |
| Environment.NewLine); | |
| Console.WriteLine(output); | |
| } | |
| } | |
| } | |
| static async Task Download(HttpClient client, int begin, int end) | |
| { | |
| for (int i = begin; i < end; ++i) | |
| await Download(client, Fighters[i]); | |
| } | |
| static async Task Main(string[] args) | |
| { | |
| var stopwatch = System.Diagnostics.Stopwatch.StartNew(); | |
| try | |
| { | |
| int jobCount = 1; | |
| if (args.Length > 0 && int.TryParse(args[0], out int n)) | |
| jobCount = Math.Max(1, n); | |
| string word = jobCount == 1 ? "worker" : "workers"; | |
| Console.WriteLine($"Downloading images using {jobCount} {word}..."); | |
| using (var client = new HttpClient()) | |
| { | |
| int jobSize = Fighters.Length / jobCount; | |
| var tasks = new Task[jobCount]; | |
| for (int i = 0; i < jobCount; ++i) | |
| { | |
| int begin = jobSize * i; | |
| int end = Math.Min(begin + jobSize, Fighters.Length); | |
| tasks[i] = Download(client, begin, end); | |
| } | |
| await Task.WhenAll(tasks); | |
| } | |
| } | |
| catch (Exception ex) | |
| { | |
| for (var e = ex; e != null; e = e.InnerException) | |
| { | |
| Console.WriteLine(e.GetType()); | |
| Console.WriteLine(e.Message); | |
| Console.WriteLine(e.StackTrace); | |
| } | |
| } | |
| finally | |
| { | |
| Console.WriteLine(stopwatch.Elapsed); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment