Support fetching deviantart tags

This commit is contained in:
Toks
2015-05-25 22:44:55 -04:00
parent e1d10b4258
commit 804cbae85c

View File

@@ -26,7 +26,7 @@ module Sources
agent.get(URI.parse(normalized_url)) do |page|
@artist_name, @profile_url = get_profile_from_page(page)
@image_url = get_image_url_from_page(page)
@tags = []
@tags = get_tags_from_page(page)
end
end
@@ -62,6 +62,14 @@ module Sources
end
end
def get_tags_from_page(page)
links = page.search("a.discoverytag")
links.map do |node|
[node.attr("data-canonical-tag"), node.attr("href")]
end
end
def normalized_url
@normalized_url ||= begin
if url =~ %r{\Ahttps?://(?:fc|th|pre|orig|img)\d{2}\.deviantart\.net/.+/[a-z0-9_]*_by_[a-z0-9_]+-d([a-z0-9]+)\.}i