This repository has been archived by the owner on Jul 16, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CalculatorViewModel] Added currently playing beatmap recognition usi…
…ng OsuSearch. Works only on Ranked maps, may be inaccurate if there are multiple ranked maps with same artist, title, difficulty name.
- Loading branch information
Showing
9 changed files
with
179 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// ------------------------------------------------------------------------- | ||
// Solution: OsuHelper | ||
// Project: OsuHelper | ||
// File: OsuGameService.cs | ||
// | ||
// Created by: Tyrrrz | ||
// On: 28.08.2016 | ||
// ------------------------------------------------------------------------- | ||
|
||
using System.Diagnostics; | ||
using System.Linq; | ||
using NegativeLayer.Extensions; | ||
|
||
namespace OsuHelper.Services | ||
{ | ||
public sealed class OsuGameService | ||
{ | ||
public string GetNowPlayingTitle() | ||
{ | ||
// Find osu process | ||
var process = Process.GetProcessesByName("osu!").FirstOrDefault(); | ||
if (process == null) return null; | ||
|
||
// Get title | ||
string windowTitle = process.MainWindowTitle; | ||
|
||
// Check if anything is playing | ||
if (!windowTitle.StartsWith("osu! - ")) | ||
return null; | ||
|
||
// Return the title | ||
return windowTitle.SubstringAfter("osu! - "); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// ------------------------------------------------------------------------- | ||
// Solution: OsuHelper | ||
// Project: OsuHelper | ||
// File: OsuSearchService.cs | ||
// | ||
// Created by: Tyrrrz | ||
// On: 28.08.2016 | ||
// ------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using NegativeLayer.Extensions; | ||
using Newtonsoft.Json; | ||
using OsuHelper.Models.API; | ||
|
||
namespace OsuHelper.Services | ||
{ | ||
public sealed class OsuSearchService : IDisposable | ||
{ | ||
private const string Home = "http://osusearch.com/"; | ||
|
||
private static string URLEncode(string arg) | ||
{ | ||
return Uri.EscapeUriString(arg); | ||
} | ||
|
||
private readonly WebClient _webClient = new WebClient(); | ||
|
||
/// <summary> | ||
/// Searches for beatmaps using given properties and then returns their beatmap IDs | ||
/// </summary> | ||
public async Task<IEnumerable<string>> SearchAsync(GameMode mode = GameMode.Standard, string artist = null, string title = null, string diffName = null) | ||
{ | ||
string url = Home + "query"; | ||
var args = new List<string>(); | ||
|
||
// Hidden parameters | ||
args.Add("statuses=Ranked"); | ||
|
||
// Mandatory parameters | ||
if (mode == GameMode.Standard) | ||
args.Add("modes=Standard"); | ||
else if (mode == GameMode.CatchTheBeat) | ||
args.Add("modes=CtB"); | ||
else if (mode == GameMode.Taiko) | ||
args.Add("modes=Taiko"); | ||
else if (mode == GameMode.Mania) | ||
args.Add("modes=Mania"); | ||
|
||
// Optional parameters | ||
if (artist.IsNotBlank()) | ||
args.Add($"artist={URLEncode(artist.Trim())}"); | ||
if (title.IsNotBlank()) | ||
args.Add($"title={URLEncode(title.Trim())}"); | ||
if (diffName.IsNotBlank()) | ||
args.Add($"diff_name={URLEncode(diffName.Trim())}"); | ||
url += "?" + args.JoinToString("&"); | ||
string response = await _webClient.DownloadStringTaskAsync(url); | ||
|
||
// High-danger zone (no typechecks) | ||
dynamic result = JsonConvert.DeserializeObject(response); | ||
return ((IEnumerable<dynamic>) result.beatmaps).Select(b => b.beatmap_id.ToString()).Cast<string>(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_webClient.Dispose(); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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