Issue 3011: import from deviantart #586

Merged
merged 1 commit into from Apr 20, 2012
Jump to file or symbol
Failed to load files and symbols.
+41 −19
Split
View
@@ -618,24 +618,25 @@ def parse_story_from_deviantart(story)
notes = ""
body = @doc.css("body")
- title = @doc.css("title").inner_html.gsub /on DeviantART$/, ""
+ title = @doc.css("title").inner_html.gsub /\s*on deviantart$/i, ""
# Find the image (original size) if it's art
image_full = body.css("img#gmi-ResViewSizer_fullimg")
unless image_full[0].nil?
storytext = "<center><img src=\"#{image_full[0]["src"]}\"></center>"
end
- # Find the fic text if it's fic
- text_table = body.css("table.f td.f div.text")[0]
+ # Find the fic text if it's fic (needs the id for disambiguation, the "deviantART loves you" bit in the footer has the same class path)
+ text_table = body.css("#gmi-ResViewContainer table.f td.f div.text")[0]
unless text_table.nil?
- # Try to remove the title:
- unless text_table.css("h1")[0].nil? && text_table.css("h1")[0].match(title)
+ # Try to remove some metadata (title and author) from the work's text, if possible
+ # Try to remove the title: if it exists, and if it's the same as the browser title
+ if text_table.css("h1")[0].present? && title && title.match(text_table.css("h1")[0].text)
text_table.css("h1")[0].remove
end
- # Try to remove the author:
- unless text_table.css("small")[0].nil? && text_table.css("small")[0].match(/by ~.*?<a class="u" href=/m)
+ # Try to remove the author: if it exists, and if it follows a certain pattern
+ if text_table.css("small")[0].present? && text_table.css("small")[0].inner_html.match(/by ~.*?<a class="u" href=/m)
text_table.css("small")[0].remove
end
storytext = text_table.inner_html
View
@@ -26,8 +26,10 @@
t.tags '@work_import_nul_character'
t.tags '@work_import_errors', :record => :all # need to run this every time bc the url is a bogus one (on purpose, for testing) so it's never properly "recorded"
- t.tags '@import_da'
- t.tags '@import_da_fic'
+ # need to run this every time for the devart features, because the recorded responses run into an encoding error I don't have time to investigate
+ t.tags '@import_da_title_link', :record => :all
+ # t.tags '@import_da_gallery_link', :record => :all # TODO: uncomment if/when implementing this feature
+ t.tags '@import_da_fic', :record => :all
t.tags '@import_dw'
t.tags '@import_dw_tables'
@@ -3,13 +3,10 @@ Feature: Import Works from deviantart
In order to have an archive full of works
As an author
I want to create new works by importing them from deviantart
- @import_da
- Scenario: Creating a new art work from an deviantart story with automatic metadata
+ @import_da_title_link
+ Scenario: Creating a new art work from a deviantart title link with automatic metadata
Given basic tags
- And the following activated user exists
- | login | password |
- | cosomeone | something |
- And I am logged in as "cosomeone" with password "something"
+ And I am logged in as "cosomeone"
When I go to the import page
And I fill in "urls" with "http://bingeling.deviantart.com/art/Flooded-45971613"
When I press "Import"
@@ -31,13 +28,35 @@ Feature: Import Works from deviantart
When I am on cosomeone's user page
#'
Then I should see "Flooded"
+ # @import_da_gallery_link
+ # Scenario: TODO: Creating a new art work from a deviantart gallery link with automatic metadata
+ # Given basic tags
+ # And I am logged in as "cosomeone"
+ # When I go to the import page
+ # And I fill in "urls" with "http://bingeling.deviantart.com/gallery/#/drdbx9"
+ # When I press "Import"
+ # Then I should see "Preview"
+ # And I should find "Flooded_by_bingeling.jpg" within "img[src]"
+ # And I should see "Digital Art" within "dd.freeform"
+ # And I should see "People" within "dd.freeform"
+ # And I should see "Vector" within "dd.freeform"
+ # And I should see "Published:2007-01-04"
+ # And I should see "Flooded" within "h2.title"
+ # And I should see "done with Photoshop 7" within "div.notes"
+ # And I should see "but they were definitely helpful" within "div.notes"
+ # And I should not see "deviant"
+ # And I should not see "bingeling"
+ # And I should not see "Visit the Artist"
+ # And I should not see "Download Image"
+ # When I press "Post"
+ # Then I should see "Work was successfully posted."
+ # When I am on cosomeone's user page
+ # #'
+ # Then I should see "Flooded"
@import_da_fic
Scenario: Creating a new fic from an deviantart
Given basic tags
- And the following activated user exists
- | login | password |
- | cosomeone | something |
- And I am logged in as "cosomeone" with password "something"
+ And I am logged in as "cosomeone"
When I go to the import page
And I fill in "urls" with "http://cesy12.deviantart.com/art/AO3-testing-text-196158032"
When I press "Import"