artists: normalize fc2.com profile urls.
This commit is contained in:
@@ -28,6 +28,7 @@ module Source
|
||||
Source::URL::DeviantArt,
|
||||
Source::URL::Fanbox,
|
||||
Source::URL::Fantia,
|
||||
Source::URL::Fc2,
|
||||
Source::URL::Foundation,
|
||||
Source::URL::HentaiFoundry,
|
||||
Source::URL::Lofter,
|
||||
|
||||
42
app/logical/source/url/fc2.rb
Normal file
42
app/logical/source/url/fc2.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Source::URL::Fc2 < Source::URL
|
||||
attr_reader :username, :profile_url
|
||||
|
||||
def self.match?(url)
|
||||
url.domain.in?(%w[fc2.com fc2blog.net fc2blog.us])
|
||||
end
|
||||
|
||||
def site_name
|
||||
"FC2"
|
||||
end
|
||||
|
||||
def parse
|
||||
case [*host.split("."), *path_segments]
|
||||
|
||||
# http://silencexs.blog.fc2.com
|
||||
# http://silencexs.blog106.fc2.com
|
||||
in username, /blog\d*/, "fc2", "com", *rest
|
||||
@username = username
|
||||
@profile_url = "http://#{username}.blog.fc2.com"
|
||||
|
||||
# http://794ancientkyoto.web.fc2.com
|
||||
# http://yorokobi.x.fc2.com
|
||||
# https://lilish28.bbs.fc2.com
|
||||
# http://jpmaid.h.fc2.com
|
||||
# http://toritokaizoku.web.fc2.com/tori.html (404: http://toritokaizoku.web.fc2.com)
|
||||
in username, ("bbs" | "web" | "h" | "x") => subsite, "fc2", "com", *rest
|
||||
@username = username
|
||||
@subsite = subsite
|
||||
@profile_url = ["http://#{username}.#{subsite}.fc2.com", *rest].join("/")
|
||||
|
||||
# http://swordsouls.blog131.fc2blog.net
|
||||
# http://swordsouls.blog131.fc2blog.us
|
||||
in username, /blog\d*/, "fc2blog", ("net" | "us") => tld, *rest
|
||||
@username = username
|
||||
@profile_url = "http://#{username}.blog.fc2blog.#{tld}"
|
||||
|
||||
else
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -23,10 +23,6 @@ class ArtistURL < ApplicationRecord
|
||||
|
||||
url = Source::URL.parse(url)&.profile_url || url
|
||||
url = url.sub(%r{^https://}, "http://")
|
||||
url = url.sub(%r{^http://blog-imgs-\d+\.fc2}, "http://blog.fc2")
|
||||
url = url.sub(%r{^http://blog-imgs-\d+-\w+\.fc2}, "http://blog.fc2")
|
||||
url = url.sub(%r{^http://blog\d*\.fc2\.com/(?:\w/){,3}(\w+)}, "http://\\1.blog.fc2.com")
|
||||
|
||||
url = url.gsub(%r{/+\Z}, "")
|
||||
url + "/"
|
||||
end
|
||||
|
||||
@@ -71,13 +71,8 @@ class ArtistURLTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "normalize fc2 urls" do
|
||||
url = create(:artist_url, url: "http://blog55.fc2.com/monet")
|
||||
assert_equal("http://blog55.fc2.com/monet", url.url)
|
||||
assert_equal("http://monet.blog.fc2.com/", url.normalized_url)
|
||||
|
||||
url = create(:artist_url, url: "http://blog-imgs-55.fc2.com/monet")
|
||||
assert_equal("http://blog-imgs-55.fc2.com/monet", url.url)
|
||||
assert_equal("http://monet.blog.fc2.com/", url.normalized_url)
|
||||
url = create(:artist_url, url: "http://silencexs.blog106.fc2.com/")
|
||||
assert_equal("http://silencexs.blog.fc2.com/", url.normalized_url)
|
||||
end
|
||||
|
||||
should "normalize deviant art artist urls" do
|
||||
|
||||
Reference in New Issue
Block a user