public static Beatmaps FetchFromApi(ICheesegullConfig cfg, string fileMd5, int beatmapId = -1) { var cg = new Cheesegull(cfg); if (!string.IsNullOrEmpty(fileMd5)) { cg.SetBM(fileMd5); } else if (beatmapId != -1) { cg.SetBM(beatmapId); } var bmSet = cg.GetSets(); if (bmSet.Count == 0) { return(null); } var bm = bmSet[0].ChildrenBeatmaps.FirstOrDefault(x => x.FileMD5 == fileMd5 || x.BeatmapID == beatmapId); if (string.IsNullOrEmpty(bm.FileMD5)) { return(null); } var b = new Beatmaps { Ar = bm.AR, Artist = bmSet[0].Artist, Bpm = bm.BPM, Cs = bm.CS, Difficulty = bm.DifficultyRating, Hp = bm.HP, Id = bm.BeatmapID, Od = bm.OD, Tags = bmSet[0].Tags, Title = bmSet[0].Title, BeatmapCreator = bmSet[0].Creator, BeatmapCreatorId = -1, // -1 because we do not own this beatmap. DifficultyName = bm.DiffName, HitLength = bm.HitLength, LastUpdate = DateTime.Now, PassCount = 0, PlayCount = 0, PlayMode = bm.Mode, RankedDate = Convert.ToDateTime(bmSet[0].ApprovedDate), RankedStatus = Fixer.FixRankedStatus((Cheesegull.RankedStatus)bmSet[0].RankedStatus), TotalLength = bm.TotalLength, BeatmapSetId = bm.ParentSetID, FileMd5 = bm.FileMD5 }; return(b); }
public static string GetBeatmap(string hash, ICheesegullConfig cfg) { if (!Directory.Exists("data/beatmaps")) { Directory.CreateDirectory("data/beatmaps"); } if (File.Exists($"data/beatmaps/{hash}")) { return($"data/beatmaps/{hash}"); } var cg = new Cheesegull(cfg); cg.SetBM(hash); var sets = cg.GetSets(); if (sets.Count < 1) { return(string.Empty); } var bm = sets[0].ChildrenBeatmaps.FirstOrDefault(cb => cb.FileMD5 == hash); var request = (HttpWebRequest)WebRequest.Create($"https://osu.ppy.sh/osu/{bm.BeatmapID}"); request.AutomaticDecompression = DecompressionMethods.GZip; using (var response = (HttpWebResponse)request.GetResponse()) using (var stream = response.GetResponseStream()) using (var reader = new StreamReader(stream ?? throw new Exception("Request Failed!"))) { var result = reader.ReadToEnd(); if (result.Length < 1) { return(string.Empty); } File.WriteAllText($"data/beatmaps/{hash}", result); } return($"data/beatmaps/{hash}"); }
public Cheesegull(ICheesegullConfig cfg) => _cfg = cfg;