Fix typecheck when fetching community attachments

This commit is contained in:
syeopite 2021-07-26 21:26:55 -07:00
parent 0137a43722
commit 34f9159277
No known key found for this signature in database
GPG key ID: 6FA616E5A5294A82
2 changed files with 5 additions and 2 deletions

View file

@ -26,6 +26,7 @@ module YouTubeStructs
struct CommunityPost struct CommunityPost
include DB::Serializable include DB::Serializable
alias AttachmentType = (VideoRenderer | PlaylistRenderer | CommunityPoll | String)? # string is image/gif
# Author information # Author information
property author : String property author : String
@ -35,7 +36,7 @@ module YouTubeStructs
# Community post data # Community post data
property post_id : String property post_id : String
property content_html : String property content_html : String
property attachment : (VideoRenderer | PlaylistRenderer | CommunityPoll | String)? # string is image/gif property attachment : AttachmentType
property likes : Int32 property likes : Int32
property published : Time property published : Time

View file

@ -353,7 +353,9 @@ private module Parsers
attachment = YouTubeStructs::CommunityPoll.new({choices: choices, total_votes: votes}) attachment = YouTubeStructs::CommunityPoll.new({choices: choices, total_votes: votes})
else else
attachment = extract_item(attachment_container) attachment = extract_item(attachment_container)
raise "Unreachable" if !attachment.is_a?(YouTubeStructs::VideoRenderer | YouTubeStructs::PlaylistRenderer) if !attachment.is_a?(YouTubeStructs::CommunityPost::AttachmentType)
raise "Unexpected type found for attachment. Expected : '#{YouTubeStructs::CommunityPost::AttachmentType}' got #{typeof(attachment)}"
end
end end
likes = short_text_to_number(item_contents["voteCount"]["simpleText"].as_s.split(" ")[0]) # Youtube doesn't provide dislikes... likes = short_text_to_number(item_contents["voteCount"]["simpleText"].as_s.split(" ")[0]) # Youtube doesn't provide dislikes...