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:
@@ -8,7 +8,6 @@ module Sources
|
||||
Strategies::Twitter,
|
||||
Strategies::Tumblr,
|
||||
Strategies::NicoSeiga,
|
||||
Strategies::Stash, # must come before DeviantArt
|
||||
Strategies::DeviantArt,
|
||||
Strategies::Moebooru,
|
||||
Strategies::Nijie,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user