sources: merge Sta.sh strategy into DeviantArt strategy.

This turns out to be a little simpler than keeping them separate. The
only thing special we have to do for Sta.sh is use the Sta.sh page when
we have a DeviantArt image with a Sta.sh referer.
This commit is contained in:
evazion
2022-03-12 00:40:52 -06:00
parent f2028c14fb
commit 787b5c8e27
6 changed files with 33 additions and 86 deletions

View File

@@ -39,7 +39,6 @@ module Source
Source::URL::PixivSketch,
Source::URL::Plurk,
Source::URL::Skeb,
Source::URL::Stash,
Source::URL::Tumblr,
Source::URL::TwitPic,
Source::URL::Weibo,

View File

@@ -18,10 +18,10 @@ module Source
class URL::DeviantArt < Source::URL
RESERVED_SUBDOMAINS = %w[www]
attr_reader :username, :work_id, :title
attr_reader :username, :work_id, :stash_id, :title
def self.match?(url)
url.domain.in?(%w[deviantart.net deviantart.com fav.me]) || url.host.in?(%w[images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com wixmp-ed30a86b8c4ca887773594c2.wixmp.com api-da.wixmp.com])
url.domain.in?(%w[deviantart.net deviantart.com fav.me sta.sh]) || url.host.in?(%w[images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com wixmp-ed30a86b8c4ca887773594c2.wixmp.com api-da.wixmp.com])
end
def parse
@@ -78,6 +78,18 @@ module Source
in "fav.me", base36_id
@work_id = base36_id.delete_prefix("d").to_i(36)
# https://sta.sh/21leo8mz87ue (folder)
# https://sta.sh/2uk0v5wabdt (subfolder)
# https://sta.sh/0wxs31o7nn2 (single image)
# Ref: https://www.deviantartsupport.com/en/article/what-is-stash-3391708
# Ref: https://www.deviantart.com/developers/http/v1/20160316/stash_item/4662dd8b10e336486ea9a0b14da62b74
in "sta.sh", stash_id
@stash_id = stash_id
# https://sta.sh/zip/21leo8mz87ue
in "sta.sh", "zip", stash_id
@stash_id = stash_id
else
end
end
@@ -119,7 +131,9 @@ module Source
end
def page_url
if username.present? && pretty_title.present? && work_id.present?
if stash_id.present?
"https://sta.sh/#{stash_id}"
elsif username.present? && pretty_title.present? && work_id.present?
"https://www.deviantart.com/#{username}/art/#{pretty_title}-#{work_id}"
elsif work_id.present?
"https://www.deviantart.com/deviation/#{work_id}"

View File

@@ -1,36 +0,0 @@
# frozen_string_literal: true
module Source
class URL::Stash < Source::URL
attr_reader :work_id, :username
def self.match?(url)
url.domain == "sta.sh"
end
def site_name
"Sta.sh"
end
def parse
case [domain, *path_segments]
# https://sta.sh/21leo8mz87ue (folder)
# https://sta.sh/2uk0v5wabdt (subfolder)
# https://sta.sh/0wxs31o7nn2 (single image)
in "sta.sh", work_id
@work_id = work_id
# https://sta.sh/zip/21leo8mz87ue
in "sta.sh", "zip", work_id
@work_id = work_id
else
end
end
def page_url
"https://sta.sh/#{work_id}"
end
end
end

View File

@@ -8,7 +8,6 @@ module Sources
Strategies::Twitter,
Strategies::Tumblr,
Strategies::NicoSeiga,
Strategies::Stash, # must come before DeviantArt
Strategies::DeviantArt,
Strategies::Moebooru,
Strategies::Nijie,

View File

@@ -38,7 +38,9 @@ module Sources
end
def page_url
if api_deviation.present?
if stash_page.present?
stash_page
elsif api_deviation.present?
api_deviation[:url]
elsif deviation_id.present?
page_url_from_image_url
@@ -48,7 +50,19 @@ module Sources
end
def page_url_from_image_url
parsed_url.page_url || parsed_referer&.page_url
stash_page || parsed_url.page_url || parsed_referer&.page_url
end
# Sta.sh posts have the same image URLs as DeviantArt but different page URLs. We use the Sta.sh page if we have one.
#
# Image: https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/83d3eb4d-13e5-4aea-a08f-8d4331d033c4/dcmjs1s-389a7505-142d-4b34-a790-ab4ea1ec9eaa.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiJcL2ZcLzgzZDNlYjRkLTEzZTUtNGFlYS1hMDhmLThkNDMzMWQwMzNjNFwvZGNtanMxcy0zODlhNzUwNS0xNDJkLTRiMzQtYTc5MC1hYjRlYTFlYzllYWEucG5nIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.pIddc32BoLpAJt6D8YcRFonoVy9nC8RgROlYwMp3huo
# Page: https://sta.sh/01pwva4zzf98
def stash_page
if parsed_url.stash_id.present?
parsed_url.page_url
elsif parsed_referer&.stash_id.present?
parsed_referer.page_url
end
end
def normalize_for_source

View File

@@ -1,43 +0,0 @@
# frozen_string_literal: true
# Page URLs:
# * https://sta.sh/0wxs31o7nn2 (single image)
# * https://sta.sh/21leo8mz87ue (folder)
#
# Image URLs:
# * https://orig00.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png
#
# Ref:
# * https://github.com/danbooru/danbooru/issues/3877
# * https://www.deviantartsupport.com/en/article/what-is-stash-3391708
# * https://www.deviantart.com/developers/http/v1/20160316/stash_item/4662dd8b10e336486ea9a0b14da62b74
#
module Sources
module Strategies
class Stash < DeviantArt
def match?
Source::URL::Stash === parsed_url || Source::URL::Stash === parsed_referer
end
def site_name
"Sta.sh"
end
def canonical_url
page_url
end
def page_url
page_url_from_image_url
end
def page_url_from_image_url
if Source::URL::Stash === parsed_url
parsed_url.page_url
elsif Source::URL::Stash === parsed_referer
parsed_referer.page_url
end
end
end
end
end