about summary refs log tree commit diff
path: root/OsuFederatedBeatmapApi/Services/BeatmapFetcherService.cs
diff options
context:
space:
mode:
authorEmma [it/its]@Rory& <root@rory.gay>2023-10-14 23:19:46 +0200
committerEmma [it/its]@Rory& <root@rory.gay>2023-10-14 23:19:46 +0200
commit73461bd79f923caa44740f170213a4abb4743660 (patch)
tree89cbb7403b4bf3f86a505d70a8f255b6463a2c3f /OsuFederatedBeatmapApi/Services/BeatmapFetcherService.cs
parentMaybe fix libmatrix bug with room creation (diff)
downloadOsuFederatedBeatmapApi-73461bd79f923caa44740f170213a4abb4743660.tar.xz
Stuff works HEAD master
Diffstat (limited to 'OsuFederatedBeatmapApi/Services/BeatmapFetcherService.cs')
-rw-r--r--OsuFederatedBeatmapApi/Services/BeatmapFetcherService.cs34
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;
+    }
+
+}