pawoo: convert commentary to dtext.
This commit is contained in:
@@ -27,8 +27,12 @@ module Sources::Strategies
|
||||
"Pawoo"
|
||||
end
|
||||
|
||||
def api_response
|
||||
@response ||= PawooApiClient.new.get_status(normalized_url)
|
||||
end
|
||||
|
||||
def get
|
||||
response = PawooApiClient.new.get_status(normalized_url)
|
||||
response = api_response
|
||||
@artist_name = response.account_name
|
||||
@profile_url = response.account_profile_url
|
||||
@image_url = response.image_urls.first
|
||||
@@ -49,5 +53,34 @@ module Sources::Strategies
|
||||
def normalizable_for_artist_finder?
|
||||
true
|
||||
end
|
||||
|
||||
def dtext_artist_commentary_desc
|
||||
to_dtext(artist_commentary_desc)
|
||||
end
|
||||
|
||||
def to_dtext(text)
|
||||
html = Nokogiri::HTML.fragment(text)
|
||||
|
||||
dtext = html.children.map do |element|
|
||||
case element.name
|
||||
when "text"
|
||||
element.content
|
||||
when "p"
|
||||
to_dtext(element.inner_html) + "\n\n"
|
||||
when "a"
|
||||
# don't include links to the toot itself.
|
||||
media_urls = api_response.json["media_attachments"].map { |attr| attr["text_url"] }
|
||||
next if element.attribute("href").value.in?(media_urls)
|
||||
|
||||
title = to_dtext(element.inner_html)
|
||||
url = element.attributes["href"].value
|
||||
%("#{title}":[#{url}])
|
||||
else
|
||||
to_dtext(element.inner_html)
|
||||
end
|
||||
end.join.strip
|
||||
|
||||
dtext
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,6 +19,16 @@ module Sources
|
||||
should "get the image url" do
|
||||
assert_equal("https://img.pawoo.net/media_attachments/files/000/128/953/original/4c0a06087b03343f.png", @site.image_url)
|
||||
end
|
||||
|
||||
should "get the commentary" do
|
||||
desc = '<p>a mind forever voyaging through strange seas of thought alone <a href="https://pawoo.net/media/9hJzXvwxVl1CezW0ecM" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="ellipsis">pawoo.net/media/9hJzXvwxVl1Cez</span><span class="invisible">W0ecM</span></a></p>'
|
||||
assert_equal(desc, @site.artist_commentary_desc)
|
||||
end
|
||||
|
||||
should "get the dtext-ified commentary" do
|
||||
desc = 'a mind forever voyaging through strange seas of thought alone'
|
||||
assert_equal(desc, @site.dtext_artist_commentary_desc)
|
||||
end
|
||||
end
|
||||
|
||||
context "The source site for a https://pawoo.net/$user/$id url" do
|
||||
|
||||
Reference in New Issue
Block a user