diff options
author | Emma [it/its]@Rory& <root@rory.gay> | 2023-10-14 23:19:46 +0200 |
---|---|---|
committer | Emma [it/its]@Rory& <root@rory.gay> | 2023-10-14 23:19:46 +0200 |
commit | 73461bd79f923caa44740f170213a4abb4743660 (patch) | |
tree | 89cbb7403b4bf3f86a505d70a8f255b6463a2c3f /OsuFederatedBeatmapApi/Services/BeatmapFetcherService.cs | |
parent | Maybe fix libmatrix bug with room creation (diff) | |
download | OsuFederatedBeatmapApi-73461bd79f923caa44740f170213a4abb4743660.tar.xz |
Diffstat (limited to 'OsuFederatedBeatmapApi/Services/BeatmapFetcherService.cs')
-rw-r--r-- | OsuFederatedBeatmapApi/Services/BeatmapFetcherService.cs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/OsuFederatedBeatmapApi/Services/BeatmapFetcherService.cs b/OsuFederatedBeatmapApi/Services/BeatmapFetcherService.cs new file mode 100644 index 0000000..ae108fb --- /dev/null +++ b/OsuFederatedBeatmapApi/Services/BeatmapFetcherService.cs @@ -0,0 +1,34 @@ +using System.Net.Http.Headers; +using OsuFederatedBeatmapApi.Events.State; +using OsuFederatedBeatmapApi.UtilityClasses; + +namespace OsuFederatedBeatmapApi.Services; + +public class BeatmapFetcherService(FederatedBeatmapApiBotAccountDataService ads) { + + public async Task<BeatmapSetInfo> FetchBeatmapSetInfo(int id) { + var hc = new HttpClient(); + hc.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("OsuFederatedBeatmapApi", "1.0")); + var res = await hc.GetFromJsonAsync<OsuDirectApiResponses.BeatmapSet>($"https://osu.direct/api/s/{id}"); + var info = new BeatmapSetInfo { + Title = res.Title, + Artist = res.Artist, + Creator = res.Creator, + Beatmaps = res.ChildrenBeatmaps.ToDictionary(b => b.BeatmapID, b => new BeatmapSetInfo.BeatmapInfo { + Difficulty = b.DiffName, + Mode = b.Mode, + DifficultyRating = b.DifficultyRating, + TotalLength = b.TotalLength, + BPM = b.BPM, + MaxCombo = b.MaxCombo + }) + }; + + await ads.LoadAccountDataAsync(); + + await ads.OwnBeatmapRepositoryRoom.SendStateEventAsync(BeatmapSetInfo.EventName, id.ToString(), info); + + return info; + } + +} |