Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 3011: import from deviantart #586

Merged
merged 1 commit into from Apr 20, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions app/models/story_parser.rb
Expand Up @@ -618,24 +618,25 @@ def parse_story_from_deviantart(story)
notes = "" notes = ""


body = @doc.css("body") 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 # Find the image (original size) if it's art
image_full = body.css("img#gmi-ResViewSizer_fullimg") image_full = body.css("img#gmi-ResViewSizer_fullimg")
unless image_full[0].nil? unless image_full[0].nil?
storytext = "<center><img src=\"#{image_full[0]["src"]}\"></center>" storytext = "<center><img src=\"#{image_full[0]["src"]}\"></center>"
end end


# Find the fic text if it's fic # 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("table.f td.f div.text")[0] text_table = body.css("#gmi-ResViewContainer table.f td.f div.text")[0]
unless text_table.nil? unless text_table.nil?
# Try to remove the title: # Try to remove some metadata (title and author) from the work's text, if possible
unless text_table.css("h1")[0].nil? && text_table.css("h1")[0].match(title) # 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 text_table.css("h1")[0].remove
end end


# Try to remove the author: # Try to remove the author: if it exists, and if it follows a certain pattern
unless text_table.css("small")[0].nil? && text_table.css("small")[0].match(/by ~.*?<a class="u" href=/m) 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 text_table.css("small")[0].remove
end end
storytext = text_table.inner_html storytext = text_table.inner_html
Expand Down
6 changes: 4 additions & 2 deletions features/support/vcr.rb
Expand Up @@ -26,8 +26,10 @@
t.tags '@work_import_nul_character' 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 '@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' # 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_fic' 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'
t.tags '@import_dw_tables' t.tags '@import_dw_tables'
Expand Down
39 changes: 29 additions & 10 deletions features/work_import_da.feature
Expand Up @@ -3,13 +3,10 @@ Feature: Import Works from deviantart
In order to have an archive full of works In order to have an archive full of works
As an author As an author
I want to create new works by importing them from deviantart I want to create new works by importing them from deviantart
@import_da @import_da_title_link
Scenario: Creating a new art work from an deviantart story with automatic metadata Scenario: Creating a new art work from a deviantart title link with automatic metadata
Given basic tags Given basic tags
And the following activated user exists And I am logged in as "cosomeone"
| login | password |
| cosomeone | something |
And I am logged in as "cosomeone" with password "something"
When I go to the import page When I go to the import page
And I fill in "urls" with "http://bingeling.deviantart.com/art/Flooded-45971613" And I fill in "urls" with "http://bingeling.deviantart.com/art/Flooded-45971613"
When I press "Import" When I press "Import"
Expand All @@ -31,13 +28,35 @@ Feature: Import Works from deviantart
When I am on cosomeone's user page When I am on cosomeone's user page
#' #'
Then I should see "Flooded" 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 @import_da_fic
Scenario: Creating a new fic from an deviantart Scenario: Creating a new fic from an deviantart
Given basic tags Given basic tags
And the following activated user exists And I am logged in as "cosomeone"
| login | password |
| cosomeone | something |
And I am logged in as "cosomeone" with password "something"
When I go to the import page When I go to the import page
And I fill in "urls" with "http://cesy12.deviantart.com/art/AO3-testing-text-196158032" And I fill in "urls" with "http://cesy12.deviantart.com/art/AO3-testing-text-196158032"
When I press "Import" When I press "Import"
Expand Down