private static void ExtractReplays(string replayLocation, string osuFolderPath) { List <string> replays = Directory.GetFiles(osuFolderPath + "\\Data\\r", "*.osr", SearchOption.AllDirectories).ToList(); List <MapReplay> replayMapHashes = new List <MapReplay>(); List <string> failedSearches = new List <string>(); List <string> failedMapPaths = new List <string>(); string apiErrorMsg = ""; bool skipAPI = false; string apiKey = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "\\apikey.txt"); if (apiKey.Length == 0) { Console.WriteLine(Properties.Resources.InformMissingAPIKey); skipAPI = true; } // Get all replays' beatmap hash Console.WriteLine(Properties.Resources.InformReplayGathering); foreach (string replayPath in replays) { replayMapHashes.Add(ReplayReader.GetReplayInfo(replayPath)); } Console.WriteLine(Properties.Resources.InformMapsGathering); Dictionary <string, Beatmap> beatmaps = DBReader.ReadDB(osuFolderPath + "\\osu!.db"); List <Beatmap> lookedUpMaps = new List <Beatmap>(); // Match the replay to its' corresponding beatmap for (int i = 0; i < replayMapHashes.Count; i++) { string totalPercentage = (Convert.ToDouble(i) / (replayMapHashes.Count - 1)).ToString("P", CultureInfo.InvariantCulture); MapReplay replayMapHash = replayMapHashes[i]; Beatmap beatmap; bool success = beatmaps.TryGetValue(replayMapHash.BeatmapHash, out beatmap); if (success) { // Beatmap has been looked up via API and does not exist if (beatmap == null) { failedSearches.Add(replayMapHash.BeatmapHash); failedMapPaths.Add(replays[i]); continue; } CopyAndRenameReplay(replays[i], replayLocation, replayMapHash, beatmap, totalPercentage); } else { if (skipAPI) { failedSearches.Add(replayMapHash.BeatmapHash); failedMapPaths.Add(replays[i]); beatmaps.Add(replayMapHash.BeatmapHash, null); } else { // Try getting beatmap via API if not found locally Console.WriteLine(Properties.Resources.InformUsingSearchAPI); Beatmap retreivedBeatmap = OsuApi.GetMapWithApiAsync(replayMapHash.BeatmapHash, out apiErrorMsg); if (retreivedBeatmap == null) { Console.WriteLine(Properties.Resources.InformSearchAPIFailed); failedSearches.Add(replayMapHash.BeatmapHash); failedMapPaths.Add(replays[i]); // Add beatmap hash to skip duplicate API calls beatmaps.Add(replayMapHash.BeatmapHash, null); } else { CopyAndRenameReplay(replays[i], replayLocation, replayMapHash, retreivedBeatmap, totalPercentage); lookedUpMaps.Add(retreivedBeatmap); } } } } File.AppendAllLines(AppDomain.CurrentDomain.BaseDirectory + "\\mapCache.txt", lookedUpMaps.ConvertAll(obj => obj.ToString()).Distinct(), Encoding.UTF8); failedSearches = failedSearches.Distinct().ToList(); LogFailures(failedSearches, failedMapPaths, apiErrorMsg, skipAPI); }