From 49a2fbb0700234ad6aec40a65ba44cc83ec0b555 Mon Sep 17 00:00:00 2001 From: Zed Date: Wed, 26 Jan 2022 18:24:34 +0100 Subject: [PATCH] Support profile image color parsing in wip parser --- src/experimental/parser/user.nim | 7 ++++++- src/experimental/types/user.nim | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/experimental/parser/user.nim b/src/experimental/parser/user.nim index 767945b..b9aaa3c 100644 --- a/src/experimental/parser/user.nim +++ b/src/experimental/parser/user.nim @@ -1,4 +1,4 @@ -import std/[algorithm, unicode, re, strutils] +import std/[algorithm, unicode, re, strutils, strformat] import jsony import utils, slices import ../types/user as userType @@ -34,9 +34,14 @@ proc expandUserEntities(user: var User; raw: RawUser) = proc getBanner(user: RawUser): string = if user.profileBannerUrl.len > 0: return user.profileBannerUrl & "/1500x500" + if user.profileLinkColor.len > 0: return '#' & user.profileLinkColor + if user.profileImageExtensions.mediaColor.r.ok.palette.len > 0: + let color = user.profileImageExtensions.mediaColor.r.ok.palette[0].rgb + return &"#{color.red:02x}{color.green:02x}{color.blue:02x}" + proc toUser*(raw: RawUser): User = result = User( id: raw.idStr, diff --git a/src/experimental/types/user.nim b/src/experimental/types/user.nim index c048ba2..430bc8e 100644 --- a/src/experimental/types/user.nim +++ b/src/experimental/types/user.nim @@ -18,6 +18,7 @@ type protected*: bool profileBannerUrl*: string profileImageUrlHttps*: string + profileImageExtensions*: ImageExtensions profileLinkColor*: string pinnedTweetIdsStr*: seq[string] @@ -27,3 +28,15 @@ type Urls* = object urls*: seq[Url] + + ImageExtensions = object + mediaColor*: tuple[r: Ok] + + Ok = object + ok*: Palette + + Palette = object + palette*: seq[tuple[rgb: Color]] + + Color* = object + red*, green*, blue*: int