Skip to content

Commit

Permalink
update player information crawler (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
Deliay authored Jun 23, 2022
1 parent 22d0991 commit a172e75
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public override string ConvertName(string name)
using var res = await _requestor.GetAsync($"https://osu.ppy.sh/users/{playerName}");
if (!res.IsSuccessStatusCode) { return (false, null); }
var rawHtml = await res.Content.ReadAsStringAsync();
var userJsonStartPos = rawHtml.IndexOf(">", rawHtml.LastIndexOf("json-user")) + 1;
var userJsonEndPos = rawHtml.IndexOf("</script>", userJsonStartPos);
var userJson = rawHtml[userJsonStartPos..userJsonEndPos];
var info = JsonSerializer.Deserialize<PlayerInformation>(userJson, SerializerOptions);
var userJsonStartPos = rawHtml.LastIndexOf("data-initial-data") + 19;
var userJsonEndPos = rawHtml.IndexOf("\"", userJsonStartPos);
var userJson = System.Web.HttpUtility.HtmlDecode(rawHtml[userJsonStartPos..userJsonEndPos]);

var info = JsonSerializer.Deserialize<UserInfomation>(userJson, SerializerOptions).User;
_informationCache[playerName] = (info, DateTime.Now);
return (true, info);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,79 @@ public class PlayerInformationEvent : Event<PlayerInformationEvent>
{
[DataSourceVariable]
public string AvatarUrl { get; set; }

[DataSourceVariable]
public string CoverUrl { get; set; }

[DataSourceVariable]
public string CountryCode { get; set; }

[DataSourceVariable]
public bool IsOnline { get; set; }

[DataSourceVariable]
public DateTimeOffset JoinDate { get; set; }

[DataSourceVariable]
public string Username { get; set; }

[DataSourceVariable]
public int SS { get; set; }

[DataSourceVariable]
public int Ssh { get; set; }

[DataSourceVariable]
public int S { get; set; }

[DataSourceVariable]
public int Sh { get; set; }

[DataSourceVariable]
public int A { get; set; }

[DataSourceVariable]
public int CurrentLevel { get; set; }

[DataSourceVariable]
public int LevelProgress { get; set; }

[DataSourceVariable]
public double PP { get; set; }

[DataSourceVariable]
public int PPRank { get; set; }

[DataSourceVariable]
public int GlobalRank { get; set; }

[DataSourceVariable]
public int CountryRank { get; set; }

[DataSourceVariable]
public long RankedScore { get; set; }

[DataSourceVariable]
public double HitAccuracy { get; set; }

[DataSourceVariable]
public int PlayCount { get; set; }

[DataSourceVariable]
public int PlayTime { get; set; }

[DataSourceVariable]
public long TotalScore { get; set; }

[DataSourceVariable]
public int TotalHit { get; set; }

[DataSourceVariable]
public int MaximumCombo { get; set; }

[DataSourceVariable]
public int ReaplysWatchedByOthers { get; set; }

[DataSourceVariable]
public bool IsRanked { get; set; }
public static PlayerInformationEvent FromPlayerInformation(PlayerInformation information)
Expand All @@ -69,7 +98,9 @@ public static PlayerInformationEvent FromPlayerInformation(PlayerInformation inf
CurrentLevel = information.Statistics.Level.Current,
LevelProgress = information.Statistics.Level.Progress,
PP = information.Statistics.PP,
PPRank = information.Statistics.PPRank,
PPRank = information.Statistics.GlobalRank,
GlobalRank = information.Statistics.GlobalRank,
CountryRank = information.Statistics.CountryRank,
RankedScore = information.Statistics.RankedScore,
HitAccuracy = information.Statistics.HitAccuracy,
PlayCount = information.Statistics.PlayCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ public class PlayerStatistic
{
public PlayerLevel Level { get; set; }
public double PP { get; set; }
public int PPRank{ get; set; }
public int GlobalRank { get; set; }
public int CountryRank { get; set; }
public long RankedScore { get; set; }
public double HitAccuracy { get; set; }
public int PlayCount { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace CurrentPlayerInformation.Models
{
public class UserInfomation
{
public PlayerInformation User { get; set; }
}
}

0 comments on commit a172e75

Please sign in to comment.