14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/twitter_api.rb', line 14
def ()
text = [:data][:text].dup.to_s
if (entities = [:data][:entities]) && (urls = entities[:urls])
urls.each do |url|
if !url[:display_url].start_with?("pic.twitter.com")
text.gsub!(
url[:url],
"<a target='_blank' href='#{url[:expanded_url]}'>#{url[:display_url]}</a>",
)
else
text.gsub!(url[:url], "")
end
end
end
text = link_hashtags_in link_handles_in text
result = Rinku.auto_link(text, :all, 'target="_blank"').to_s
if [:includes] && media = [:includes][:media]
media.each do |m|
if m[:type] == "photo"
result << "<div class='tweet-images'><img class='tweet-image' src='#{m[:url]}' width='#{m[:width]}' height='#{m[:height]}'></div>"
elsif m[:type] == "video" || m[:type] == "animated_gif"
video_to_display =
m[:variants]
.select { |v| v[:content_type] == "video/mp4" }
.sort { |v| v[:bit_rate] }
.last
if video_to_display && url = video_to_display[:url]
width = m[:width]
height = m[:height]
attributes =
if m[:type] == "animated_gif"
%w[playsinline loop muted autoplay disableRemotePlayback disablePictureInPicture]
else
%w[controls playsinline]
end.join(" ")
result << <<~HTML
<div class='tweet-images'>
<div class='aspect-image-full-size' style='--aspect-ratio:#{width}/#{height};'>
<video class='tweet-video' #{attributes}
width='#{width}'
height='#{height}'
poster='#{m[:preview_image_url]}'>
<source src='#{url}' type="video/mp4">
</video>
</div>
</div>
HTML
end
end
end
end
result
end
|