sources: add methods for customizing new artist entries.

* Rename `unique_id` to `tag_name`.

* Add `other_names` and `profile_urls` methods that sources can override
  to provide extra names or urls when creating new artist entries.
This commit is contained in:
evazion
2018-12-27 15:03:11 -06:00
parent 2170961f47
commit 1f73e60514
6 changed files with 38 additions and 23 deletions

View File

@@ -101,13 +101,33 @@ module Sources
page_url || image_url
end
# A link to the artist's profile page on the site.
def profile_url
""
# A name to suggest as the artist's tag name when creating a new artist.
# This should usually be the artist's account name.
def tag_name
artist_name
end
# The artists's primary name. If an artist has both a display name and an
# account name, this should be the display name.
def artist_name
""
nil
end
# A list of all names associated with the artist. These names will be suggested
# as other names when creating a new artist.
def other_names
[artist_name, tag_name].compact.uniq
end
# A link to the artist's profile page on the site.
def profile_url
nil
end
# A list of all profile urls associated with the artist. These urls will
# be suggested when creating a new artist.
def profile_urls
[normalize_for_artist_finder]
end
def artist_commentary_title
@@ -157,11 +177,6 @@ module Sources
profile_url.presence || url
end
# A unique identifier for the artist. This is used for artist creation.
def unique_id
artist_name
end
def artists
Artist.find_artists(normalize_for_artist_finder)
end
@@ -170,9 +185,9 @@ module Sources
# exist. Used in Artist.new_with_defaults to prefill the new artist form.
def new_artist
Artist.new(
name: unique_id,
other_names: [artist_name],
url_string: [profile_url, normalize_for_artist_finder].sort.uniq.join("\n")
name: tag_name,
other_names: other_names,
url_string: profile_urls.join("\n")
)
end
@@ -249,9 +264,14 @@ module Sources
def to_h
return {
:artist_name => artist_name,
:artist => {
:name => artist_name,
:tag_name => tag_name,
:other_names => other_names,
:profile_url => profile_url,
:profile_urls => profile_urls,
},
:artists => artists.as_json(include: :sorted_urls),
:profile_url => profile_url,
:image_url => image_url,
:image_urls => image_urls,
:page_url => page_url,
@@ -260,7 +280,6 @@ module Sources
:tags => tags,
:normalized_tags => normalized_tags,
:translated_tags => translated_tags,
:unique_id => unique_id,
:artist_commentary => {
:title => artist_commentary_title,
:description => artist_commentary_desc,

View File

@@ -36,7 +36,7 @@ module Sources
URL_SLUG = %r!/(?:yande\.re%20|Konachan\.com%20-%20)(?<id>\d+).*!i
IMAGE_URL = %r!#{BASE_URL}/(?<type>image|jpeg|sample)/(?<md5>\h{32})#{URL_SLUG}?\.(?<ext>jpg|jpeg|png|gif)\z!i
delegate :artist_name, :profile_url, :unique_id, :artist_commentary_title, :artist_commentary_desc, :dtext_artist_commentary_title, :dtext_artist_commentary_desc, to: :sub_strategy, allow_nil: true
delegate :artist_name, :profile_url, :tag_name, :artist_commentary_title, :artist_commentary_desc, :dtext_artist_commentary_title, :dtext_artist_commentary_desc, to: :sub_strategy, allow_nil: true
def domains
["yande.re", "konachan.com"]

View File

@@ -112,7 +112,7 @@ module Sources
"#{profile_url}/"
end
def unique_id
def tag_name
"nicoseiga#{api_client.user_id}"
end

View File

@@ -123,7 +123,7 @@ module Sources
end
end
def unique_id
def tag_name
"nijie" + artist_id.to_s
end

View File

@@ -24,10 +24,6 @@ module Sources
def normalize_for_artist_finder
url
end
def unique_id
url
end
end
end
end

View File

@@ -149,7 +149,7 @@ module Sources
illust_id.present? || novel_id.present? || fanbox_id.present? || fanbox_account_id.present?
end
def unique_id
def tag_name
moniker
end