sources: factor out Source::URL::DeviantArt and Source::URL::Stash.
This commit is contained in:
@@ -21,6 +21,7 @@ module Source
|
||||
Source::URL::Pixiv,
|
||||
Source::URL::Twitter,
|
||||
Source::URL::ArtStation,
|
||||
Source::URL::DeviantArt,
|
||||
Source::URL::Fanbox,
|
||||
Source::URL::Foundation,
|
||||
Source::URL::HentaiFoundry,
|
||||
@@ -32,6 +33,7 @@ module Source
|
||||
Source::URL::PixivSketch,
|
||||
Source::URL::Plurk,
|
||||
Source::URL::Skeb,
|
||||
Source::URL::Stash,
|
||||
Source::URL::Tumblr,
|
||||
Source::URL::TwitPic,
|
||||
Source::URL::Weibo,
|
||||
|
||||
135
app/logical/source/url/deviant_art.rb
Normal file
135
app/logical/source/url/deviant_art.rb
Normal file
@@ -0,0 +1,135 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Unhandled:
|
||||
#
|
||||
# http://th04.deviantart.net/fs70/300W/f/2009/364/4/d/Alphes_Mimic___Rika_by_Juriesute.png
|
||||
# http://fc02.deviantart.net/fs48/f/2009/186/2/c/Animation_by_epe_tohri.swf
|
||||
# http://fc08.deviantart.net/files/f/2007/120/c/9/Cool_Like_Me_by_47ness.jpg
|
||||
#
|
||||
# http://fc08.deviantart.net/images3/i/2004/088/8/f/Blackrose_for_MuzicFreq.jpg
|
||||
# http://img04.deviantart.net/720b/i/2003/37/9/6/princess_peach.jpg
|
||||
#
|
||||
# http://prnt00.deviantart.net/9b74/b/2016/101/4/468a9d89f52a835d4f6f1c8caca0dfb2-pnjfbh.jpg
|
||||
# http://other00.deviantart.net/8863/o/2009/197/3/7/37ac79eaeef9fb32e6ae998e9a77d8dd.jpg
|
||||
# http://fc09.deviantart.net/fs22/o/2009/197/3/7/37ac79eaeef9fb32e6ae998e9a77d8dd.jpg
|
||||
# http://pre06.deviantart.net/8497/th/pre/f/2009/173/c/c/cc9686111dcffffffb5fcfaf0cf069fb.jpg
|
||||
|
||||
module Source
|
||||
class URL::DeviantArt < Source::URL
|
||||
RESERVED_SUBDOMAINS = %w[www]
|
||||
|
||||
attr_reader :username, :work_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])
|
||||
end
|
||||
|
||||
def parse
|
||||
case [domain, *path_segments]
|
||||
|
||||
# https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/52c4a3ad-d416-42f0-90f6-570983e36797/dczr28f-bd255304-01bf-4765-8cd3-e53983d3f78a.jpg
|
||||
# https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/8b472d70-a0d6-41b5-9a66-c35687090acc/d23jbr4-8a06af02-70cb-46da-8a96-42a6ba73cdb4.jpg/v1/fill/w_786,h_1017,q_70,strp/silverhawks_quicksilver_by_edsfox_d23jbr4-pre.jpg
|
||||
# https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/76098ac8-04ab-4784-b382-88ca082ba9b1/d9x7lmk-595099de-fe8f-48e5-9841-7254f9b2ab8d.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOiIsImlzcyI6InVybjphcHA6Iiwib2JqIjpbW3sicGF0aCI6IlwvZlwvNzYwOThhYzgtMDRhYi00Nzg0LWIzODItODhjYTA4MmJhOWIxXC9kOXg3bG1rLTU5NTA5OWRlLWZlOGYtNDhlNS05ODQxLTcyNTRmOWIyYWI4ZC5wbmcifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6ZmlsZS5kb3dubG9hZCJdfQ.KFOVXAiF8MTlLb3oM-FlD0nnDvODmjqEhFYN5I2X5Bc
|
||||
# https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/fe7ab27f-7530-4252-99ef-2baaf81b36fd/dddf6pe-1a4a091c-768c-4395-9465-5d33899be1eb.png/v1/fill/w_800,h_1130,q_80,strp/stay_hydrated_and_in_the_shade_by_raikoart_dddf6pe-fullview.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9MTEzMCIsInBhdGgiOiJcL2ZcL2ZlN2FiMjdmLTc1MzAtNDI1Mi05OWVmLTJiYWFmODFiMzZmZFwvZGRkZjZwZS0xYTRhMDkxYy03NjhjLTQzOTUtOTQ2NS01ZDMzODk5YmUxZWIucG5nIiwid2lkdGgiOiI8PTgwMCJ9XV0sImF1ZCI6WyJ1cm46c2VydmljZTppbWFnZS5vcGVyYXRpb25zIl19.J0W4k-iV6Mg8Kt_5Lr_L_JbBq4lyr7aCausWWJ_Fsbw
|
||||
in "wixmp.com", *rest
|
||||
parse_filename
|
||||
|
||||
# http://orig12.deviantart.net/9b69/f/2017/023/7/c/illustration___tokyo_encount_oei__by_melisaongmiqin-dawi58s.png
|
||||
# http://pre15.deviantart.net/81de/th/pre/f/2015/063/5/f/inha_by_inhaestudios-d8kfzm5.jpg
|
||||
# http://th00.deviantart.net/fs71/PRE/f/2014/065/3/b/goruto_by_xyelkiltrox-d797tit.png
|
||||
# http://fc00.deviantart.net/fs71/f/2013/234/d/8/d84e05f26f0695b1153e9dab3a962f16-d6j8jl9.jpg
|
||||
# http://th04.deviantart.net/fs71/PRE/f/2013/337/3/5/35081351f62b432f84eaeddeb4693caf-d6wlrqs.jpg
|
||||
in "deviantart.net", *rest
|
||||
parse_filename
|
||||
|
||||
# http://www.deviantart.com/download/135944599/Touhou___Suwako_Moriya_Colored_by_Turtle_Chibi.png
|
||||
# https://www.deviantart.com/download/549677536/countdown_to_midnight_by_kawacy-d939hwg.jpg?token=92090cd3910d52089b566661e8c2f749755ed5f8&ts=1438535525
|
||||
in "deviantart.com", "download", work_id, file
|
||||
parse_filename
|
||||
@work_id = work_id.to_i
|
||||
|
||||
# https://www.deviantart.com/deviation/685436408
|
||||
in "deviantart.com", "deviation", work_id
|
||||
@work_id = work_id.to_i
|
||||
|
||||
# https://www.deviantart.com/noizave/art/test-post-please-ignore-685436408
|
||||
in "deviantart.com", username, "art", /^([a-zA-Z0-9-]+)-(\d+)$/ => title
|
||||
@username = username
|
||||
@title = $1
|
||||
@work_id = $2.to_i
|
||||
|
||||
# https://noizave.deviantart.com/art/test-post-please-ignore-685436408
|
||||
in "deviantart.com", "art", /^([a-z0-9_-]+)-(\d+)$/i => title unless subdomain.in?(RESERVED_SUBDOMAINS)
|
||||
@username = subdomain
|
||||
@title = $1
|
||||
@work_id = $2.to_i
|
||||
|
||||
# https://www.deviantart.com/noizave
|
||||
# https://deviantart.com/noizave
|
||||
in "deviantart.com", username
|
||||
@username = username
|
||||
|
||||
# https://noizave.deviantart.com
|
||||
in ["deviantart.com"] unless subdomain.in?(RESERVED_SUBDOMAINS)
|
||||
@username = subdomain
|
||||
|
||||
# https://fav.me/dbc3a48
|
||||
# https://www.fav.me/dbc3a48
|
||||
in "fav.me", base36_id
|
||||
@work_id = base36_id.delete_prefix("d").to_i(36)
|
||||
|
||||
else
|
||||
end
|
||||
end
|
||||
|
||||
def parse_filename
|
||||
case filename
|
||||
|
||||
# http://orig12.deviantart.net/9b69/f/2017/023/7/c/illustration___tokyo_encount_oei__by_melisaongmiqin-dawi58s.png
|
||||
# http://pre15.deviantart.net/81de/th/pre/f/2015/063/5/f/inha_by_inhaestudios-d8kfzm5.jpg
|
||||
# http://th00.deviantart.net/fs71/PRE/f/2014/065/3/b/goruto_by_xyelkiltrox-d797tit.png
|
||||
# https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/8b472d70-a0d6-41b5-9a66-c35687090acc/d23jbr4-8a06af02-70cb-46da-8a96-42a6ba73cdb4.jpg/v1/fill/w_786,h_1017,q_70,strp/silverhawks_quicksilver_by_edsfox_d23jbr4-pre.jpg
|
||||
# https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/fe7ab27f-7530-4252-99ef-2baaf81b36fd/dddf6pe-1a4a091c-768c-4395-9465-5d33899be1eb.png/v1/fill/w_800,h_1130,q_80,strp/stay_hydrated_and_in_the_shade_by_raikoart_dddf6pe-fullview.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9MTEzMCIsInBhdGgiOiJcL2ZcL2ZlN2FiMjdmLTc1MzAtNDI1Mi05OWVmLTJiYWFmODFiMzZmZFwvZGRkZjZwZS0xYTRhMDkxYy03NjhjLTQzOTUtOTQ2NS01ZDMzODk5YmUxZWIucG5nIiwid2lkdGgiOiI8PTgwMCJ9XV0sImF1ZCI6WyJ1cm46c2VydmljZTppbWFnZS5vcGVyYXRpb25zIl19.J0W4k-iV6Mg8Kt_5Lr_L_JbBq4lyr7aCausWWJ_Fsbw
|
||||
# https://www.deviantart.com/download/549677536/countdown_to_midnight_by_kawacy-d939hwg.jpg?token=92090cd3910d52089b566661e8c2f749755ed5f8&ts=1438535525
|
||||
when /^(.+)_by_(.+)[_-]d([a-z0-9]+)(?:-\w+)?$/i
|
||||
@title = $1
|
||||
@username = $2.dasherize
|
||||
@work_id = $3.to_i(36)
|
||||
|
||||
# http://fc00.deviantart.net/fs71/f/2013/234/d/8/d84e05f26f0695b1153e9dab3a962f16-d6j8jl9.jpg
|
||||
# http://th04.deviantart.net/fs71/PRE/f/2013/337/3/5/35081351f62b432f84eaeddeb4693caf-d6wlrqs.jpg
|
||||
when /^[a-f0-9]{32}-d([a-z0-9]+)$/
|
||||
@work_id = $1.to_i(36)
|
||||
|
||||
# https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/52c4a3ad-d416-42f0-90f6-570983e36797/dczr28f-bd255304-01bf-4765-8cd3-e53983d3f78a.jpg
|
||||
# https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/76098ac8-04ab-4784-b382-88ca082ba9b1/d9x7lmk-595099de-fe8f-48e5-9841-7254f9b2ab8d.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOiIsImlzcyI6InVybjphcHA6Iiwib2JqIjpbW3sicGF0aCI6IlwvZlwvNzYwOThhYzgtMDRhYi00Nzg0LWIzODItODhjYTA4MmJhOWIxXC9kOXg3bG1rLTU5NTA5OWRlLWZlOGYtNDhlNS05ODQxLTcyNTRmOWIyYWI4ZC5wbmcifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6ZmlsZS5kb3dubG9hZCJdfQ.KFOVXAiF8MTlLb3oM-FlD0nnDvODmjqEhFYN5I2X5Bc
|
||||
when /^d([a-z0-9]{6})-\h{8}-\h{4}-\h{4}-\h{4}-\h{12}$/
|
||||
@work_id = $1.to_i(36)
|
||||
|
||||
# http://www.deviantart.com/download/135944599/Touhou___Suwako_Moriya_Colored_by_Turtle_Chibi.png
|
||||
# http://th04.deviantart.net/fs70/300W/f/2009/364/4/d/Alphes_Mimic___Rika_by_Juriesute.png
|
||||
# http://fc02.deviantart.net/fs48/f/2009/186/2/c/Animation_by_epe_tohri.swf
|
||||
# http://fc08.deviantart.net/files/f/2007/120/c/9/Cool_Like_Me_by_47ness.jpg
|
||||
when /^(.+)_by_(.+)$/
|
||||
@title = $1
|
||||
@username = $2.dasherize
|
||||
|
||||
else
|
||||
end
|
||||
end
|
||||
|
||||
def page_url
|
||||
if 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}"
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def pretty_title
|
||||
title.titleize.strip.squeeze(" ").tr(" ", "-") if title.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
36
app/logical/source/url/stash.rb
Normal file
36
app/logical/source/url/stash.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
# 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
|
||||
@@ -1,103 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Asset URLs:
|
||||
#
|
||||
## NORMALIZABLE
|
||||
## * http://orig12.deviantart.net/9b69/f/2017/023/7/c/illustration___tokyo_encount_oei__by_melisaongmiqin-dawi58s.png
|
||||
## * http://pre15.deviantart.net/81de/th/pre/f/2015/063/5/f/inha_by_inhaestudios-d8kfzm5.jpg
|
||||
## * http://th00.deviantart.net/fs71/PRE/f/2014/065/3/b/goruto_by_xyelkiltrox-d797tit.png
|
||||
##
|
||||
## * http://fc00.deviantart.net/fs71/f/2013/234/d/8/d84e05f26f0695b1153e9dab3a962f16-d6j8jl9.jpg
|
||||
## * http://th04.deviantart.net/fs71/PRE/f/2013/337/3/5/35081351f62b432f84eaeddeb4693caf-d6wlrqs.jpg
|
||||
##
|
||||
## * https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/52c4a3ad-d416-42f0-90f6-570983e36797/dczr28f-bd255304-01bf-4765-8cd3-e53983d3f78a.jpg
|
||||
## * https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/8b472d70-a0d6-41b5-9a66-c35687090acc/d23jbr4-8a06af02-70cb-46da-8a96-42a6ba73cdb4.jpg/v1/fill/w_786,h_1017,q_70,strp/silverhawks_quicksilver_by_edsfox_d23jbr4-pre.jpg
|
||||
## * https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/76098ac8-04ab-4784-b382-88ca082ba9b1/d9x7lmk-595099de-fe8f-48e5-9841-7254f9b2ab8d.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOiIsImlzcyI6InVybjphcHA6Iiwib2JqIjpbW3sicGF0aCI6IlwvZlwvNzYwOThhYzgtMDRhYi00Nzg0LWIzODItODhjYTA4MmJhOWIxXC9kOXg3bG1rLTU5NTA5OWRlLWZlOGYtNDhlNS05ODQxLTcyNTRmOWIyYWI4ZC5wbmcifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6ZmlsZS5kb3dubG9hZCJdfQ.KFOVXAiF8MTlLb3oM-FlD0nnDvODmjqEhFYN5I2X5Bc
|
||||
## * https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/fe7ab27f-7530-4252-99ef-2baaf81b36fd/dddf6pe-1a4a091c-768c-4395-9465-5d33899be1eb.png/v1/fill/w_800,h_1130,q_80,strp/stay_hydrated_and_in_the_shade_by_raikoart_dddf6pe-fullview.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9MTEzMCIsInBhdGgiOiJcL2ZcL2ZlN2FiMjdmLTc1MzAtNDI1Mi05OWVmLTJiYWFmODFiMzZmZFwvZGRkZjZwZS0xYTRhMDkxYy03NjhjLTQzOTUtOTQ2NS01ZDMzODk5YmUxZWIucG5nIiwid2lkdGgiOiI8PTgwMCJ9XV0sImF1ZCI6WyJ1cm46c2VydmljZTppbWFnZS5vcGVyYXRpb25zIl19.J0W4k-iV6Mg8Kt_5Lr_L_JbBq4lyr7aCausWWJ_Fsbw
|
||||
#
|
||||
## * http://www.deviantart.com/download/135944599/Touhou___Suwako_Moriya_Colored_by_Turtle_Chibi.png
|
||||
## * https://www.deviantart.com/download/549677536/countdown_to_midnight_by_kawacy-d939hwg.jpg?token=92090cd3910d52089b566661e8c2f749755ed5f8&ts=1438535525
|
||||
#
|
||||
## NOT NORMALIZABLE
|
||||
## * http://th04.deviantart.net/fs70/300W/f/2009/364/4/d/Alphes_Mimic___Rika_by_Juriesute.png
|
||||
## * http://fc02.deviantart.net/fs48/f/2009/186/2/c/Animation_by_epe_tohri.swf
|
||||
## * http://fc08.deviantart.net/files/f/2007/120/c/9/Cool_Like_Me_by_47ness.jpg
|
||||
##
|
||||
## * http://fc08.deviantart.net/images3/i/2004/088/8/f/Blackrose_for_MuzicFreq.jpg
|
||||
## * http://img04.deviantart.net/720b/i/2003/37/9/6/princess_peach.jpg
|
||||
##
|
||||
## * http://prnt00.deviantart.net/9b74/b/2016/101/4/468a9d89f52a835d4f6f1c8caca0dfb2-pnjfbh.jpg
|
||||
## * http://other00.deviantart.net/8863/o/2009/197/3/7/37ac79eaeef9fb32e6ae998e9a77d8dd.jpg
|
||||
## * http://fc09.deviantart.net/fs22/o/2009/197/3/7/37ac79eaeef9fb32e6ae998e9a77d8dd.jpg
|
||||
## * http://pre06.deviantart.net/8497/th/pre/f/2009/173/c/c/cc9686111dcffffffb5fcfaf0cf069fb.jpg
|
||||
#
|
||||
########################
|
||||
#
|
||||
# Page URLs:
|
||||
#
|
||||
# * https://www.deviantart.com/noizave/art/test-post-please-ignore-685436408
|
||||
# * https://noizave.deviantart.com/art/test-post-please-ignore-685436408
|
||||
# * https://www.deviantart.com/deviation/685436408
|
||||
# * https://fav.me/dbc3a48
|
||||
#
|
||||
# Profile URLs:
|
||||
#
|
||||
# * https://noizave.deviantart.com
|
||||
# * https://www.deviantart.com/noizave
|
||||
# * https://deviantart.com/noizave
|
||||
|
||||
module Sources
|
||||
module Strategies
|
||||
class DeviantArt < Base
|
||||
ASSET_SUBDOMAINS = /(?:fc|th|pre|img|orig|origin-orig)\d*/i
|
||||
RESERVED_SUBDOMAINS = %r{\Ahttps?://(?:#{ASSET_SUBDOMAINS}|www)\.}i
|
||||
MAIN_DOMAIN = %r{\Ahttps?://(?:www\.)?deviantart.com}i
|
||||
|
||||
TITLE = /(?<title>[a-z0-9_-]+?)/i
|
||||
ARTIST = /(?<artist>[a-z0-9_-]+?)/i
|
||||
DEVIATION_ID = /(?<deviation_id>[0-9]+)/i
|
||||
|
||||
DA_FILENAME_1 = /[a-f0-9]{32}-d(?<base36_deviation_id>[a-z0-9]+)\./i
|
||||
DA_FILENAME_2 = /#{TITLE}(?:_by_#{ARTIST}(?:-d(?<base36_deviation_id>[a-z0-9]+))?)?\./i
|
||||
DA_FILENAME = Regexp.union(DA_FILENAME_1, DA_FILENAME_2)
|
||||
WIX_FILENAME = %r{d(?<base36_deviation_id>[a-z0-9]+)[0-9a-f-]+\.\w+(?:/\w+/\w+/[\w,]+/(?<title>[\w-]+)_by_(?<artist>[\w-]+)_d\w+-\w+\.\w+)?.+}i
|
||||
|
||||
NOT_NORMALIZABLE_ASSET = %r{\Ahttps?://#{ASSET_SUBDOMAINS}\.deviantart\.net/.+/[0-9a-f]{32}(?:-[^d]\w+)?\.}i
|
||||
|
||||
DA_ASSET = %r{\Ahttps?://#{ASSET_SUBDOMAINS}\.deviantart\.net/.+/#{DA_FILENAME}}i
|
||||
WIX_ASSET = %r{\Ahttps?://images-wixmp-ed30a86b8c4ca887773594c2\.wixmp\.com/(?:intermediary/)?\w/[0-9a-f-]+/#{WIX_FILENAME}}i
|
||||
ASSET = Regexp.union(DA_ASSET, WIX_ASSET)
|
||||
|
||||
DA_DOWNLOAD = %r{#{MAIN_DOMAIN}/download/#{DEVIATION_ID}/#{DA_FILENAME_2}?}i
|
||||
|
||||
DEVIATION_ART = %r{#{MAIN_DOMAIN}/deviation/#{DEVIATION_ID}\z}i
|
||||
PATH_ART = %r{#{MAIN_DOMAIN}/#{ARTIST}/art/#{TITLE}-#{DEVIATION_ID}\z}i
|
||||
SUBDOMAIN_ART = %r{\Ahttps?://#{ARTIST}\.deviantart\.com/art/#{TITLE}-#{DEVIATION_ID}\z}i
|
||||
|
||||
PATH_PROFILE = %r{#{MAIN_DOMAIN}/#{ARTIST}/?\z}i
|
||||
SUBDOMAIN_PROFILE = %r{\Ahttps?://#{ARTIST}\.deviantart\.com/?\z}i
|
||||
|
||||
FAVME = %r{\Ahttps?://(?:www\.)?fav\.me/d(?<base36_deviation_id>[a-z0-9]+)\z}i
|
||||
|
||||
def self.enabled?
|
||||
Danbooru.config.deviantart_client_id.present? && Danbooru.config.deviantart_client_secret.present?
|
||||
end
|
||||
|
||||
def domains
|
||||
["deviantart.net", "deviantart.com", "fav.me"]
|
||||
end
|
||||
|
||||
def wixmp_hosts
|
||||
%w[images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com wixmp-ed30a86b8c4ca887773594c2.wixmp.com api-da.wixmp.com]
|
||||
def match?
|
||||
Source::URL::DeviantArt === parsed_url
|
||||
end
|
||||
|
||||
def site_name
|
||||
"Deviant Art"
|
||||
end
|
||||
|
||||
def match?
|
||||
return false if parsed_url.nil?
|
||||
parsed_url.domain.in?(domains) || parsed_url.host.in?(wixmp_hosts)
|
||||
parsed_url.site_name
|
||||
end
|
||||
|
||||
def image_urls
|
||||
@@ -137,15 +52,7 @@ module Sources
|
||||
end
|
||||
|
||||
def page_url_from_image_url
|
||||
artist, title, id = artist_name_from_url, title_from_url, deviation_id
|
||||
|
||||
if artist.present? && title.present? && id.present?
|
||||
"https://www.deviantart.com/#{artist}/art/#{title}-#{id}"
|
||||
elsif id.present?
|
||||
"https://www.deviantart.com/deviation/#{id}"
|
||||
else
|
||||
nil
|
||||
end
|
||||
parsed_url.page_url || parsed_referer&.page_url
|
||||
end
|
||||
|
||||
def normalize_for_source
|
||||
@@ -217,52 +124,12 @@ module Sources
|
||||
end.gsub(/\A[[:space:]]+|[[:space:]]+\z/, "")
|
||||
end
|
||||
|
||||
def self.deviation_id_from_url(url)
|
||||
if url =~ NOT_NORMALIZABLE_ASSET
|
||||
nil
|
||||
elsif url =~ ASSET || url =~ FAVME
|
||||
$~[:base36_deviation_id].try(:to_i, 36)
|
||||
elsif url =~ PATH_ART || (url !~ RESERVED_SUBDOMAINS && url =~ SUBDOMAIN_ART) || url =~ DA_DOWNLOAD || url =~ DEVIATION_ART
|
||||
$~[:deviation_id].to_i
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def self.artist_name_from_url(url)
|
||||
if url =~ NOT_NORMALIZABLE_ASSET
|
||||
nil
|
||||
elsif url =~ ASSET || url =~ PATH_ART || url =~ PATH_PROFILE || url =~ DA_DOWNLOAD
|
||||
$~[:artist].try(:dasherize)
|
||||
elsif url !~ RESERVED_SUBDOMAINS && (url =~ SUBDOMAIN_ART || url =~ SUBDOMAIN_PROFILE)
|
||||
$~[:artist]
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def self.title_from_url(url)
|
||||
if url =~ NOT_NORMALIZABLE_ASSET
|
||||
nil
|
||||
elsif url =~ ASSET || url =~ PATH_ART || url =~ DA_DOWNLOAD
|
||||
$~[:title].to_s.titleize.strip.squeeze(" ").tr(" ", "-").presence
|
||||
elsif url !~ RESERVED_SUBDOMAINS && url =~ SUBDOMAIN_ART
|
||||
$~[:title].to_s.titleize.strip.squeeze(" ").tr(" ", "-").presence
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def deviation_id
|
||||
self.class.deviation_id_from_url(url) || self.class.deviation_id_from_url(referer_url)
|
||||
parsed_url.work_id || parsed_referer&.work_id
|
||||
end
|
||||
|
||||
def artist_name_from_url
|
||||
self.class.artist_name_from_url(url) || self.class.artist_name_from_url(referer_url)
|
||||
end
|
||||
|
||||
def title_from_url
|
||||
self.class.title_from_url(url) || self.class.title_from_url(referer_url)
|
||||
parsed_url.username || parsed_referer&.username
|
||||
end
|
||||
|
||||
def page
|
||||
|
||||
@@ -15,14 +15,8 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class Stash < DeviantArt
|
||||
STASH = %r{\Ahttps?://sta\.sh/(?<post_id>[0-9a-zA-Z]+)}i
|
||||
|
||||
def domains
|
||||
["deviantart.net", "sta.sh"]
|
||||
end
|
||||
|
||||
def match?
|
||||
parsed_urls.map(&:domain).any?("sta.sh")
|
||||
Source::URL::Stash === parsed_url || Source::URL::Stash === parsed_referer
|
||||
end
|
||||
|
||||
def site_name
|
||||
@@ -38,20 +32,12 @@ module Sources
|
||||
end
|
||||
|
||||
def page_url_from_image_url
|
||||
"https://sta.sh/#{stash_id}"
|
||||
end
|
||||
|
||||
def self.stash_id_from_url(url)
|
||||
if url =~ STASH
|
||||
$~[:post_id].downcase
|
||||
else
|
||||
nil
|
||||
if Source::URL::Stash === parsed_url
|
||||
parsed_url.page_url
|
||||
elsif Source::URL::Stash === parsed_referer
|
||||
parsed_referer.page_url
|
||||
end
|
||||
end
|
||||
|
||||
def stash_id
|
||||
[url, referer_url].map { |x| self.class.stash_id_from_url(x) }.compact.first
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user