From 04e6aa74745d27b6b9252350b3344bec8fe52f0c Mon Sep 17 00:00:00 2001 From: Toks Date: Fri, 13 Mar 2015 14:12:17 -0400 Subject: [PATCH] #1866 update for new deviantart urls --- .../downloads/rewrite_strategies/deviant_art.rb | 8 ++++++-- app/logical/sources/strategies/deviant_art.rb | 10 +++++----- app/models/post.rb | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/logical/downloads/rewrite_strategies/deviant_art.rb b/app/logical/downloads/rewrite_strategies/deviant_art.rb index e8d7ae24f..cac22b692 100644 --- a/app/logical/downloads/rewrite_strategies/deviant_art.rb +++ b/app/logical/downloads/rewrite_strategies/deviant_art.rb @@ -22,12 +22,16 @@ module Downloads end def rewrite_thumbnails(url, headers) - if url =~ %r{^(https?://.+?\.deviantart\.net/.+?/)200H/} + if url =~ %r{^(https?://(?:fc|th)\d{2}\.deviantart\.net/.+?/)200H/} match = $1 url.sub!(match + "200H/", match) - elsif url =~ %r{^(https?://.+?\.deviantart\.net/.+?/)PRE/} + elsif url =~ %r{^(https?://(?:fc|th)\d{2}\.deviantart\.net/.+?/)PRE/} match = $1 url.sub!(match + "PRE/", match) + elsif url =~ %r{^https?://(?:pre|img)\d{2}\.deviantart\.net/} + source = ::Sources::Strategies::DeviantArt.new(url) + source.get + return [source.image_url, headers] end return [url, headers] diff --git a/app/logical/sources/strategies/deviant_art.rb b/app/logical/sources/strategies/deviant_art.rb index af2297898..e5232b0e5 100644 --- a/app/logical/sources/strategies/deviant_art.rb +++ b/app/logical/sources/strategies/deviant_art.rb @@ -47,10 +47,10 @@ module Sources end def get_image_url_from_page(page) - image = page.search("div.dev-view-deviation img.dev-content-normal") + download_link = page.link_with(:class => /dev-page-download/) - if image.any? - image[0]["src"] + if download_link + download_link.click.uri.to_s # need to follow the redirect now to get the full size url, following it later seems to not work. else nil end @@ -58,9 +58,9 @@ module Sources def normalized_url @normalized_url ||= begin - if url =~ %r{\Ahttps?://(?:fc|th)\d{2}\.deviantart\.net/.+/[a-z0-9_]*_by_[a-z0-9_]+-d([a-z0-9]+)\.}i + 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 "http://fav.me/d#{$1}" - elsif url =~ %r{\Ahttps?://(?:fc|th)\d{2}\.deviantart\.net/.+/[a-f0-9]+-d([a-z0-9]+)\.}i + elsif url =~ %r{\Ahttps?://(?:fc|th|pre|orig|img)\d{2}\.deviantart\.net/.+/[a-f0-9]+-d([a-z0-9]+)\.}i "http://fav.me/d#{$1}" elsif url =~ %r{deviantart\.com/art/} url diff --git a/app/models/post.rb b/app/models/post.rb index 770c36d6d..d76a496bb 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -324,10 +324,10 @@ class Post < ActiveRecord::Base base_36_id = base_10_id.to_s(36) "http://twitpic.com/#{base_36_id}" - when %r{\Ahttps?://(?:fc|th)\d{2}\.deviantart\.net/.+/[a-z0-9_]*_by_([a-z0-9_]+)-d([a-z0-9]+)\.}i + when %r{\Ahttps?://(?:fc|th|pre|orig|img)\d{2}\.deviantart\.net/.+/[a-z0-9_]*_by_([a-z0-9_]+)-d([a-z0-9]+)\.}i "http://#{$1}.deviantart.com/gallery/#/d#{$2}" - when %r{\Ahttps?://(?:fc|th)\d{2}\.deviantart\.net/.+/[a-f0-9]+-d([a-z0-9]+)\.}i + when %r{\Ahttps?://(?:fc|th|pre|orig|img)\d{2}\.deviantart\.net/.+/[a-f0-9]+-d([a-z0-9]+)\.}i "http://deviantart.com/gallery/#/d#{$1}" when %r{\Ahttp://www\.karabako\.net/images(?:ub)?/karabako_(\d+)(?:_\d+)?\.}i