diff options
| author | ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> | 2023-02-14 22:48:37 -0500 |
|---|---|---|
| committer | ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> | 2023-02-14 22:48:37 -0500 |
| commit | 8384fa94c2de8c4bf561f4fe5964ce802f22a545 (patch) | |
| tree | 83ad6c0c145f3fdff4dc6f13df413f7100741341 | |
| parent | 7993784701686c057b85c57704537135e6326de9 (diff) | |
| download | invidious-8384fa94c2de8c4bf561f4fe5964ce802f22a545.tar.gz invidious-8384fa94c2de8c4bf561f4fe5964ce802f22a545.tar.bz2 invidious-8384fa94c2de8c4bf561f4fe5964ce802f22a545.zip | |
Community: Parse polls
| -rw-r--r-- | src/invidious/channels/community.cr | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/invidious/channels/community.cr b/src/invidious/channels/community.cr index 13af2d8b..a0e79c22 100644 --- a/src/invidious/channels/community.cr +++ b/src/invidious/channels/community.cr @@ -185,10 +185,40 @@ def fetch_channel_community(ucid, continuation, locale, format, thin_mode) end end end - # TODO - # when .has_key?("pollRenderer") - # attachment = attachment["pollRenderer"] - # json.field "type", "poll" + when .has_key?("pollRenderer") + attachment = attachment["pollRenderer"] + json.field "type", "poll" + json.field "totalVotes", attachment["totalVotes"]["simpleText"].as_s + json.field "choices" do + json.array do + attachment["choices"].as_a.each do |choice| + json.object do + json.field "text", choice["text"]["runs"][0]["text"].as_s + # A choice can have an image associated with it. + # Ex post: https://www.youtube.com/post/UgkxD4XavXUD4NQiddJXXdohbwOwcVqrH9Re + if choice["image"]? + thumbnail = choice["image"]["thumbnails"][0].as_h + width = thumbnail["width"].as_i + height = thumbnail["height"].as_i + aspect_ratio = (width.to_f / height.to_f) + url = thumbnail["url"].as_s.gsub(/=w\d+-h\d+(-p)?(-nd)?(-df)?(-rwa)?/, "=s640") + qualities = {320, 560, 640, 1280, 2000} + json.field "image" do + json.array do + qualities.each do |quality| + json.object do + json.field "url", url.gsub(/=s\d+/, "=s#{quality}") + json.field "width", quality + json.field "height", (quality / aspect_ratio).ceil.to_i + end + end + end + end + end + end + end + end + end when .has_key?("postMultiImageRenderer") attachment = attachment["postMultiImageRenderer"] json.field "type", "multiImage" |
