Skip to content

Commit

Permalink
update angelthump api
Browse files Browse the repository at this point in the history
  • Loading branch information
slugalisk committed Feb 12, 2024
1 parent 930f33a commit 90f9f60
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 32 deletions.
72 changes: 40 additions & 32 deletions api/src/AngelThumpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,64 +10,72 @@ rapidjson::Document ChannelResult::GetSchema() {
rapidjson::Document schema;
schema.Parse(R"json(
{
"type": "object",
"properties": {
"type": {"type": "string"},
"thumbnail_url": {
"type": "string",
"format": "uri"
},
"viewer_count": {"type": "integer"},
"user": {
"type": "object",
"properties": {
"title": {"type": "string"},
"offline_banner_url": {
"type": "string",
"format": "uri"
},
"nsfw": {"type": "boolean"}
"type": "array",
"minItems": "1",
"items": {
"type": "object",
"properties": {
"type": {"type": "string"},
"thumbnail_url": {
"type": "string",
"format": "uri"
},
"required": ["offline_banner_url", "nsfw"]
}
},
"required": ["user"]
"viewer_count": {"type": "integer"},
"user": {
"type": "object",
"properties": {
"title": {"type": "string"},
"offline_banner_url": {
"type": "string",
"format": "uri"
},
"nsfw": {"type": "boolean"}
},
"required": ["offline_banner_url", "nsfw"]
}
},
"required": ["user"]
}
}
)json");
return schema;
}

const rapidjson::Value& ChannelResult::GetVideoData() const {
return GetData().GetArray()[0];
}

std::string ChannelResult::GetTitle() const {
if (GetData()["user"].HasMember("title")) {
return json::StringRef(GetData()["user"]["title"]);
if (GetVideoData()["user"].HasMember("title")) {
return json::StringRef(GetVideoData()["user"]["title"]);
}
return "";
}

bool ChannelResult::GetLive() const {
return GetData().HasMember("type") &&
json::StringRef(GetData()["type"]) == "live";
return GetVideoData().HasMember("type") &&
json::StringRef(GetVideoData()["type"]) == "live";
}

std::string ChannelResult::GetThumbnail() const {
return GetData().HasMember("thumbnail_url")
? json::StringRef(GetData()["thumbnail_url"])
: json::StringRef(GetData()["user"]["offline_banner_url"]);
return GetVideoData().HasMember("thumbnail_url")
? json::StringRef(GetVideoData()["thumbnail_url"])
: json::StringRef(GetVideoData()["user"]["offline_banner_url"]);
}

bool ChannelResult::IsNSFW() const {
return GetData()["user"]["nsfw"].GetBool();
return GetVideoData()["user"]["nsfw"].GetBool();
}

uint64_t ChannelResult::GetViewers() const {
return GetData().HasMember("viewer_count")
? GetData()["viewer_count"].GetUint64()
return GetVideoData().HasMember("viewer_count")
? GetVideoData()["viewer_count"].GetUint64()
: 0;
}

Status Client::GetChannelByName(const std::string& name,
ChannelResult* result) {
CurlRequest req("https://api.angelthump.com/v2/streams/" + name);
CurlRequest req("https://api.angelthump.com/v3/streams?username=" + name);
req.Submit();

if (!req.Ok()) {
Expand Down
2 changes: 2 additions & 0 deletions api/src/AngelThumpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class ChannelResult : public APIResult {
public:
rapidjson::Document GetSchema() final;

const rapidjson::Value& GetVideoData() const;

std::string GetTitle() const;

bool GetLive() const;
Expand Down

0 comments on commit 90f9f60

Please sign in to comment.