Twitter: rewrite tests
Also add partial support for profile banner images.
This commit is contained in:
@@ -58,13 +58,16 @@ class Source::Extractor
|
|||||||
end
|
end
|
||||||
|
|
||||||
def intent_url
|
def intent_url
|
||||||
user_id = api_response.dig(:user, :id_str)
|
|
||||||
return nil if user_id.blank?
|
return nil if user_id.blank?
|
||||||
"https://twitter.com/intent/user?user_id=#{user_id}"
|
"https://twitter.com/intent/user?user_id=#{user_id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def profile_urls
|
def profile_urls
|
||||||
[profile_url, intent_url].compact
|
[profile_url, intent_url].compact.uniq
|
||||||
|
end
|
||||||
|
|
||||||
|
def user_id
|
||||||
|
parsed_url.user_id || parsed_referer&.user_id || api_response.dig(:user, :id_str)
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_name
|
def tag_name
|
||||||
@@ -72,8 +75,6 @@ class Source::Extractor
|
|||||||
tag_name_from_url
|
tag_name_from_url
|
||||||
elsif api_response.present?
|
elsif api_response.present?
|
||||||
api_response.dig(:user, :screen_name)
|
api_response.dig(:user, :screen_name)
|
||||||
else
|
|
||||||
""
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,6 @@
|
|||||||
# * https://video.twimg.com/ext_tw_video/1496554514312269828/pu/vid/480x360/amWjOw0MmLdnPMPB.mp4?tag=12
|
# * https://video.twimg.com/ext_tw_video/1496554514312269828/pu/vid/480x360/amWjOw0MmLdnPMPB.mp4?tag=12
|
||||||
#
|
#
|
||||||
# Profile image URLs:
|
# Profile image URLs:
|
||||||
#
|
|
||||||
# * https://pbs.twimg.com/profile_banners/780804311529906176/1475001696
|
|
||||||
# * https://pbs.twimg.com/profile_images/1493345400929112064/lF1mY1i2_normal.jpg
|
# * https://pbs.twimg.com/profile_images/1493345400929112064/lF1mY1i2_normal.jpg
|
||||||
#
|
#
|
||||||
# Shortened URLs:
|
# Shortened URLs:
|
||||||
@@ -71,6 +69,8 @@ class Source::URL::Twitter < Source::URL
|
|||||||
# https://pbs.twimg.com/amplify_video_thumb/1215590775364259840/img/lolCkEEioFZTb5dl.jpg
|
# https://pbs.twimg.com/amplify_video_thumb/1215590775364259840/img/lolCkEEioFZTb5dl.jpg
|
||||||
in "twimg.com", ("media" | "tweet_video_thumb" | "ext_tw_video_thumb" | "amplify_video_thumb") => media_type, *subdirs, file
|
in "twimg.com", ("media" | "tweet_video_thumb" | "ext_tw_video_thumb" | "amplify_video_thumb") => media_type, *subdirs, file
|
||||||
# EBGbJe_U8AA4Ekb.jpg:small
|
# EBGbJe_U8AA4Ekb.jpg:small
|
||||||
|
@media_type = media_type
|
||||||
|
|
||||||
@file, @file_size = file.split(":")
|
@file, @file_size = file.split(":")
|
||||||
@file, @file_ext = @file.split(".")
|
@file, @file_ext = @file.split(".")
|
||||||
|
|
||||||
@@ -80,7 +80,14 @@ class Source::URL::Twitter < Source::URL
|
|||||||
|
|
||||||
# /media/EBGbJe_U8AA4Ekb.jpg
|
# /media/EBGbJe_U8AA4Ekb.jpg
|
||||||
# /ext_tw_video_thumb/1243725361986375680/pu/img/JDA7g7lcw7wK-PIv.jpg
|
# /ext_tw_video_thumb/1243725361986375680/pu/img/JDA7g7lcw7wK-PIv.jpg
|
||||||
@file_path = File.join(media_type, subdirs.join("/"), "#{@file}.#{@file_ext}")
|
@file_path = File.join(@media_type, subdirs.join("/"), "#{@file}.#{@file_ext}")
|
||||||
|
|
||||||
|
# https://pbs.twimg.com/profile_banners/780804311529906176/1475001696
|
||||||
|
# https://pbs.twimg.com/profile_banners/780804311529906176/1475001696/600x200
|
||||||
|
in "twimg.com", "profile_banners" => media_type, /^\d+$/ => user_id, /^\d+$/ => file_id, *dimensions
|
||||||
|
@user_id = user_id
|
||||||
|
@media_type = media_type
|
||||||
|
@file_path = "profile_banners/#{user_id}/#{file_id}/1500x500"
|
||||||
|
|
||||||
# https://twitter.com/motty08111213
|
# https://twitter.com/motty08111213
|
||||||
# https://twitter.com/motty08111213/likes
|
# https://twitter.com/motty08111213/likes
|
||||||
@@ -102,7 +109,11 @@ class Source::URL::Twitter < Source::URL
|
|||||||
# https://pbs.twimg.com/amplify_video_thumb/1215590775364259840/img/lolCkEEioFZTb5dl.jpg:orig
|
# https://pbs.twimg.com/amplify_video_thumb/1215590775364259840/img/lolCkEEioFZTb5dl.jpg:orig
|
||||||
def full_image_url
|
def full_image_url
|
||||||
return to_s unless @file_path.present?
|
return to_s unless @file_path.present?
|
||||||
"#{site}/#{@file_path}:orig"
|
if @media_type == "profile_banners"
|
||||||
|
"#{site}/#{@file_path}"
|
||||||
|
else
|
||||||
|
"#{site}/#{@file_path}:orig"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def page_url
|
def page_url
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ module SourceTestHelper
|
|||||||
should_match_source_data(strategy, arguments)
|
should_match_source_data(strategy, arguments)
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_download_successfully(strategy, download_size = nil)
|
def should_download_successfully(strategy, download_size = nil) # XXX perhaps refactor into should_upload_successfully in order to streamline the source tests further?
|
||||||
should "download successfully" do
|
should "download successfully" do
|
||||||
file = strategy.download_file!(strategy.image_urls.first)
|
file = strategy.download_file!(strategy.image_urls.first)
|
||||||
if download_size.present?
|
if download_size.present?
|
||||||
@@ -56,8 +56,8 @@ module SourceTestHelper
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
should "not incorrectly extract a profile url or artist data when there's none to be found" do
|
should "not incorrectly extract a profile url or artist data when there's none to be found" do
|
||||||
assert_nil(strategy.profile_url)
|
assert_nil(strategy.profile_url.presence)
|
||||||
assert_nil(strategy.artist_name)
|
assert_nil(strategy.artist_name.presence)
|
||||||
assert_equal([], strategy.other_names)
|
assert_equal([], strategy.other_names)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,181 +6,6 @@ module Sources
|
|||||||
skip "Twitter credentials are not configured" if !Source::Extractor::Twitter.enabled?
|
skip "Twitter credentials are not configured" if !Source::Extractor::Twitter.enabled?
|
||||||
end
|
end
|
||||||
|
|
||||||
context "An extended tweet" do
|
|
||||||
should "extract the correct image url" do
|
|
||||||
@site = Source::Extractor.find("https://twitter.com/onsen_musume_jp/status/865534101918330881")
|
|
||||||
assert_equal(["https://pbs.twimg.com/media/DAL-ntWV0AEbhes.jpg:orig"], @site.image_urls)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "extract all the image urls" do
|
|
||||||
@site = Source::Extractor.find("https://twitter.com/baalbuddy/status/1455330043828264963")
|
|
||||||
|
|
||||||
urls = %w[
|
|
||||||
https://pbs.twimg.com/media/FDJekEfX0AQZ-Mx.png:orig
|
|
||||||
https://pbs.twimg.com/media/FDJekEkWYAICHzF.png:orig
|
|
||||||
https://pbs.twimg.com/media/FDJekEiWEAEsPky.png:orig
|
|
||||||
https://pbs.twimg.com/media/FDJekEkWEAo4sMQ.png:orig
|
|
||||||
]
|
|
||||||
|
|
||||||
assert_equal(urls, @site.image_urls)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "A video" do
|
|
||||||
should "get the correct urls" do
|
|
||||||
@site = Source::Extractor.find("https://twitter.com/CincinnatiZoo/status/859073537713328129")
|
|
||||||
assert_equal(["https://video.twimg.com/ext_tw_video/859073467769126913/pu/vid/1280x720/cPGgVROXHy3yrK6u.mp4"], @site.image_urls)
|
|
||||||
assert_equal("https://twitter.com/CincinnatiZoo/status/859073537713328129", @site.page_url)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "work when given a video thumbnail" do
|
|
||||||
# https://twitter.com/Kekeflipnote/status/1241038667898118144
|
|
||||||
@site = Source::Extractor.find("https://pbs.twimg.com/tweet_video_thumb/ETkN_L3X0AMy1aT.jpg:small")
|
|
||||||
assert_equal(["https://pbs.twimg.com/tweet_video_thumb/ETkN_L3X0AMy1aT.jpg:orig"], @site.image_urls)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "work when given an external video thumbnail" do
|
|
||||||
# https://twitter.com/chivedips/status/1243850897056133121
|
|
||||||
@site = Source::Extractor.find("https://pbs.twimg.com/ext_tw_video_thumb/1243725361986375680/pu/img/JDA7g7lcw7wK-PIv.jpg:small")
|
|
||||||
assert_equal(["https://pbs.twimg.com/ext_tw_video_thumb/1243725361986375680/pu/img/JDA7g7lcw7wK-PIv.jpg:orig"], @site.image_urls)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "work when given an amplify video thumbnail" do
|
|
||||||
# https://twitter.com/UNITED_CINEMAS/status/1223138847417978881
|
|
||||||
@site = Source::Extractor.find("https://pbs.twimg.com/amplify_video_thumb/1215590775364259840/img/lolCkEEioFZTb5dl.jpg:small")
|
|
||||||
assert_equal(["https://pbs.twimg.com/amplify_video_thumb/1215590775364259840/img/lolCkEEioFZTb5dl.jpg:orig"], @site.image_urls)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "An animated gif" do
|
|
||||||
setup do
|
|
||||||
@site = Source::Extractor.find("https://twitter.com/i/web/status/1252517866059907073")
|
|
||||||
end
|
|
||||||
|
|
||||||
should "get the image url" do
|
|
||||||
assert_equal(["https://video.twimg.com/tweet_video/EWHWVrmVcAAp4Vw.mp4"], @site.image_urls)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "A twitter summary card from twitter with a :large image" do
|
|
||||||
setup do
|
|
||||||
@site = Source::Extractor.find("https://twitter.com/aranobu/status/817736083567820800")
|
|
||||||
end
|
|
||||||
|
|
||||||
should "get the image url" do
|
|
||||||
assert_equal(["https://pbs.twimg.com/media/C1kt72yVEAEGpOv.jpg:orig"], @site.image_urls)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "get the page url" do
|
|
||||||
assert_equal("https://twitter.com/aranobu/status/817736083567820800", @site.page_url)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "The source site for a restricted twitter" do
|
|
||||||
setup do
|
|
||||||
@site = Source::Extractor.find("https://mobile.twitter.com/Strangestone/status/556440271961858051")
|
|
||||||
end
|
|
||||||
|
|
||||||
should "get the urls" do
|
|
||||||
assert_equal(["https://pbs.twimg.com/media/B7jfc1JCcAEyeJh.png:orig"], @site.image_urls)
|
|
||||||
assert_equal("https://twitter.com/Strangestone/status/556440271961858051", @site.page_url)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "A tweet without any images" do
|
|
||||||
should "not fail" do
|
|
||||||
@site = Source::Extractor.find("https://twitter.com/teruyo/status/1058452066060853248")
|
|
||||||
|
|
||||||
assert_equal([], @site.image_urls)
|
|
||||||
assert_nothing_raised { @site.to_h }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "The source site for twitter" do
|
|
||||||
setup do
|
|
||||||
@site = Source::Extractor.find("https://mobile.twitter.com/nounproject/status/540944400767922176")
|
|
||||||
end
|
|
||||||
|
|
||||||
should "get the main profile url" do
|
|
||||||
assert_equal("https://twitter.com/nounproject", @site.profile_url)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "get the profile urls" do
|
|
||||||
assert_includes(@site.profile_urls, "https://twitter.com/nounproject")
|
|
||||||
assert_includes(@site.profile_urls, "https://twitter.com/intent/user?user_id=88996186")
|
|
||||||
end
|
|
||||||
|
|
||||||
should "get the artist name" do
|
|
||||||
assert_equal("Noun Project", @site.artist_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "get the image urls" do
|
|
||||||
assert_equal(["https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:orig"], @site.image_urls)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "get the page url" do
|
|
||||||
assert_equal("https://twitter.com/nounproject/status/540944400767922176", @site.page_url)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "get the tags" do
|
|
||||||
assert_equal([], @site.tags)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "get the artist commentary" do
|
|
||||||
assert_not_nil(@site.artist_commentary_desc)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "convert a page into a json representation" do
|
|
||||||
assert_nothing_raised do
|
|
||||||
@site.to_json
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "The source site for a direct image and a referer" do
|
|
||||||
setup do
|
|
||||||
@site = Source::Extractor.find("https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:large", "https://twitter.com/nounproject/status/540944400767922176")
|
|
||||||
end
|
|
||||||
|
|
||||||
should "get the source data" do
|
|
||||||
assert_equal("nounproject", @site.tag_name)
|
|
||||||
assert_equal("Noun Project", @site.artist_name)
|
|
||||||
assert_equal(["https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:orig"], @site.image_urls)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "The source site for a direct image url (pbs.twimg.com/media/*.jpg) without a referer url" do
|
|
||||||
setup do
|
|
||||||
@site = Source::Extractor.find("https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:large")
|
|
||||||
end
|
|
||||||
|
|
||||||
should "work" do
|
|
||||||
assert_equal(["https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:orig"], @site.image_urls)
|
|
||||||
assert(@site.artist_name.blank?)
|
|
||||||
assert(@site.profile_url.blank?)
|
|
||||||
assert(@site.artists.empty?)
|
|
||||||
assert(@site.tags.empty?)
|
|
||||||
assert(@site.artist_commentary_desc.blank?)
|
|
||||||
assert(@site.dtext_artist_commentary_desc.blank?)
|
|
||||||
assert_nothing_raised { @site.to_h }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "The source site for a direct image url (pbs.twimg.com/media/*?format=jpg&name=*) without a referer url" do
|
|
||||||
setup do
|
|
||||||
@site = Source::Extractor.find("https://pbs.twimg.com/media/EBGp2YdUYAA19Uj?format=jpg&name=small")
|
|
||||||
end
|
|
||||||
|
|
||||||
should "work" do
|
|
||||||
assert_equal(["https://pbs.twimg.com/media/EBGp2YdUYAA19Uj.jpg:orig"], @site.image_urls)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "work for filenames containing dashes" do
|
|
||||||
@site = Source::Extractor.find("https://pbs.twimg.com/media/EAjc-OWVAAAxAgQ.jpg", "https://twitter.com/asteroid_ill/status/1155420330128625664")
|
|
||||||
assert_equal(["https://pbs.twimg.com/media/EAjc-OWVAAAxAgQ.jpg:orig"], @site.image_urls)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "A https://twitter.com/:username/status/:id url" do
|
context "A https://twitter.com/:username/status/:id url" do
|
||||||
strategy_should_work(
|
strategy_should_work(
|
||||||
"https://twitter.com/motty08111213/status/943446161586733056",
|
"https://twitter.com/motty08111213/status/943446161586733056",
|
||||||
@@ -188,12 +13,13 @@ module Sources
|
|||||||
image_urls: [
|
image_urls: [
|
||||||
"https://pbs.twimg.com/media/DRfKHmgV4AAycFB.jpg:orig",
|
"https://pbs.twimg.com/media/DRfKHmgV4AAycFB.jpg:orig",
|
||||||
"https://pbs.twimg.com/media/DRfKHioVoAALRlK.jpg:orig",
|
"https://pbs.twimg.com/media/DRfKHioVoAALRlK.jpg:orig",
|
||||||
"https://pbs.twimg.com/media/DRfKHgHU8AE7alV.jpg:orig"
|
"https://pbs.twimg.com/media/DRfKHgHU8AE7alV.jpg:orig",
|
||||||
],
|
],
|
||||||
|
download_size: 275_713,
|
||||||
profile_url: "https://twitter.com/motty08111213",
|
profile_url: "https://twitter.com/motty08111213",
|
||||||
artist_name: "えのぐマネージャー 丸茂",
|
artist_name: "えのぐマネージャー 丸茂",
|
||||||
tag_name: "motty08111213",
|
tag_name: "motty08111213",
|
||||||
tags: ["岩本町芸能社", "女優部"],
|
tags: ["岩本町芸能社", "女優部"]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -204,12 +30,13 @@ module Sources
|
|||||||
image_urls: [
|
image_urls: [
|
||||||
"https://pbs.twimg.com/media/DRfKHmgV4AAycFB.jpg:orig",
|
"https://pbs.twimg.com/media/DRfKHmgV4AAycFB.jpg:orig",
|
||||||
"https://pbs.twimg.com/media/DRfKHioVoAALRlK.jpg:orig",
|
"https://pbs.twimg.com/media/DRfKHioVoAALRlK.jpg:orig",
|
||||||
"https://pbs.twimg.com/media/DRfKHgHU8AE7alV.jpg:orig"
|
"https://pbs.twimg.com/media/DRfKHgHU8AE7alV.jpg:orig",
|
||||||
],
|
],
|
||||||
|
download_size: 275_713,
|
||||||
profile_url: "https://twitter.com/motty08111213",
|
profile_url: "https://twitter.com/motty08111213",
|
||||||
artist_name: "えのぐマネージャー 丸茂",
|
artist_name: "えのぐマネージャー 丸茂",
|
||||||
tag_name: "motty08111213",
|
tag_name: "motty08111213",
|
||||||
tags: ["岩本町芸能社", "女優部"],
|
tags: ["岩本町芸能社", "女優部"]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -220,107 +47,165 @@ module Sources
|
|||||||
image_urls: [
|
image_urls: [
|
||||||
"https://pbs.twimg.com/media/DRfKHmgV4AAycFB.jpg:orig",
|
"https://pbs.twimg.com/media/DRfKHmgV4AAycFB.jpg:orig",
|
||||||
"https://pbs.twimg.com/media/DRfKHioVoAALRlK.jpg:orig",
|
"https://pbs.twimg.com/media/DRfKHioVoAALRlK.jpg:orig",
|
||||||
"https://pbs.twimg.com/media/DRfKHgHU8AE7alV.jpg:orig"
|
"https://pbs.twimg.com/media/DRfKHgHU8AE7alV.jpg:orig",
|
||||||
],
|
],
|
||||||
|
download_size: 275_713,
|
||||||
profile_url: "https://twitter.com/motty08111213",
|
profile_url: "https://twitter.com/motty08111213",
|
||||||
artist_name: "えのぐマネージャー 丸茂",
|
artist_name: "えのぐマネージャー 丸茂",
|
||||||
tag_name: "motty08111213",
|
tag_name: "motty08111213",
|
||||||
tags: ["岩本町芸能社", "女優部"],
|
tags: ["岩本町芸能社", "女優部"]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "A video tweet" do
|
||||||
|
strategy_should_work(
|
||||||
|
"https://twitter.com/CincinnatiZoo/status/859073537713328129",
|
||||||
|
image_urls: ["https://video.twimg.com/ext_tw_video/859073467769126913/pu/vid/1280x720/cPGgVROXHy3yrK6u.mp4"],
|
||||||
|
page_url: "https://twitter.com/CincinnatiZoo/status/859073537713328129",
|
||||||
|
download_size: 8_602_983
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "A video thumbnail" do
|
||||||
|
# https://twitter.com/Kekeflipnote/status/1241038667898118144
|
||||||
|
strategy_should_work(
|
||||||
|
"https://pbs.twimg.com/tweet_video_thumb/ETkN_L3X0AMy1aT.jpg:small",
|
||||||
|
image_urls: ["https://pbs.twimg.com/tweet_video_thumb/ETkN_L3X0AMy1aT.jpg:orig"],
|
||||||
|
download_size: 18_058
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "An external video thumbnail" do
|
||||||
|
strategy_should_work(
|
||||||
|
"https://pbs.twimg.com/ext_tw_video_thumb/1578376127801761793/pu/img/oGcUqPnwRYYhk-gi.jpg:small",
|
||||||
|
image_urls: ["https://pbs.twimg.com/ext_tw_video_thumb/1578376127801761793/pu/img/oGcUqPnwRYYhk-gi.jpg:orig"],
|
||||||
|
download_size: 243_227
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "An amplify video thumbnail" do
|
||||||
|
# https://twitter.com/UNITED_CINEMAS/status/1223138847417978881
|
||||||
|
strategy_should_work(
|
||||||
|
"https://pbs.twimg.com/amplify_video_thumb/1215590775364259840/img/lolCkEEioFZTb5dl.jpg:small",
|
||||||
|
image_urls: ["https://pbs.twimg.com/amplify_video_thumb/1215590775364259840/img/lolCkEEioFZTb5dl.jpg:orig"],
|
||||||
|
download_size: 106_942
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "A tweet with an animated gif" do
|
||||||
|
strategy_should_work(
|
||||||
|
"https://twitter.com/i/web/status/1252517866059907073",
|
||||||
|
image_urls: ["https://video.twimg.com/tweet_video/EWHWVrmVcAAp4Vw.mp4"],
|
||||||
|
download_size: 542_833
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "A restricted tweet" do
|
||||||
|
strategy_should_work(
|
||||||
|
"https://mobile.twitter.com/Strangestone/status/556440271961858051",
|
||||||
|
image_urls: ["https://pbs.twimg.com/media/B7jfc1JCcAEyeJh.png:orig"],
|
||||||
|
page_url: "https://twitter.com/Strangestone/status/556440271961858051",
|
||||||
|
profile_url: "https://twitter.com/Strangestone",
|
||||||
|
profile_urls: ["https://twitter.com/Strangestone", "https://twitter.com/intent/user?user_id=93332575"],
|
||||||
|
tag_name: "Strangestone",
|
||||||
|
artist_name: "比村奇石",
|
||||||
|
dtext_artist_commentary_desc: "ブレザーが描きたかったのでJK鈴谷"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "A tweet without any images" do
|
||||||
|
strategy_should_work(
|
||||||
|
"https://twitter.com/teruyo/status/1058452066060853248",
|
||||||
|
profile_url: "https://twitter.com/teruyo",
|
||||||
|
image_urls: []
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "A direct image url" do
|
||||||
|
strategy_should_work(
|
||||||
|
"https://pbs.twimg.com/media/EBGp2YdUYAA19Uj?format=jpg&name=small",
|
||||||
|
image_urls: ["https://pbs.twimg.com/media/EBGp2YdUYAA19Uj.jpg:orig"],
|
||||||
|
download_size: 229_661,
|
||||||
|
profile_url: nil
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "A direct image url with dashes" do
|
||||||
|
strategy_should_work(
|
||||||
|
"https://pbs.twimg.com/media/EAjc-OWVAAAxAgQ.jpg",
|
||||||
|
image_urls: ["https://pbs.twimg.com/media/EAjc-OWVAAAxAgQ.jpg:orig"],
|
||||||
|
download_size: 842_373,
|
||||||
|
profile_url: nil
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "A deleted tweet" do
|
context "A deleted tweet" do
|
||||||
should "still find the artist name" do
|
strategy_should_work(
|
||||||
@site = Source::Extractor.find("https://twitter.com/masayasuf/status/870734961778630656")
|
"https://twitter.com/masayasuf/status/870734961778630656",
|
||||||
@artist = FactoryBot.create(:artist, name: "masayasuf", url_string: @site.url)
|
deleted: true,
|
||||||
|
tag_name: "masayasuf",
|
||||||
assert_equal("masayasuf", @site.tag_name)
|
profile_url: "https://twitter.com/masayasuf"
|
||||||
assert_equal("https://twitter.com/masayasuf", @site.profile_url)
|
)
|
||||||
assert_equal([@artist], @site.artists)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "A tweet" do
|
|
||||||
setup do
|
|
||||||
@site = Source::Extractor.find("https://twitter.com/noizave/status/875768175136317440")
|
|
||||||
end
|
|
||||||
|
|
||||||
should "convert urls, hashtags, and mentions to dtext" do
|
|
||||||
desc = 'test "#foo":[https://twitter.com/hashtag/foo] "#ホワイトデー":[https://twitter.com/hashtag/ホワイトデー] "@noizave":[https://twitter.com/noizave]\'s blah http://www.example.com <>& 😀'
|
|
||||||
assert_equal(desc, @site.dtext_artist_commentary_desc)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "get the tags" do
|
|
||||||
tags = [
|
|
||||||
%w[foo https://twitter.com/hashtag/foo],
|
|
||||||
%w[ホワイトデー https://twitter.com/hashtag/ホワイトデー]
|
|
||||||
]
|
|
||||||
|
|
||||||
assert_equal(tags, @site.tags)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "A profile banner image" do
|
|
||||||
should "work" do
|
|
||||||
@site = Source::Extractor.find("https://pbs.twimg.com/profile_banners/1225702850002468864/1588597370/1500x500")
|
|
||||||
assert_equal([@site.url], @site.image_urls)
|
|
||||||
assert_nothing_raised { @site.to_h }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "A tweet containing non-normalized Unicode text" do
|
|
||||||
should "be normalized to nfkc" do
|
|
||||||
site = Source::Extractor.find("https://twitter.com/aprilarcus/status/367557195186970624")
|
|
||||||
desc1 = "𝖸𝗈 𝐔𝐧𝐢𝐜𝐨𝐝𝐞 𝗅 𝗁𝖾𝗋𝖽 𝕌 𝗅𝗂𝗄𝖾 𝑡𝑦𝑝𝑒𝑓𝑎𝑐𝑒𝑠 𝗌𝗈 𝗐𝖾 𝗉𝗎𝗍 𝗌𝗈𝗆𝖾 𝚌𝚘𝚍𝚎𝚙𝚘𝚒𝚗𝚝𝚜 𝗂𝗇 𝗒𝗈𝗎𝗋 𝔖𝔲𝔭𝔭𝔩𝔢𝔪𝔢𝔫𝔱𝔞𝔯𝔶 𝔚𝔲𝔩𝔱𝔦𝔩𝔦𝔫𝔤𝔳𝔞𝔩 𝔓𝔩𝔞𝔫𝔢 𝗌𝗈 𝗒𝗈𝗎 𝖼𝖺𝗇 𝓮𝓷𝓬𝓸𝓭𝓮 𝕗𝕠𝕟𝕥𝕤 𝗂𝗇 𝗒𝗈𝗎𝗋 𝒇𝒐𝒏𝒕𝒔."
|
|
||||||
desc2 = "Yo Unicode l herd U like typefaces so we put some codepoints in your Supplementary Wultilingval Plane so you can encode fonts in your fonts."
|
|
||||||
|
|
||||||
assert_equal(desc1, site.artist_commentary_desc)
|
|
||||||
assert_equal(desc2, site.dtext_artist_commentary_desc)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "normalize full-width hashtags" do
|
|
||||||
site = Source::Extractor.find("https://twitter.com/corpsmanWelt/status/1037724260075069441")
|
|
||||||
desc1 = %{新しいおともだち\n#けものフレンズ https://t.co/sEAuu16yAQ}
|
|
||||||
desc2 = %{新しいおともだち\n"#けものフレンズ":[https://twitter.com/hashtag/けものフレンズ]}
|
|
||||||
|
|
||||||
assert_equal(desc1, site.artist_commentary_desc)
|
|
||||||
assert_equal(desc2, site.dtext_artist_commentary_desc)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "A twitter post with a pixiv referer" do
|
|
||||||
should "use the twitter strategy" do
|
|
||||||
site = Source::Extractor.find("https://twitter.com/Mityubi/status/849630665603665920", "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=56735489")
|
|
||||||
|
|
||||||
assert_equal(site.site_name, "Twitter")
|
|
||||||
assert_equal(["https://pbs.twimg.com/media/C8p-gPhVoAMZupS.png:orig"], site.image_urls)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "A tweet from a suspended user" do
|
context "A tweet from a suspended user" do
|
||||||
should "not fail" do
|
strategy_should_work(
|
||||||
site = Source::Extractor.find("https://twitter.com/tanso_panz/status/1192429800717029377")
|
"https://twitter.com/tanso_panz/status/1192429800717029377",
|
||||||
|
tag_name: "tanso_panz",
|
||||||
assert_equal(site.site_name, "Twitter")
|
profile_url: "https://twitter.com/tanso_panz",
|
||||||
assert_equal("tanso_panz", site.tag_name)
|
image_urls: []
|
||||||
assert_equal("https://twitter.com/tanso_panz", site.profile_url)
|
)
|
||||||
assert_equal([], site.image_urls)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "A tweet with hashtags" do
|
context "A profile banner image" do
|
||||||
should "ignore common suffixes when translating hashtags" do
|
strategy_should_work(
|
||||||
as(create(:user)) do
|
"https://pbs.twimg.com/profile_banners/780804311529906176/1475001696",
|
||||||
create(:tag, name: "nishizumi_miho", post_count: 1)
|
image_urls: ["https://pbs.twimg.com/profile_banners/780804311529906176/1475001696/1500x500"],
|
||||||
create(:wiki_page, title: "nishizumi_miho", other_names: "西住みほ")
|
download_size: 128_141,
|
||||||
end
|
profile_url: nil
|
||||||
|
# profile_url: "https://twitter.com/intent/user?user_id=780804311529906176"
|
||||||
|
# XXX we COULD fully support these by setting the page_url to https://twitter.com/Kekeflipnote/header_photo, but it's a lot of work for a niche case
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
site = Source::Extractor.find("https://twitter.com/kasaishin100/status/1186658635226607616")
|
context "A profile banner image sample" do
|
||||||
|
strategy_should_work(
|
||||||
|
"https://pbs.twimg.com/profile_banners/780804311529906176/1475001696/600x200",
|
||||||
|
image_urls: ["https://pbs.twimg.com/profile_banners/780804311529906176/1475001696/1500x500"],
|
||||||
|
download_size: 128_141,
|
||||||
|
profile_url: nil
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
assert_includes(site.tags.map(&:first), "西住みほ生誕祭2019")
|
context "A tweet with hashtags with normalizable prefixes" do
|
||||||
assert_includes(site.normalized_tags, "西住みほ")
|
strategy_should_work(
|
||||||
assert_includes(site.translated_tags.map(&:name), "nishizumi_miho")
|
"https://twitter.com/kasaishin100/status/1186658635226607616",
|
||||||
end
|
tags: ["西住みほ生誕祭2019"],
|
||||||
|
normalized_tags: ["西住みほ"]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "A tweet with mentions that can be converted to dtext" do
|
||||||
|
strategy_should_work(
|
||||||
|
"https://twitter.com/noizave/status/875768175136317440",
|
||||||
|
dtext_artist_commentary_desc: 'test "#foo":[https://twitter.com/hashtag/foo] "#ホワイトデー":[https://twitter.com/hashtag/ホワイトデー] "@noizave":[https://twitter.com/noizave]\'s blah http://www.example.com <>& 😀'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "A tweet with normalizable unicode text" do
|
||||||
|
strategy_should_work(
|
||||||
|
"https://twitter.com/aprilarcus/status/367557195186970624",
|
||||||
|
artist_commentary_desc: "𝖸𝗈 𝐔𝐧𝐢𝐜𝐨𝐝𝐞 𝗅 𝗁𝖾𝗋𝖽 𝕌 𝗅𝗂𝗄𝖾 𝑡𝑦𝑝𝑒𝑓𝑎𝑐𝑒𝑠 𝗌𝗈 𝗐𝖾 𝗉𝗎𝗍 𝗌𝗈𝗆𝖾 𝚌𝚘𝚍𝚎𝚙𝚘𝚒𝚗𝚝𝚜 𝗂𝗇 𝗒𝗈𝗎𝗋 𝔖𝔲𝔭𝔭𝔩𝔢𝔪𝔢𝔫𝔱𝔞𝔯𝔶 𝔚𝔲𝔩𝔱𝔦𝔩𝔦𝔫𝔤𝔳𝔞𝔩 𝔓𝔩𝔞𝔫𝔢 𝗌𝗈 𝗒𝗈𝗎 𝖼𝖺𝗇 𝓮𝓷𝓬𝓸𝓭𝓮 𝕗𝕠𝕟𝕥𝕤 𝗂𝗇 𝗒𝗈𝗎𝗋 𝒇𝒐𝒏𝒕𝒔.",
|
||||||
|
dtext_artist_commentary_desc: "Yo Unicode l herd U like typefaces so we put some codepoints in your Supplementary Wultilingval Plane so you can encode fonts in your fonts."
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "A tweet with normalizable full-width hashtags" do
|
||||||
|
strategy_should_work(
|
||||||
|
"https://twitter.com/corpsmanWelt/status/1037724260075069441",
|
||||||
|
artist_commentary_desc: %{新しいおともだち\n#けものフレンズ https://t.co/sEAuu16yAQ},
|
||||||
|
dtext_artist_commentary_desc: %{新しいおともだち\n"#けものフレンズ":[https://twitter.com/hashtag/けものフレンズ]}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "Parse Twitter URLs correctly" do
|
should "Parse Twitter URLs correctly" do
|
||||||
@@ -343,7 +228,7 @@ module Sources
|
|||||||
assert(Source::URL.profile_url?("https://twitter.com/intent/user?screen_name=ryuudog_NFT"))
|
assert(Source::URL.profile_url?("https://twitter.com/intent/user?screen_name=ryuudog_NFT"))
|
||||||
assert(Source::URL.profile_url?("https://twitter.com/i/user/889592953"))
|
assert(Source::URL.profile_url?("https://twitter.com/i/user/889592953"))
|
||||||
|
|
||||||
refute(Source::URL.profile_url?("https://twitter.com/home"))
|
assert_not(Source::URL.profile_url?("https://twitter.com/home"))
|
||||||
|
|
||||||
assert_nil(Source::URL.parse("https://twitter.com/i/status/1261877313349640194").username)
|
assert_nil(Source::URL.parse("https://twitter.com/i/status/1261877313349640194").username)
|
||||||
assert_nil(Source::URL.parse("https://twitter.com/i/web/status/1261877313349640194").username)
|
assert_nil(Source::URL.parse("https://twitter.com/i/web/status/1261877313349640194").username)
|
||||||
|
|||||||
Reference in New Issue
Block a user