Files
danbooru/app/logical/source/url/plurk.rb
evazion 9343f7c912 Source::URL: add profile_url method.
Add a method for converting a source URL into a profile URL. This will
be used for normalizing profile URLs in artist entries.

Also add the ability to parse a few more profile URL formats.
2022-03-13 03:54:17 -05:00

46 lines
965 B
Ruby

# frozen_string_literal: true
class Source::URL::Plurk < Source::URL
attr_reader :username, :work_id
def self.match?(url)
url.domain == "plurk.com"
end
def parse
case [domain, *path_segments]
# https://images.plurk.com/5wj6WD0r6y4rLN0DL3sqag.jpg
# https://images.plurk.com/mx_5wj6WD0r6y4rLN0DL3sqag.jpg
in "plurk.com", /^(mx_)?(\w{22})\.(\w+)$/
@image_id = $2
# https://www.plurk.com/p/om6zv4
in "plurk.com", "p", work_id
@work_id = work_id
# https://www.plurk.com/m/p/okxzae
in "plurk.com", "m", "p", work_id
@work_id = work_id
# https://www.plurk.com/redeyehare
in "plurk.com", username
@username = username
# https://www.plurk.com/m/redeyehare
in "plurk.com", "m", username
@username = username
else
end
end
def image_url?
host == "images.plurk.com"
end
def profile_url
"https://www.plurk.com/#{username}" if username.present?
end
end