Skip to content

Commit

Permalink
Merge pull request #120 from Deer-Spangle/submission_detect_gallery
Browse files Browse the repository at this point in the history
Adding "gallery" key to submissions endpoint
  • Loading branch information
Deer-Spangle authored Mar 2, 2024
2 parents b358690 + d77ba9e commit fe74d59
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/faexport/scraper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,7 @@ def parse_submission_page(id, html, is_login)
else
og_thumb["content"].sub "http:", "https:"
end
gallery = html.at_css(".minigallery-title a")["href"].split("/")[1]

submission = {
title: submission_title.at_css("h2").content,
Expand All @@ -1590,6 +1591,7 @@ def parse_submission_page(id, html, is_login)
download: download_url,
full: img ? "https:#{img["data-fullview-src"]}" : nil,
thumbnail: thumb_img,
gallery: gallery,
category: field(info, "Category"),
theme: field(info, "Theme"),
species: field(info, "Species"),
Expand Down
1 change: 1 addition & 0 deletions lib/faexport/views/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ If you supply a login cookie, you will get two additional keys in the results: `
"download": "http://d.furaffinity.net/art/fender/1284661300/1284661300.fender_fender.png",
"full": "http://d.furaffinity.net/art/fender/1284661300/1284661300.fender_fender.png",
"thumbnail": "http://t.furaffinity.net/4483888@400-1284661300.jpg",
"gallery": "gallery",
"category": "Artwork (Digital)",
"theme": "Doodle",
"species": "Unspecified / Any",
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/fa_parsing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@
expect(sub[:link]).to be_valid_link_for_sub_id(sub_id)
expect(sub[:posted]).to be_valid_date_and_match_iso(sub[:posted_at])
expect(sub[:download]).to match(%r{https://d.furaffinity.net/art/[^/]+/[0-9]+/[0-9]+\..+\.png})
expect(sub[:gallery]).to eql("gallery")
# For an image submission, full == download
expect(sub[:full]).to eql(sub[:download])
expect(sub[:thumbnail]).to be_valid_thumbnail_link_for_sub_id(sub_id)
Expand Down Expand Up @@ -516,6 +517,7 @@
expect(sub[:link]).to be_valid_link_for_sub_id(sub_id)
expect(sub[:posted]).to be_valid_date_and_match_iso(sub[:posted_at])
expect(sub[:download]).to match(%r{https://d.furaffinity.net/download/art/[^/]+/stories/[0-9]+/[0-9]+\..+\.(rtf|doc|txt|docx|pdf)})
expect(sub[:gallery]).to eql("gallery")
# For a story submission, full != download
expect(sub[:full]).not_to be_blank
expect(sub[:full]).not_to eql(sub[:download])
Expand Down Expand Up @@ -548,6 +550,7 @@
expect(sub[:link]).to be_valid_link_for_sub_id(sub_id)
expect(sub[:posted]).to be_valid_date_and_match_iso(sub[:posted_at])
expect(sub[:download]).to match(%r{https://d.furaffinity.net/download/art/[^/]+/music/[0-9]+/[0-9]+\..+\.(mp3|mid|wav|mpeg)})
expect(sub[:gallery]).to eql("gallery")
# For a music submission, full != download
expect(sub[:full]).not_to be_blank
expect(sub[:full]).not_to eql(sub[:download])
Expand Down Expand Up @@ -580,6 +583,7 @@
expect(sub[:link]).to be_valid_link_for_sub_id(sub_id)
expect(sub[:posted]).to be_valid_date_and_match_iso(sub[:posted_at])
expect(sub[:download]).to match(%r{https://d.furaffinity.net/download/art/[^/]+/[0-9]+/[0-9]+\..+\.swf})
expect(sub[:gallery]).to eql("gallery")
# For a flash submission, full is nil
expect(sub[:full]).to be_nil
expect(sub[:thumbnail]).to be_valid_thumbnail_link_for_sub_id(sub_id)
Expand Down Expand Up @@ -611,6 +615,7 @@
expect(sub[:link]).to be_valid_link_for_sub_id(sub_id)
expect(sub[:posted]).to be_valid_date_and_match_iso(sub[:posted_at])
expect(sub[:download]).to match(%r{https://d.furaffinity.net/download/art/[^/]+/poetry/[0-9]+/[0-9]+\..+\.(rtf|doc|txt|docx|pdf)})
expect(sub[:gallery]).to eql("gallery")
# For a poetry submission, full is nil
expect(sub[:full]).not_to be_nil
expect(sub[:thumbnail]).to be_valid_thumbnail_link_for_sub_id(sub_id)
Expand Down Expand Up @@ -644,6 +649,7 @@
expect(sub[:link]).to be_valid_link_for_sub_id(sub_id)
expect(sub[:posted]).to be_valid_date_and_match_iso(sub[:posted_at])
expect(sub[:download]).to match(%r{https://d.furaffinity.net/art/[^/]+/[0-9]+/[0-9]+\..+\.png})
expect(sub[:gallery]).to eql("gallery")
# For an image submission, full == download
expect(sub[:full]).to eql(sub[:download])
expect(sub[:thumbnail]).to be_valid_thumbnail_link_for_sub_id(sub_id)
Expand All @@ -664,6 +670,15 @@
expect(sub[:keywords]).to be_empty
end

it "detects when a submission is in scraps" do
sub = @fa.submission("32006460")
expect(sub[:title]).not_to be_blank
expect(sub[:description]).not_to be_blank
expect(sub[:description_body]).to eql(sub[:description])
expect(sub).to have_valid_profile_link
expect(sub[:gallery]).to eql("scraps")
end

it "hides nsfw submission if sfw is set" do
@fa.safe_for_work = true
expect { @fa.submission("32011278") }.to raise_error(FAContentFilterError)
Expand Down Expand Up @@ -734,6 +749,7 @@
expect(sub[:link]).to be_valid_link_for_sub_id(sub_id)
expect(sub[:posted]).to be_valid_date_and_match_iso(sub[:posted_at])
expect(sub[:download]).to match(%r{https://d.furaffinity.net/art/[^/]+/[0-9]+/[0-9]+\..+\.png})
expect(sub[:gallery]).to eql("gallery")
# For an image submission, full is equal to download
expect(sub[:full]).to eql(sub[:download])
expect(sub[:thumbnail]).to be_valid_thumbnail_link_for_sub_id(sub_id)
Expand Down

0 comments on commit fe74d59

Please sign in to comment.