sources: add Instagram profile url normalization.
This commit is contained in:
@@ -31,6 +31,7 @@ module Source
|
||||
Source::URL::Fc2,
|
||||
Source::URL::Foundation,
|
||||
Source::URL::HentaiFoundry,
|
||||
Source::URL::Instagram,
|
||||
Source::URL::Lofter,
|
||||
Source::URL::Mastodon,
|
||||
Source::URL::Moebooru,
|
||||
|
||||
35
app/logical/source/url/instagram.rb
Normal file
35
app/logical/source/url/instagram.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Unhandled:
|
||||
#
|
||||
# https://scontent-lga3-1.cdninstagram.com/v/t51.2885-15/sh0.08/e35/s640x640/202831473_394388808595845_6890631933098833028_n.jpg?_nc_ht=scontent-lga3-1.cdninstagram.com&_nc_cat=109&_nc_ohc=Fcle68OyC80AX8VTGxs&edm=AABBvjUBAAAA&ccb=7-4&oh=00_AT_DYX0zhyNR9vo6ZFKfXjzEWqwFLLfEd3qcpAds5KIvnA&oe=6216DDB5&_nc_sid=83d603
|
||||
# https://instagram.fgyn2-1.fna.fbcdn.net/v/t51.2885-15/260126945_125485689990401_3753783352853967169_n.webp?stp=dst-jpg_e35_s750x750_sh0.08&_nc_ht=instagram.fgyn2-1.fna.fbcdn.net&_nc_cat=105&_nc_ohc=7njl7WM7D1cAX_oe4xv&tn=ZvUMUWKqovKgvpX-&edm=AABBvjUBAAAA&ccb=7-4&ig_cache_key=Mjc2NTM3ODUzMDE2MTA4OTMyNw==.2-ccb7-4&oh=00_AT9T3WAiFaHEf1labFFZiXHjy-8nacOA13AWl6hDEPz_EQ&oe=6230B686&_nc_sid=83d603
|
||||
|
||||
class Source::URL::Instagram < Source::URL
|
||||
attr_reader :username, :work_id
|
||||
|
||||
def self.match?(url)
|
||||
url.domain.in?(%w[instagram.com])
|
||||
end
|
||||
|
||||
def parse
|
||||
case [domain, *path_segments]
|
||||
|
||||
# https://www.instagram.com/p/CbDW9mVuEnn/
|
||||
# https://www.instagram.com/reel/CV7mHEwgbeF/?utm_medium=copy_link
|
||||
in "instagram.com", ("p" | "reel"), work_id
|
||||
@work_id = work_id
|
||||
|
||||
# https://www.instagram.com/itomugi/
|
||||
in "instagram.com", username, *rest
|
||||
@username = username
|
||||
|
||||
else
|
||||
end
|
||||
end
|
||||
|
||||
def profile_url
|
||||
# Instagram URLs canonically end with "/"
|
||||
"https://www.instagram.com/#{username}/" if username.present?
|
||||
end
|
||||
end
|
||||
@@ -188,6 +188,12 @@ class ArtistURLTest < ActiveSupport::TestCase
|
||||
assert_equal("http://baraag.net/@curator/", url.normalized_url)
|
||||
end
|
||||
|
||||
should "normalize Instagram urls" do
|
||||
url = create(:artist_url, url: "http://instagram.com/itomugi")
|
||||
assert_equal("https://www.instagram.com/itomugi/", url.url)
|
||||
assert_equal("http://www.instagram.com/itomugi/", url.normalized_url)
|
||||
end
|
||||
|
||||
context "#search method" do
|
||||
subject { ArtistURL }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user