mirror of https://github.com/iv-org/invidious.git
Community: Parse polls
This commit is contained in:
parent
7993784701
commit
8384fa94c2
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue