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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/Parsers/IframeParser.rb', line 21
def parse(paragraph)
jekyllOpen = ""
if isForJekyll
jekyllOpen = "{:target=\"_blank\"}"
end
if paragraph.type == 'IFRAME'
return unless paragraph.iframe
if !paragraph.iframe.src.nil? && paragraph.iframe.src != ""
url = paragraph.iframe.src
else
url = "https://medium.com/media/#{paragraph.iframe.id}"
end
result = "[#{paragraph.iframe.title}](#{url})#{jekyllOpen}"
if !url[/(www\.youtube\.com)/].nil?
youtubeURL = URI(URI.decode(url)).query
params = URI::decode_www_form(youtubeURL).to_h
if !params["image"].nil? && !params["url"].nil?
fileName = "#{paragraph.name}_#{URI(params["image"]).path.split("/").last}"
imageURL = params["image"]
imagePathPolicy = PathPolicy.new(pathPolicy.getAbsolutePath(paragraph.postID), pathPolicy.getRelativePath(paragraph.postID))
absolutePath = imagePathPolicy.getAbsolutePath(fileName)
title = paragraph.iframe.title
if title.nil? or title == ""
title = "Youtube"
end
if ImageDownloader.download(absolutePath, imageURL)
relativePath = imagePathPolicy.getRelativePath(fileName)
if isForJekyll
result = "\r\n\r\n[](#{params["url"]})#{jekyllOpen}\r\n\r\n"
else
result = "\r\n\r\n[](#{params["url"]})#{jekyllOpen}\r\n\r\n"
end
else
result = "\r\n[#{title}](#{params["url"]})#{jekyllOpen}\r\n"
end
end
else
html = Request.html(Request.URL(url))
return "" unless html
src = html.search('script').first
srce = src.attribute('src') if src
result = nil
if !srce.to_s[/^(https\:\/\/gist\.github\.com)/].nil?
gist = Request.body(Request.URL(srce)).scan(/(document\.write\('){1}(.*)(\)){1}/)[1][1]
gist.gsub! '\n', ''
gist.gsub! '\"', '"'
gist.gsub! '<\/', '</'
gistHTML = Nokogiri::HTML(gist)
lang = gistHTML.search('table').first['data-tagsearch-lang'].downcase
if isForJekyll and lang == "objective-c"
lang = "objectivec"
end
gistHTML.search('a').each do |a|
if a.text == 'view raw'
gistRAW = Request.body(Request.URL(a['href']))
result = "```#{lang}\n"
result += gistRAW.chomp
result += "\n```"
end
end
else
ogURL = url
if !url[/(cdn\.embedly\.com)/].nil?
params = URI::decode_www_form(URI(URI.decode(url)).query).to_h
if !params["url"].nil?
ogURL = params["url"]
end
end
= ogURL[/^(https\:\/\/twitter\.com\/){1}.+(\/){1}(\d+)/, 3]
if !.nil?
uri = URI("https://api.twitter.com/1.1/statuses/show.json?simple_quoted_tweet=true&include_entities=true&tweet_mode=extended&include_cards=1&id=#{}")
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
request = Net::HTTP::Get.new(uri)
request['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.17.375.766 Safari/537.36';
request['Authorization'] = 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA';
response = https.request(request)
if response.code.to_i == 200
= JSON.parse(response.read_body)
fullText = ["full_text"]
["entities"]["user_mentions"].each do |user_mention|
fullText = fullText.gsub(user_mention["screen_name"],"[#{user_mention["screen_name"]}](https://twitter.com/#{user_mention["screen_name"]})")
end
["entities"]["urls"].each do |url|
fullText = fullText.gsub(url["url"],"[#{url["display_url"]}](#{url["expanded_url"]})")
end
createdAt = Time.parse(["created_at"]).strftime('%Y-%m-%d %H:%M:%S')
result = "\n\n"
result += "■■■■■■■■■■■■■■ \n"
result += "> **[#{["user"]["name"]}](https://twitter.com/#{["user"]["screen_name"]})#{jekyllOpen} @ Twitter Says:** \n\n"
result += "> > #{fullText} \n\n"
result += "> **Tweeted at [#{createdAt}](#{ogURL})#{jekyllOpen}.** \n\n"
result += "■■■■■■■■■■■■■■ \n\n"
end
elsif ![/^(https\:\/\/app\.widgetic\.com)/].nil?
result = nil
else
ogImageURL = Helper.fetchOGImage(ogURL)
title = paragraph.iframe.title
if title.nil? or title == ""
title = Helper.escapeMarkdown(ogURL)
end
if !ogImageURL.nil?
result = "\r\n\r\n[](#{ogURL})#{jekyllOpen}\r\n\r\n"
else
result = "[#{title}](#{ogURL})#{jekyllOpen}"
end
end
end
end
result
else
if !nextParser.nil?
nextParser.parse(paragraph)
end
end
end
|