Skip to content

Commit

Permalink
Parse twitter video from path instead of entity data. Max width and h…
Browse files Browse the repository at this point in the history
…eight in entity data seems to be 1024x576 while videos are really 1280x720.
  • Loading branch information
stefansundin committed Apr 27, 2017
1 parent 540ba7f commit e310699
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions config/initializers/05-string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,10 @@ def embed_html(request=nil)
"<iframe width='640' height='538' src='#{self.https}' frameborder='0' scrolling='no' allowfullscreen></iframe>"
elsif %r{^https?://[a-z0-9\-._~:/?#\[\]@!$&'()*+,;=]+\.(?:gif|jpg|png)(?::large)?}i =~ self
"<img src='#{self.https}'>"
elsif %r{^https?://[a-z0-9\-._~:/?#\[\]@!$&'()*+,;=]+\.mp4}i =~ self
query = CGI.parse(URI.parse(self).query)
width = query["w"][0] || "640"
height = query["h"][0] || "538"
elsif %r{^https?://video\.twimg\.com/ext_tw_video/.+/(?<width>\d+)x(?<height>\d+)/.+\.mp4}i =~ self
"<iframe width='#{width}' height='#{height}' src='#{self}' frameborder='0' scrolling='no' allowfullscreen></iframe>"
elsif %r{^https?://[a-z0-9\-._~:/?#\[\]@!$&'()*+,;=]+\.mp4}i =~ self
"<iframe width='640' height='538' src='#{self}' frameborder='0' scrolling='no' allowfullscreen></iframe>"
elsif %r{^https?://amp\.twimg\.com/v/.+}i =~ self
"<iframe width='640' height='600' src='#{self}' frameborder='0' scrolling='no' allowfullscreen></iframe>"
end
Expand Down
2 changes: 1 addition & 1 deletion views/twitter_feed.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
b["content_type"].start_with?("video/") <=> a["content_type"].start_with?("video/")
end
end.first
text += " #{video["url"]}?w=#{entity["sizes"]["large"]["w"]}&h=#{entity["sizes"]["large"]["h"]}"
text += " #{video["url"]}"
end
end
if t["entities"]["media"]
Expand Down

0 comments on commit e310699

Please sign in to comment.