Fix #4110: New Twitter image urls are broken in bookmarklet.
This commit is contained in:
@@ -4,6 +4,13 @@ module Sources::Strategies
|
|||||||
ASSET = %r!\A(https?://(?:video|pbs)\.twimg\.com/media/)!i
|
ASSET = %r!\A(https?://(?:video|pbs)\.twimg\.com/media/)!i
|
||||||
PROFILE = %r!\Ahttps?://(?:mobile\.)?twitter.com/(?<username>[a-z0-9_]+)!i
|
PROFILE = %r!\Ahttps?://(?:mobile\.)?twitter.com/(?<username>[a-z0-9_]+)!i
|
||||||
|
|
||||||
|
# https://pbs.twimg.com/media/EBGbJe_U8AA4Ekb.jpg
|
||||||
|
# https://pbs.twimg.com/media/EBGbJe_U8AA4Ekb?format=jpg&name=900x900
|
||||||
|
BASE_IMAGE_URL = %r!\Ahttps?://pbs\.twimg\.com/media!i
|
||||||
|
FILENAME1 = %r!(?<file_name>\w+)\.(?<file_ext>\w+)!i
|
||||||
|
FILENAME2 = %r!(?<file_name>\w+)\?.*format=(?<file_ext>\w+)!i
|
||||||
|
IMAGE_URL = %r!#{BASE_IMAGE_URL}/#{Regexp.union(FILENAME1, FILENAME2)}!i
|
||||||
|
|
||||||
# Twitter provides a list but it's inaccurate; some names ('intent') aren't
|
# Twitter provides a list but it's inaccurate; some names ('intent') aren't
|
||||||
# included and other names in the list aren't actually reserved.
|
# included and other names in the list aren't actually reserved.
|
||||||
# https://developer.twitter.com/en/docs/developer-utilities/configuration/api-reference/get-help-configuration
|
# https://developer.twitter.com/en/docs/developer-utilities/configuration/api-reference/get-help-configuration
|
||||||
@@ -40,8 +47,8 @@ module Sources::Strategies
|
|||||||
end
|
end
|
||||||
|
|
||||||
def image_urls
|
def image_urls
|
||||||
if url =~ /(#{ASSET}[^:]+)/
|
if url =~ IMAGE_URL
|
||||||
[$1 + ":orig" ]
|
["https://pbs.twimg.com/media/#{$~[:file_name]}.#{$~[:file_ext]}:orig"]
|
||||||
elsif api_response.present?
|
elsif api_response.present?
|
||||||
service.image_urls(api_response)
|
service.image_urls(api_response)
|
||||||
else
|
else
|
||||||
@@ -57,7 +64,7 @@ module Sources::Strategies
|
|||||||
end
|
end
|
||||||
|
|
||||||
def page_url
|
def page_url
|
||||||
return "" if status_id.blank? || artist_name.blank?
|
return nil if status_id.blank? || artist_name.blank?
|
||||||
"https://twitter.com/#{artist_name}/status/#{status_id}"
|
"https://twitter.com/#{artist_name}/status/#{status_id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ module Sources
|
|||||||
assert_equal(urls, @site.image_urls)
|
assert_equal(urls, @site.image_urls)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "A video" do
|
context "A video" do
|
||||||
setup do
|
setup do
|
||||||
@site = Sources::Strategies.find("https://twitter.com/CincinnatiZoo/status/859073537713328129")
|
@site = Sources::Strategies.find("https://twitter.com/CincinnatiZoo/status/859073537713328129")
|
||||||
@@ -179,6 +179,18 @@ module Sources
|
|||||||
end
|
end
|
||||||
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 = Sources::Strategies.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_url)
|
||||||
|
assert_equal(["https://pbs.twimg.com/media/EBGp2YdUYAA19Uj.jpg:orig"], @site.image_urls)
|
||||||
|
assert_equal("https://pbs.twimg.com/media/EBGp2YdUYAA19Uj.jpg:orig", @site.canonical_url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "The source site for a https://twitter.com/i/web/status/:id url" do
|
context "The source site for a https://twitter.com/i/web/status/:id url" do
|
||||||
setup do
|
setup do
|
||||||
@site = Sources::Strategies.find("https://twitter.com/i/web/status/943446161586733056")
|
@site = Sources::Strategies.find("https://twitter.com/i/web/status/943446161586733056")
|
||||||
|
|||||||
Reference in New Issue
Block a user