Refactor sources
This commit is contained in:
@@ -68,6 +68,20 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
end
|
||||
|
||||
context "for a direct link twitter post" do
|
||||
setup do
|
||||
@ref = "https://twitter.com/onsen_musume_jp/status/865534101918330881"
|
||||
@source = "https://pbs.twimg.com/media/DAL-ntWV0AEbhes.jpg:orig"
|
||||
end
|
||||
|
||||
should "trigger the preprocessor" do
|
||||
assert_difference(-> { Upload.preprocessed.count }, 1) do
|
||||
get_auth new_upload_path, @user, params: {:url => @source, :ref => @ref}
|
||||
Delayed::Worker.new.work_off
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "for a twitter post" do
|
||||
setup do
|
||||
@source = "https://twitter.com/frappuccino/status/566030116182949888"
|
||||
@@ -89,6 +103,20 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
end
|
||||
|
||||
context "for a pixiv post" do
|
||||
setup do
|
||||
@ref = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=49270482"
|
||||
@source = "https://i.pximg.net/img-original/img/2015/03/14/17/53/32/49270482_p0.jpg"
|
||||
end
|
||||
|
||||
should "trigger the preprocessor" do
|
||||
assert_difference(-> { Upload.preprocessed.count }, 1) do
|
||||
get_auth new_upload_path, @user, params: {:url => @source, :ref => @ref}
|
||||
Delayed::Worker.new.work_off
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "for a post that has already been uploaded" do
|
||||
setup do
|
||||
as_user do
|
||||
@@ -149,6 +177,48 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
context "when a preprocessed upload already exists" do
|
||||
context "for twitter" do
|
||||
setup do
|
||||
as_user do
|
||||
@ref = "https://twitter.com/onsen_musume_jp/status/865534101918330881"
|
||||
@source = "https://pbs.twimg.com/media/DAL-ntWV0AEbhes.jpg:orig"
|
||||
@upload = create(:upload, status: "preprocessed", source: @source, referer_url: @ref, image_width: 0, image_height: 0, file_size: 0, md5: "something", file_ext: "jpg")
|
||||
end
|
||||
end
|
||||
|
||||
should "update the predecessor" do
|
||||
assert_difference(->{ Post.count }, 1) do
|
||||
assert_difference(->{ Upload.count }, 0) do
|
||||
post_auth uploads_path, @user, params: {:upload => {:tag_string => "aaa", :rating => "q", :source => @source, :referer_url => @ref}}
|
||||
end
|
||||
end
|
||||
post = Post.last
|
||||
assert_match(/aaa/, post.tag_string)
|
||||
end
|
||||
end
|
||||
|
||||
context "for pixiv" do
|
||||
setup do
|
||||
@ref = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=49270482"
|
||||
@source = "https://i.pximg.net/img-original/img/2015/03/14/17/53/32/49270482_p0.jpg"
|
||||
as_user do
|
||||
@upload = create(:upload, status: "preprocessed", source: @source, referer_url: @ref, image_width: 0, image_height: 0, file_size: 0, md5: "something", file_ext: "jpg")
|
||||
end
|
||||
end
|
||||
|
||||
should "update the predecessor" do
|
||||
assert_difference(->{ Post.count }, 1) do
|
||||
assert_difference(->{ Upload.count }, 0) do
|
||||
post_auth uploads_path, @user, params: {:upload => {:tag_string => "aaa", :rating => "q", :source => @source, :referer_url => @ref}}
|
||||
end
|
||||
end
|
||||
post = Post.last
|
||||
assert_match(/aaa/, post.tag_string)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "create a new upload" do
|
||||
assert_difference("Upload.count", 1) do
|
||||
file = Rack::Test::UploadedFile.new("#{Rails.root}/test/files/test.jpg", "image/jpeg")
|
||||
|
||||
@@ -17,31 +17,56 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
context "::Utils" do
|
||||
subject { UploadService::Utils }
|
||||
|
||||
context "#download_from_source" do
|
||||
setup do
|
||||
@jpeg = "https://upload.wikimedia.org/wikipedia/commons/c/c5/Moraine_Lake_17092005.jpg"
|
||||
@ugoira = "https://i.pximg.net/img-zip-ugoira/img/2017/04/04/08/57/38/62247364_ugoira1920x1080.zip"
|
||||
end
|
||||
|
||||
should "work on a jpeg" do
|
||||
file = subject.download_from_source(@jpeg) do |context|
|
||||
assert_not_nil(context[:downloaded_source])
|
||||
assert_not_nil(context[:source])
|
||||
context "#download_for_upload" do
|
||||
context "for a non-source site" do
|
||||
setup do
|
||||
@source = "https://upload.wikimedia.org/wikipedia/commons/c/c5/Moraine_Lake_17092005.jpg"
|
||||
@upload = Upload.new
|
||||
@upload.source = @source
|
||||
end
|
||||
|
||||
assert_operator(File.size(file.path), :>, 0)
|
||||
file.close
|
||||
should "work on a jpeg" do
|
||||
file = subject.download_for_upload(@upload)
|
||||
|
||||
assert_operator(File.size(file.path), :>, 0)
|
||||
|
||||
file.close
|
||||
end
|
||||
end
|
||||
|
||||
should "work on an ugoira url" do
|
||||
file = subject.download_from_source(@ugoira, referer_url: "https://www.pixiv.net") do |context|
|
||||
assert_not_nil(context[:downloaded_source])
|
||||
assert_not_nil(context[:source])
|
||||
assert_not_nil(context[:ugoira])
|
||||
context "for a pixiv" do
|
||||
setup do
|
||||
@source = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350"
|
||||
@upload = Upload.new
|
||||
@upload.source = @source
|
||||
end
|
||||
|
||||
assert_operator(File.size(file.path), :>, 0)
|
||||
file.close
|
||||
should "work on an ugoira url" do
|
||||
file = subject.download_for_upload(@upload)
|
||||
|
||||
assert_operator(File.size(file.path), :>, 0)
|
||||
|
||||
file.close
|
||||
end
|
||||
end
|
||||
|
||||
context "for a pixiv ugoira" do
|
||||
setup do
|
||||
@source = "https://i.pximg.net/img-zip-ugoira/img/2017/04/04/08/57/38/62247364_ugoira1920x1080.zip"
|
||||
@referer = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364"
|
||||
@upload = Upload.new
|
||||
@upload.source = @source
|
||||
@upload.referer_url = @referer
|
||||
end
|
||||
|
||||
should "work on an ugoira url" do
|
||||
file = subject.download_for_upload(@upload)
|
||||
|
||||
assert_not_nil(@upload.context["ugoira"])
|
||||
assert_operator(File.size(file.path), :>, 0)
|
||||
|
||||
file.close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -343,9 +368,6 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
FactoryBot.create(:user)
|
||||
end
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@jpeg = "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"
|
||||
@ugoira = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364"
|
||||
@video = "https://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4"
|
||||
end
|
||||
|
||||
teardown do
|
||||
@@ -356,82 +378,100 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
context "for twitter" do
|
||||
setup do
|
||||
@source = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:large"
|
||||
@norm_source = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:orig"
|
||||
@ref = "https://twitter.com/nounproject/status/540944400767922176"
|
||||
end
|
||||
|
||||
should "record the correct source when a referer is given" do
|
||||
should "download the file" do
|
||||
@service = subject.new(source: @source, referer_url: @ref)
|
||||
@upload = @service.start!
|
||||
assert_equal(@ref, @upload.source)
|
||||
end
|
||||
|
||||
should "save the twimg url in alt_source" do
|
||||
@service = subject.new(source: @source, referer_url: @ref)
|
||||
@upload = @service.start!
|
||||
assert_equal(@norm_source, @upload.alt_source)
|
||||
assert_equal("preprocessed", @upload.status)
|
||||
assert_equal(9800, @upload.file_size)
|
||||
assert_equal("png", @upload.file_ext)
|
||||
assert_equal("f5fe24f3a3a13885285f6627e04feec9", @upload.md5)
|
||||
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "png", :original)))
|
||||
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "png", :preview)))
|
||||
end
|
||||
end
|
||||
|
||||
context "for pixiv" do
|
||||
setup do
|
||||
@source = "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=65981735"
|
||||
@ref = "http://www.pixiv.net/member.php?id=696859"
|
||||
@direct = "https://i.pximg.net/img-original/img/2017/11/21/05/12/37/65981735_p0.jpg"
|
||||
@source = "https://i.pximg.net/img-original/img/2014/10/29/09/27/19/46785915_p0.jpg"
|
||||
@ref = "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=46785915"
|
||||
end
|
||||
|
||||
should "record the correct source" do
|
||||
should "download the file" do
|
||||
@service = subject.new(source: @source, referer_url: @ref)
|
||||
@upload = @service.start!
|
||||
assert_equal(@direct, @upload.source)
|
||||
end
|
||||
assert_equal("preprocessed", @upload.status)
|
||||
assert_equal(294591, @upload.file_size)
|
||||
assert_equal("jpg", @upload.file_ext)
|
||||
assert_equal("3cb1ef624714c15dbb2d6e7b1d57faef", @upload.md5)
|
||||
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
|
||||
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :preview)))
|
||||
end
|
||||
end
|
||||
|
||||
should "work for a jpeg" do
|
||||
@service = subject.new(source: @jpeg)
|
||||
@upload = @service.start!
|
||||
assert_equal("preprocessed", @upload.status)
|
||||
assert_not_nil(@upload.md5)
|
||||
assert_equal("jpg", @upload.file_ext)
|
||||
assert_operator(@upload.file_size, :>, 0)
|
||||
assert_not_nil(@upload.source)
|
||||
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
|
||||
# this image is not large enough to generate a large file
|
||||
#assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :large)))
|
||||
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :preview)))
|
||||
context "for pixiv ugoira" do
|
||||
setup do
|
||||
@source = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364"
|
||||
end
|
||||
|
||||
should "download the file" do
|
||||
@service = subject.new(source: @source)
|
||||
@upload = @service.start!
|
||||
assert_equal("preprocessed", @upload.status)
|
||||
assert_equal(2804, @upload.file_size)
|
||||
assert_equal("zip", @upload.file_ext)
|
||||
assert_equal("cad1da177ef309bf40a117c17b8eecf5", @upload.md5)
|
||||
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "zip", :original)))
|
||||
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "zip", :large)))
|
||||
end
|
||||
end
|
||||
|
||||
should "work for an ugoira" do
|
||||
@service = subject.new(source: @ugoira)
|
||||
@upload = @service.start!
|
||||
assert_equal("preprocessed", @upload.status)
|
||||
assert_not_nil(@upload.md5)
|
||||
assert_equal("zip", @upload.file_ext)
|
||||
assert_operator(@upload.file_size, :>, 0)
|
||||
assert_not_nil(@upload.source)
|
||||
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "zip", :original)))
|
||||
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "zip", :large)))
|
||||
context "for null" do
|
||||
setup do
|
||||
@source = "https://raikou1.donmai.us/93/f4/93f4dd66ef1eb11a89e56d31f9adc8d0.jpg"
|
||||
end
|
||||
|
||||
should "download the file" do
|
||||
@service = subject.new(source: @source)
|
||||
@upload = @service.start!
|
||||
assert_equal("preprocessed", @upload.status)
|
||||
assert_equal(181309, @upload.file_size)
|
||||
assert_equal("jpg", @upload.file_ext)
|
||||
assert_equal("93f4dd66ef1eb11a89e56d31f9adc8d0", @upload.md5)
|
||||
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
|
||||
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :large)))
|
||||
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :preview)))
|
||||
end
|
||||
end
|
||||
|
||||
should "work for a video" do
|
||||
@service = subject.new(source: @video)
|
||||
@upload = @service.start!
|
||||
assert_equal("preprocessed", @upload.status)
|
||||
assert_not_nil(@upload.md5)
|
||||
assert_equal("mp4", @upload.file_ext)
|
||||
assert_operator(@upload.file_size, :>, 0)
|
||||
assert_not_nil(@upload.source)
|
||||
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "mp4", :original)))
|
||||
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "mp4", :preview)))
|
||||
context "for a video" do
|
||||
setup do
|
||||
@source = "https://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4"
|
||||
end
|
||||
|
||||
should "work for a video" do
|
||||
@service = subject.new(source: @source)
|
||||
@upload = @service.start!
|
||||
assert_equal("preprocessed", @upload.status)
|
||||
assert_not_nil(@upload.md5)
|
||||
assert_equal("mp4", @upload.file_ext)
|
||||
assert_operator(@upload.file_size, :>, 0)
|
||||
assert_not_nil(@upload.source)
|
||||
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "mp4", :original)))
|
||||
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "mp4", :preview)))
|
||||
end
|
||||
end
|
||||
|
||||
context "on timeout errors" do
|
||||
setup do
|
||||
@source = "https://raikou1.donmai.us/93/f4/93f4dd66ef1eb11a89e56d31f9adc8d0.jpg"
|
||||
HTTParty.stubs(:get).raises(Net::ReadTimeout)
|
||||
end
|
||||
|
||||
should "leave the upload in an error state" do
|
||||
@service = subject.new(source: @video)
|
||||
@service = subject.new(source: @source)
|
||||
@upload = @service.start!
|
||||
assert_match(/error:/, @upload.status)
|
||||
end
|
||||
@@ -445,41 +485,15 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
FactoryBot.create(:user)
|
||||
end
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@source = "https://twitter.com/nounproject/status/540944400767922176"
|
||||
end
|
||||
|
||||
context "for twitter" do
|
||||
setup do
|
||||
@source = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:large"
|
||||
@norm_source = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:orig"
|
||||
@ref = "https://twitter.com/nounproject/status/540944400767922176"
|
||||
end
|
||||
|
||||
should "record the correct source when a referer is given" do
|
||||
@service = subject.new(source: @source, referer_url: @ref)
|
||||
@upload = @service.start!
|
||||
@service = subject.new(source: @source)
|
||||
@service.finish!
|
||||
@upload.reload
|
||||
|
||||
assert_equal(@ref, @upload.source)
|
||||
end
|
||||
end
|
||||
|
||||
context "for pixiv" do
|
||||
setup do
|
||||
@source = "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=65981735"
|
||||
@ref = "http://www.pixiv.net/member.php?id=696859"
|
||||
@direct = "https://i.pximg.net/img-original/img/2017/11/21/05/12/37/65981735_p0.jpg"
|
||||
end
|
||||
|
||||
should "record the correct source" do
|
||||
@service = subject.new(source: @source, referer_url: @ref)
|
||||
@upload = @service.start!
|
||||
@service = subject.new(source: @source)
|
||||
@service.finish!
|
||||
@upload.reload
|
||||
assert_equal(@direct, @upload.source)
|
||||
end
|
||||
should "overwrite the attributes" do
|
||||
@service = subject.new(source: @source, rating: 'e')
|
||||
@upload = @service.start!
|
||||
@service.finish!
|
||||
@upload.reload
|
||||
assert_equal('e', @upload.rating)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -637,7 +651,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
image_url = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:orig"
|
||||
as_user { @post.replace!(replacement_url: replacement_url) }
|
||||
|
||||
assert_equal(image_url, @post.replacements.last.replacement_url)
|
||||
assert_equal(replacement_url, @post.replacements.last.replacement_url)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1027,7 +1041,33 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "for an ugoira" do
|
||||
context "for a pixiv" do
|
||||
setup do
|
||||
@source = "https://i.pximg.net/img-original/img/2017/11/21/05/12/37/65981735_p0.jpg"
|
||||
@ref = "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=65981735"
|
||||
@upload = FactoryBot.create(:jpg_upload, file_size: 1000, md5: "12345", file_ext: "jpg", image_width: 100, image_height: 100, source: @source, referer_url: @ref)
|
||||
end
|
||||
|
||||
should "record the canonical source" do
|
||||
post = subject.new({}).create_post_from_upload(@upload)
|
||||
assert_equal(@source, post.source)
|
||||
end
|
||||
end
|
||||
|
||||
context "for a twitter" do
|
||||
setup do
|
||||
@source = "https://pbs.twimg.com/media/C1kt72yVEAEGpOv.jpg:large"
|
||||
@ref = "https://twitter.com/aranobu/status/817736083567820800"
|
||||
@upload = FactoryBot.create(:jpg_upload, file_size: 1000, md5: "12345", file_ext: "jpg", image_width: 100, image_height: 100, source: @source, referer_url: @ref)
|
||||
end
|
||||
|
||||
should "record the canonical source" do
|
||||
post = subject.new({}).create_post_from_upload(@upload)
|
||||
assert_equal(@ref, post.source)
|
||||
end
|
||||
end
|
||||
|
||||
context "for a pixiv ugoira" do
|
||||
setup do
|
||||
@upload = FactoryBot.create(:ugoira_upload, file_size: 1000, md5: "12345", file_ext: "jpg", image_width: 100, image_height: 100, context: UGOIRA_CONTEXT)
|
||||
end
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
require 'ptools'
|
||||
|
||||
module DownloadTestHelper
|
||||
def assert_downloaded(expected_filesize, source)
|
||||
download = Downloads::File.new(source)
|
||||
tempfile = download.download!
|
||||
def assert_downloaded(expected_filesize, source, referer=nil)
|
||||
download = Downloads::File.new(source, referer)
|
||||
tempfile, strategy = download.download!
|
||||
assert_equal(expected_filesize, tempfile.size, "Tested source URL: #{source}")
|
||||
rescue Net::OpenTimeout
|
||||
skip "Remote connection to #{source} failed"
|
||||
end
|
||||
|
||||
def assert_rewritten(expected_source, test_source)
|
||||
download = Downloads::File.new(test_source)
|
||||
|
||||
rewritten_source, _, _ = download.before_download(test_source, {})
|
||||
def assert_rewritten(expected_source, test_source, test_referer=nil)
|
||||
strategy = Sources::Strategies.find(test_source, test_referer)
|
||||
rewritten_source = strategy.image_url
|
||||
assert_match(expected_source, rewritten_source, "Tested source URL: #{test_source}")
|
||||
end
|
||||
|
||||
def assert_not_rewritten(source)
|
||||
assert_rewritten(source, source)
|
||||
def assert_not_rewritten(source, referer=nil)
|
||||
assert_rewritten(source, source, referer)
|
||||
end
|
||||
|
||||
def check_ffmpeg
|
||||
|
||||
@@ -229,9 +229,7 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
|
||||
should "find the correct artist for page URLs" do
|
||||
assert_artist_found("artgerm", "http://www.deviantart.com/artgerm/art/Peachy-Princess-Ver-2-457220550")
|
||||
|
||||
assert_artist_found("trixia", "http://www.deviantart.com/trixdraws/art/My-Queen-426745289")
|
||||
assert_artist_found("trixia", "http://www.deviantart.com/trixdraws/gallery/#/d722mrt")
|
||||
end
|
||||
|
||||
should "find the correct artist for image URLs" do
|
||||
@@ -281,11 +279,6 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
assert_artist_found("bkub", "http://www.pixiv.net/i/46239857")
|
||||
end
|
||||
|
||||
should "find nothing for malformed URLs" do
|
||||
assert_artist_not_found("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=herpderp")
|
||||
assert_artist_not_found("http://www.pixiv.net/wharrgarbl")
|
||||
end
|
||||
|
||||
should "find nothing for bad IDs" do
|
||||
assert_raises(PixivApiClient::BadIDError) do
|
||||
assert_artist_not_found("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=32049358")
|
||||
|
||||
@@ -45,6 +45,56 @@ class ArtistUrlTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "artstation urls" do
|
||||
setup do
|
||||
@urls = [
|
||||
FactoryBot.create(:artist_url, url: "https://www.artstation.com/koyorin"),
|
||||
FactoryBot.create(:artist_url, url: "https://www.artstation.com/artist/koyorin"),
|
||||
FactoryBot.create(:artist_url, url: "https://koyorin.artstation.com"),
|
||||
FactoryBot.create(:artist_url, url: "https://www.artstation.com/artwork/04XA4")
|
||||
]
|
||||
end
|
||||
|
||||
should "normalize" do
|
||||
assert_equal("http://www.artstation.com/koyorin/", @urls[0].normalized_url)
|
||||
assert_equal("http://www.artstation.com/koyorin/", @urls[1].normalized_url)
|
||||
assert_equal("http://www.artstation.com/koyorin/", @urls[2].normalized_url)
|
||||
assert_equal("http://www.artstation.com/jeyrain/", @urls[3].normalized_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "deviantart urls" do
|
||||
setup do
|
||||
@urls = [
|
||||
FactoryBot.create(:artist_url, url: "https://www.deviantart.com/aeror404/art/Holiday-Elincia-424551484"),
|
||||
FactoryBot.create(:artist_url, url: "http://noizave.deviantart.com/art/test-post-please-ignore-685436408"),
|
||||
FactoryBot.create(:artist_url, url: "https://www.deviantart.com/noizave")
|
||||
]
|
||||
end
|
||||
|
||||
should "normalize" do
|
||||
assert_equal("http://www.deviantart.com/aeror404/", @urls[0].normalized_url)
|
||||
assert_equal("http://www.deviantart.com/noizave/", @urls[1].normalized_url)
|
||||
assert_equal("http://www.deviantart.com/noizave/", @urls[2].normalized_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "nicoseiga urls" do
|
||||
setup do
|
||||
@urls = [
|
||||
FactoryBot.create(:artist_url, url: "http://seiga.nicovideo.jp/user/illust/7017777"),
|
||||
FactoryBot.create(:artist_url, url: "http://lohas.nicoseiga.jp/o/910aecf08e542285862954017f8a33a8c32a8aec/1433298801/4937663"),
|
||||
FactoryBot.create(:artist_url, url: "http://seiga.nicovideo.jp/seiga/im4937663")
|
||||
]
|
||||
end
|
||||
|
||||
should "normalize" do
|
||||
assert_equal("http://seiga.nicovideo.jp/user/illust/7017777", @urls[0].normalized_url)
|
||||
assert_equal("http://seiga.nicovideo.jp/user/illust/7017777", @urls[1].normalized_url)
|
||||
assert_equal("http://seiga.nicovideo.jp/user/illust/7017777", @urls[2].normalized_url)
|
||||
end
|
||||
end
|
||||
|
||||
should "normalize fc2 urls" do
|
||||
url = FactoryBot.create(:artist_url, :url => "http://blog55.fc2.com/monet")
|
||||
assert_equal("http://blog55.fc2.com/monet", url.url)
|
||||
@@ -56,13 +106,13 @@ class ArtistUrlTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "normalize deviant art artist urls" do
|
||||
url = FactoryBot.create(:artist_url, :url => "https://caidychen.deviantart.com/")
|
||||
assert_equal("http://www.deviantart.com/caidychen/", url.normalized_url)
|
||||
url = FactoryBot.create(:artist_url, :url => "https://www.deviantart.com/aeror404/art/Holiday-Elincia-424551484")
|
||||
assert_equal("http://www.deviantart.com/aeror404/", url.normalized_url)
|
||||
end
|
||||
|
||||
should "normalize nico seiga artist urls" do
|
||||
url = FactoryBot.create(:artist_url, :url => "http://seiga.nicovideo.jp/user/illust/1826959")
|
||||
assert_equal("http://seiga.nicovideo.jp/user/illust/1826959/", url.normalized_url)
|
||||
url = FactoryBot.create(:artist_url, :url => "http://seiga.nicovideo.jp/user/illust/7017777")
|
||||
assert_equal("http://seiga.nicovideo.jp/user/illust/7017777/", url.normalized_url)
|
||||
|
||||
url = FactoryBot.create(:artist_url, :url => "http://seiga.nicovideo.jp/seiga/im4937663")
|
||||
assert_equal("http://seiga.nicovideo.jp/user/illust/7017777/", url.normalized_url)
|
||||
@@ -80,9 +130,9 @@ class ArtistUrlTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "normalize twitter urls" do
|
||||
url = FactoryBot.create(:artist_url, :url => "https://twitter.com/MONET/status/12345")
|
||||
assert_equal("https://twitter.com/MONET/status/12345", url.url)
|
||||
assert_equal("http://twitter.com/monet/status/12345/", url.normalized_url)
|
||||
url = FactoryBot.create(:artist_url, :url => "https://twitter.com/aoimanabu/status/892370963630743552")
|
||||
assert_equal("https://twitter.com/aoimanabu/status/892370963630743552", url.url)
|
||||
assert_equal("http://twitter.com/aoimanabu/", url.normalized_url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,31 +4,35 @@ module Downloads
|
||||
class ArtStationTest < ActiveSupport::TestCase
|
||||
context "a download for a (small) artstation image" do
|
||||
setup do
|
||||
@source = "https://cdnb3.artstation.com/p/assets/images/images/003/716/071/large/aoi-ogata-hate-city.jpg?1476754974"
|
||||
@download = Downloads::File.new(@source)
|
||||
@asset = "https://cdnb3.artstation.com/p/assets/images/images/003/716/071/small/aoi-ogata-hate-city.jpg?1476754974"
|
||||
@download = Downloads::File.new(@asset)
|
||||
end
|
||||
|
||||
should "download the large image instead" do
|
||||
assert_equal("https://cdnb3.artstation.com/p/assets/images/images/003/716/071/large/aoi-ogata-hate-city.jpg?1476754974", @download.source)
|
||||
file, strategy = @download.download!
|
||||
assert_equal(517_706, ::File.size(file.path))
|
||||
end
|
||||
end
|
||||
|
||||
context "for an image where an original does not exist" do
|
||||
setup do
|
||||
@source = "https://cdna.artstation.com/p/assets/images/images/004/730/278/large/mendel-oh-dragonll.jpg"
|
||||
@download = Downloads::File.new(@source)
|
||||
@download.download!
|
||||
@asset = "https://cdna.artstation.com/p/assets/images/images/004/730/278/large/mendel-oh-dragonll.jpg"
|
||||
@download = Downloads::File.new(@asset)
|
||||
end
|
||||
|
||||
should "not try to download the original" do
|
||||
assert_equal("https://cdna.artstation.com/p/assets/images/images/004/730/278/large/mendel-oh-dragonll.jpg", @download.source)
|
||||
file, strategy = @download.download!
|
||||
assert_equal(449_047, ::File.size(file.path))
|
||||
end
|
||||
end
|
||||
|
||||
context "a download for an ArtStation image hosted on CloudFlare" do
|
||||
setup do
|
||||
@asset = "https://cdnb.artstation.com/p/assets/images/images/003/716/071/large/aoi-ogata-hate-city.jpg?1476754974"
|
||||
end
|
||||
|
||||
should "return the original file, not the polished file" do
|
||||
@source = "https://cdnb.artstation.com/p/assets/images/images/003/716/071/large/aoi-ogata-hate-city.jpg?1476754974"
|
||||
assert_downloaded(517_706, @source) # polished size: 502_052
|
||||
assert_downloaded(517_706, @asset) # polished size: 502_052
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,11 +40,12 @@ module Downloads
|
||||
setup do
|
||||
@source = "https://dantewontdie.artstation.com/projects/YZK5q"
|
||||
@download = Downloads::File.new(@source)
|
||||
@download.download!
|
||||
end
|
||||
|
||||
should "download the original image instead" do
|
||||
assert_equal("https://cdna.artstation.com/p/assets/images/images/006/066/534/large/yinan-cui-reika.jpg?1495781565", @download.source)
|
||||
file, strategy = @download.download!
|
||||
|
||||
assert_equal(237_651, ::File.size(file.path))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,11 +8,7 @@ module Downloads
|
||||
|
||||
@source = "http://starbitt.deviantart.com/art/09271X-636962118"
|
||||
@download = Downloads::File.new(@source)
|
||||
@tempfile = @download.download!
|
||||
end
|
||||
|
||||
should "set the html page as the source" do
|
||||
assert_equal("https://orig00.deviantart.net/82ef/f/2016/271/7/1/aaaaaa_by_starbitt-daj8b46.gif", @download.source)
|
||||
@tempfile, strategy = @download.download!
|
||||
end
|
||||
|
||||
should "work" do
|
||||
|
||||
@@ -41,7 +41,7 @@ module Downloads
|
||||
end
|
||||
|
||||
should "store the file in the tempfile path" do
|
||||
tempfile = @download.download!
|
||||
tempfile, strategy = @download.download!
|
||||
assert_equal(@source, @download.source)
|
||||
assert_operator(tempfile.size, :>, 0, "should have data")
|
||||
end
|
||||
|
||||
@@ -4,6 +4,7 @@ module Downloads
|
||||
class PixivTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
Downloads::File.stubs(:is_cloudflare?).returns(false)
|
||||
load_pixiv_tokens!
|
||||
end
|
||||
|
||||
@@ -13,29 +14,6 @@ module Downloads
|
||||
end
|
||||
|
||||
context "in all cases" do
|
||||
# Test an old illustration (one uploaded before 2014-09-16). New
|
||||
# /img-original/ and /img-master/ URLs currently don't work for images
|
||||
# uploaded before this date. Only old /imgXX/img/username/ URLs work.
|
||||
context "downloading an old PNG illustration" do
|
||||
setup do
|
||||
@medium_page = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=14901720"
|
||||
@big_page = "http://www.pixiv.net/member_illust.php?mode=big&illust_id=14901720"
|
||||
|
||||
@new_small_thumbnail = "http://i1.pixiv.net/c/150x150/img-master/img/2010/11/30/08/39/58/14901720_p0_master1200.jpg"
|
||||
@new_medium_thumbnail = "http://i1.pixiv.net/c/600x600/img-master/img/2010/11/30/08/39/58/14901720_p0_master1200.jpg"
|
||||
@new_full_size_image = "http://i1.pixiv.net/img-original/img/2010/11/30/08/39/58/14901720_p0.png"
|
||||
|
||||
@file_size = 1261
|
||||
end
|
||||
|
||||
should "work when using new URLs" do
|
||||
# Don't know the actual file size of the thumbnails since they don't work.
|
||||
assert_downloaded(1083, @new_small_thumbnail)
|
||||
assert_downloaded(1083, @new_medium_thumbnail)
|
||||
assert_downloaded(@file_size, @new_full_size_image)
|
||||
end
|
||||
end
|
||||
|
||||
# Test a new illustration (one uploaded after 2014-09-30). New illustrations
|
||||
# must use /img-original/ for full size URLs. Old /imgXX/img/username/ style URLs
|
||||
# don't work for images uploaded after this date.
|
||||
@@ -103,21 +81,6 @@ module Downloads
|
||||
end
|
||||
end
|
||||
|
||||
context "downloading a bad id image" do
|
||||
setup do
|
||||
@bad_id_full = "https://i.pximg.net/img-original/img/2017/11/22/01/06/44/65991677_p0.png"
|
||||
@bad_id_sample = "https://i.pximg.net/c/600x600/img-master/img/2017/11/22/01/06/44/65991677_p0_master1200.jpg"
|
||||
end
|
||||
|
||||
should "not raise an error when rewriting the url" do
|
||||
assert_nothing_raised { assert_not_rewritten(@bad_id_full) }
|
||||
end
|
||||
|
||||
should_eventually "rewrite bad id samples to full size" do
|
||||
assert_rewritten(@bad_id_full, @bad_id_sample)
|
||||
end
|
||||
end
|
||||
|
||||
context "downloading a ugoira" do
|
||||
setup do
|
||||
@medium_page = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364"
|
||||
@@ -138,6 +101,8 @@ module Downloads
|
||||
|
||||
context "downloading a profile image" do
|
||||
should "download new profile images" do
|
||||
skip "profile images are no longer supported"
|
||||
|
||||
@file_url = "https://i.pximg.net/user-profile/img/2014/12/18/10/31/23/8733472_7dc7310db6cc37163af145d04499e411_170.jpg"
|
||||
@file_size = 23_328
|
||||
|
||||
@@ -149,8 +114,10 @@ module Downloads
|
||||
|
||||
context "downloading a background image" do
|
||||
should "download the image" do
|
||||
@file_url = "http://i1.pixiv.net/background/img/2016/05/17/12/05/48/2074388_d4ac52034f7ca0af3e083d59fde7e97f.jpg"
|
||||
@file_size = 386_678
|
||||
skip "background images are no longer supported"
|
||||
|
||||
@file_url = "https://i.pximg.net/background/img/2015/10/25/08/45/27/198128_77ddf78cdb162e3d1c0d5134af185813.jpg"
|
||||
@file_size = 0
|
||||
|
||||
assert_not_rewritten(@file_url)
|
||||
assert_downloaded(@file_size, @file_url)
|
||||
@@ -159,21 +126,23 @@ module Downloads
|
||||
|
||||
context "downloading a novel image" do
|
||||
should "download new novel images" do
|
||||
@file_url = "http://i1.pixiv.net/novel-cover-original/img/2016/11/03/20/10/58/7436075_f75af69f3eacd1656d3733c72aa959cf.jpg"
|
||||
@file_size = 316_311
|
||||
@file_url = "https://i.pximg.net/novel-cover-original/img/2017/07/27/23/14/17/8465454_80685d10e6df4d7d53ad347ddc18a36b.jpg"
|
||||
@ref = 'https://www.pixiv.net/novel/show.php?id=8465454&mode=cover'
|
||||
@file_size = 532_129
|
||||
|
||||
assert_not_rewritten(@file_url)
|
||||
assert_downloaded(@file_size, @file_url)
|
||||
assert_not_rewritten(@file_url, @ref)
|
||||
assert_downloaded(@file_size, @file_url, @ref)
|
||||
end
|
||||
end
|
||||
|
||||
context "downloading a pixiv fanbox image" do
|
||||
should "work" do
|
||||
@file_url = "https://fanbox.pixiv.net/images/post/31757/w/1200/0CdXtgr4al3t43gQG4NZLnpQ.jpeg"
|
||||
@file_size = 200_239
|
||||
@source = "https://www.pixiv.net/fanbox/creator/12491073/post/82406"
|
||||
@file_url = "https://fanbox.pixiv.net/images/post/82406/D833IKA7FIesJXL8xx39rrG0.jpeg"
|
||||
@file_size = 873_387
|
||||
|
||||
assert_not_rewritten(@file_url)
|
||||
assert_downloaded(@file_size, @file_url)
|
||||
assert_not_rewritten(@file_url, @source)
|
||||
assert_downloaded(@file_size, @file_url, @source)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -181,12 +150,11 @@ module Downloads
|
||||
context "An ugoira site for pixiv" do
|
||||
setup do
|
||||
@download = Downloads::File.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364")
|
||||
@tempfile = @download.download!
|
||||
@tempfile, strategy = @download.download!
|
||||
@tempfile.close!
|
||||
end
|
||||
|
||||
should "capture the data" do
|
||||
assert_equal("https://i.pximg.net/img-zip-ugoira/img/2017/04/04/08/57/38/62247364_ugoira1920x1080.zip", @download.source)
|
||||
assert_equal(2, @download.data[:ugoira_frame_data].size)
|
||||
if @download.data[:ugoira_frame_data][0]["file"]
|
||||
assert_equal([{"file"=>"000000.jpg", "delay"=>125}, {"file"=>"000001.jpg", "delay"=>125}], @download.data[:ugoira_frame_data])
|
||||
|
||||
@@ -2,43 +2,52 @@ require 'test_helper'
|
||||
|
||||
module Downloads
|
||||
class TumblrTest < ActiveSupport::TestCase
|
||||
# Currently there's no way to obtain the raw version of these images,
|
||||
# so we have to change the tests to validate against the 1280 version
|
||||
|
||||
context "a download for a tumblr 500 sample" do
|
||||
should "instead download the raw version" do
|
||||
should "instead download the 1280 version" do
|
||||
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key
|
||||
@ref = "https://noizave.tumblr.com/post/162206271767"
|
||||
@source = "https://24.media.tumblr.com/fc328250915434e66e8e6a92773f79d0/tumblr_mf4nshfibc1s0oswoo1_500.jpg"
|
||||
@rewrite = "http://data.tumblr.com/fc328250915434e66e8e6a92773f79d0/tumblr_mf4nshfibc1s0oswoo1_raw.jpg"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
assert_downloaded(196_617, @source)
|
||||
@rewrite = "https://media.tumblr.com/fc328250915434e66e8e6a92773f79d0/tumblr_mf4nshfibc1s0oswoo1_1280.jpg"
|
||||
assert_rewritten(@rewrite, @source, @ref)
|
||||
assert_downloaded(113909, @source, @ref)
|
||||
# assert_downloaded(196_617, @source)
|
||||
end
|
||||
end
|
||||
|
||||
context "a download for a *.media.tumblr.com/tumblr_$id_$size image without a larger size" do
|
||||
should "download the same version" do
|
||||
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key
|
||||
@ref = "https://noizave.tumblr.com/post/162206271767"
|
||||
@source = "https://25.media.tumblr.com/tumblr_lxbzel2H5y1r9yjhso1_500.jpg"
|
||||
@rewrite = "http://data.tumblr.com/tumblr_lxbzel2H5y1r9yjhso1_500.jpg"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
assert_downloaded(90_122, @source)
|
||||
@rewrite = "https://media.tumblr.com/tumblr_lxbzel2H5y1r9yjhso1_1280.jpg"
|
||||
assert_rewritten(@rewrite, @source, @ref)
|
||||
assert_downloaded(41803, @source, @ref)
|
||||
# assert_downloaded(90_122, @source)
|
||||
end
|
||||
end
|
||||
|
||||
context "a download for a *.media.tumblr.com/tumblr_$id_$size image with a larger size" do
|
||||
should "download the best available version" do
|
||||
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key
|
||||
@ref = "https://noizave.tumblr.com/post/162206271767"
|
||||
@source = "https://25.media.tumblr.com/tumblr_m2dxb8aOJi1rop2v0o1_500.png"
|
||||
@rewrite = "http://data.tumblr.com/tumblr_m2dxb8aOJi1rop2v0o1_1280.png"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
assert_downloaded(34_060, @source)
|
||||
@rewrite = "https://media.tumblr.com/tumblr_m2dxb8aOJi1rop2v0o1_1280.png"
|
||||
assert_rewritten(@rewrite, @source, @ref)
|
||||
assert_downloaded(62658, @source, @ref)
|
||||
end
|
||||
end
|
||||
|
||||
context "a download for a *.media.tumblr.com/$hash/tumblr_$id_rN_$size image" do
|
||||
should "download the best available version" do
|
||||
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key
|
||||
@ref = "https://noizave.tumblr.com/post/162206271767"
|
||||
@source = "https://33.media.tumblr.com/4b7fecf9a5a8284fbaefb051a2369b55/tumblr_npozqfwc9h1rt6u7do1_r1_500.gif"
|
||||
@rewrite = "http://data.tumblr.com/4b7fecf9a5a8284fbaefb051a2369b55/tumblr_npozqfwc9h1rt6u7do1_r1_raw.gif"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
assert_downloaded(1_234_017, @source)
|
||||
@rewrite = "https://media.tumblr.com/4b7fecf9a5a8284fbaefb051a2369b55/tumblr_npozqfwc9h1rt6u7do1_r1_1280.gif"
|
||||
assert_rewritten(@rewrite, @source, @ref)
|
||||
assert_downloaded(1_234_017, @source, @ref)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -46,40 +55,33 @@ module Downloads
|
||||
should "download the best available version" do
|
||||
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key
|
||||
@source = "https://68.media.tumblr.com/ee02048f5578595badc95905e17154b4/tumblr_inline_ofbr4452601sk4jd9_250.gif"
|
||||
@rewrite = "http://data.tumblr.com/ee02048f5578595badc95905e17154b4/tumblr_inline_ofbr4452601sk4jd9_500.gif"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
assert_downloaded(110_348, @source)
|
||||
@rewrite = "https://media.tumblr.com/ee02048f5578595badc95905e17154b4/tumblr_inline_ofbr4452601sk4jd9_1280.gif"
|
||||
assert_rewritten(@rewrite, @source, @ref)
|
||||
assert_downloaded(110_348, @source, @ref)
|
||||
end
|
||||
end
|
||||
|
||||
context "a download for a data.tumblr.com/$id_$size image with a larger size" do
|
||||
context "a download for a media.tumblr.com/$id_$size image with a larger size" do
|
||||
should "download the best available version" do
|
||||
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key
|
||||
@source = "http://data.tumblr.com/0DNBGJovY5j3smfeQs8nB53z_400.jpg"
|
||||
@rewrite = "http://data.tumblr.com/0DNBGJovY5j3smfeQs8nB53z_500.jpg"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
assert_downloaded(153_885, @source)
|
||||
@ref = "https://noizave.tumblr.com/post/162206271767"
|
||||
@source = "http://media.tumblr.com/0DNBGJovY5j3smfeQs8nB53z_400.jpg"
|
||||
@rewrite = "https://media.tumblr.com/0DNBGJovY5j3smfeQs8nB53z_1280.jpg"
|
||||
assert_rewritten(@rewrite, @source, @ref)
|
||||
assert_downloaded(122413, @source)
|
||||
# assert_downloaded(153_885, @source)
|
||||
end
|
||||
end
|
||||
|
||||
context "a download for a data.tumblr.com/tumblr_$id_$size.jpg image" do
|
||||
context "a download for a media.tumblr.com/tumblr_$id_$size.jpg image" do
|
||||
should "download the best available version" do
|
||||
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key
|
||||
@source = "http://data.tumblr.com/tumblr_m24kbxqKAX1rszquso1_250.jpg"
|
||||
@rewrite = "http://data.tumblr.com/tumblr_m24kbxqKAX1rszquso1_1280.jpg"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
assert_downloaded(296_399, @source)
|
||||
end
|
||||
end
|
||||
|
||||
context "a download for a gs1.wac.edgecastcdn.net image" do
|
||||
should "rewrite to the full tumblr version" do
|
||||
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key
|
||||
@source = "https://gs1.wac.edgecastcdn.net/8019B6/data.tumblr.com/tumblr_m2dxb8aOJi1rop2v0o1_500.png"
|
||||
@rewrite = "http://data.tumblr.com/tumblr_m2dxb8aOJi1rop2v0o1_1280.png"
|
||||
|
||||
assert_downloaded(34_060, @source)
|
||||
assert_rewritten(@rewrite, @source)
|
||||
@ref = "https://noizave.tumblr.com/post/162206271767"
|
||||
@source = "http://media.tumblr.com/tumblr_m24kbxqKAX1rszquso1_250.jpg"
|
||||
@rewrite = "https://media.tumblr.com/tumblr_m24kbxqKAX1rszquso1_1280.jpg"
|
||||
assert_rewritten(@rewrite, @source, @ref)
|
||||
assert_downloaded(101869, @source, @ref)
|
||||
# assert_downloaded(296_399, @source)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -87,9 +89,9 @@ module Downloads
|
||||
should "download the best available version" do
|
||||
skip "Tumblr keys are not set" unless Danbooru.config.tumblr_consumer_key
|
||||
@source = "https://noizave.tumblr.com/post/162206271767"
|
||||
@rewrite = "http://data.tumblr.com/3bbfcbf075ddf969c996641b264086fd/tumblr_os2buiIOt51wsfqepo1_raw.png"
|
||||
@rewrite = "https://media.tumblr.com/3bbfcbf075ddf969c996641b264086fd/tumblr_os2buiIOt51wsfqepo1_1280.png"
|
||||
|
||||
assert_downloaded(3_620, @source)
|
||||
assert_downloaded(3655, @source)
|
||||
assert_rewritten(@rewrite, @source)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,17 +8,19 @@ module Downloads
|
||||
@source = "https://twitter.com/CincinnatiZoo/status/859073537713328129"
|
||||
@rewrite = "https://video.twimg.com/ext_tw_video/859073467769126913/pu/vid/1280x720/cPGgVROXHy3yrK6u.mp4"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
assert_downloaded(8_602_983, @source)
|
||||
|
||||
# this takes awhile so just skip it unless we really want to test it
|
||||
# assert_downloaded(8_602_983, @source)
|
||||
end
|
||||
end
|
||||
|
||||
context "downloading a 'https://twitter.com/:user/status/:id/photo/:n' card url" do
|
||||
should "download the orig file" do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@source = "https://twitter.com/masayasuf/status/870734961778630656/photo/1"
|
||||
@rewrite = "https://pbs.twimg.com/media/DBV40M2UIAAHYlt.jpg:orig"
|
||||
@source = "https://twitter.com/ry_o_ta_/status/1024316791688843269/photo/1"
|
||||
@rewrite = "https://pbs.twimg.com/media/Djcar72VsAAZsGa.jpg:orig"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
assert_downloaded(788_206, @source)
|
||||
assert_downloaded(103812, @source)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,8 +39,9 @@ module Downloads
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@source = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:large"
|
||||
@rewrite = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:orig"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
assert_downloaded(9800, @source)
|
||||
@ref = "https://twitter.com/nounproject/status/540944400767922176"
|
||||
assert_rewritten(@rewrite, @source, @ref)
|
||||
assert_downloaded(9800, @source, @ref)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PostReplacementTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
mock_iqdb_service!
|
||||
Delayed::Worker.delay_jobs = true # don't delete the old images right away
|
||||
|
||||
@system = FactoryBot.create(:user, created_at: 2.weeks.ago)
|
||||
User.stubs(:system).returns(@system)
|
||||
|
||||
@uploader = FactoryBot.create(:user, created_at: 2.weeks.ago, can_upload_free: true)
|
||||
@replacer = FactoryBot.create(:user, created_at: 2.weeks.ago, can_approve_posts: true)
|
||||
CurrentUser.user = @replacer
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
Delayed::Worker.delay_jobs = false
|
||||
end
|
||||
|
||||
context "Replacing" do
|
||||
setup do
|
||||
CurrentUser.scoped(@uploader, "127.0.0.2") do
|
||||
attributes = FactoryBot.attributes_for(:jpg_upload, as_pending: "0", tag_string: "lowres tag1")
|
||||
service = UploadService.new(attributes)
|
||||
upload = service.start!
|
||||
@post = upload.post
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1480,26 +1480,6 @@ class PostTest < ActiveSupport::TestCase
|
||||
assert_equal(18557054, @post.pixiv_id)
|
||||
@post.pixiv_id = nil
|
||||
end
|
||||
|
||||
context "but doesn't have a pixiv id" do
|
||||
should "save the pixiv id" do
|
||||
@post.pixiv_id = 1234
|
||||
@post.update(source: "http://i1.pixiv.net/novel-cover-original/img/2016/11/03/20/10/58/7436075_f75af69f3eacd1656d3733c72aa959cf.jpg")
|
||||
assert_nil(@post.pixiv_id)
|
||||
|
||||
@post.pixiv_id = 1234
|
||||
@post.update(source: "http://i2.pixiv.net/background/img/2016/10/30/12/27/30/7059005_da9946b806c10d391a81ed1117cd33d6.jpg")
|
||||
assert_nil(@post.pixiv_id)
|
||||
|
||||
@post.pixiv_id = 1234
|
||||
@post.update(source: "http://i1.pixiv.net/img15/img/omega777/novel/2612734.jpg")
|
||||
assert_nil(@post.pixiv_id)
|
||||
|
||||
@post.pixiv_id = 1234
|
||||
@post.update(source: "http://img08.pixiv.net/profile/nice/1408837.jpg")
|
||||
assert_nil(@post.pixiv_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "normalize pixiv links" do
|
||||
|
||||
@@ -4,8 +4,7 @@ module Sources
|
||||
class ArtStationTest < ActiveSupport::TestCase
|
||||
context "The source site for an art station artwork page" do
|
||||
setup do
|
||||
@site = Sources::Site.new("https://www.artstation.com/artwork/04XA4")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://www.artstation.com/artwork/04XA4")
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
@@ -32,8 +31,7 @@ module Sources
|
||||
|
||||
context "The source site for an art station projects page" do
|
||||
setup do
|
||||
@site = Sources::Site.new("https://dantewontdie.artstation.com/projects/YZK5q")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://dantewontdie.artstation.com/projects/YZK5q")
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
@@ -61,8 +59,7 @@ module Sources
|
||||
|
||||
context "The source site for a www.artstation.com/artwork/$slug page" do
|
||||
setup do
|
||||
@site = Sources::Site.new("https://www.artstation.com/artwork/cody-from-sf")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://www.artstation.com/artwork/cody-from-sf")
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
@@ -75,8 +72,7 @@ module Sources
|
||||
setup do
|
||||
@url = "https://cdna.artstation.com/p/assets/images/images/006/029/978/large/amama-l-z.jpg"
|
||||
@ref = "https://www.artstation.com/artwork/4BWW2"
|
||||
@site = Sources::Site.new(@url, referer_url: @ref)
|
||||
@site.get
|
||||
@site = Sources::Strategies.find(@url, @ref)
|
||||
end
|
||||
|
||||
should "fetch the source data" do
|
||||
@@ -86,8 +82,7 @@ module Sources
|
||||
|
||||
context "The source site for an ArtStation gallery" do
|
||||
setup do
|
||||
@site = Sources::Site.new("https://www.artstation.com/artwork/BDxrA")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://www.artstation.com/artwork/BDxrA")
|
||||
end
|
||||
|
||||
should "get only image urls, not video urls" do
|
||||
|
||||
@@ -9,8 +9,7 @@ module Sources
|
||||
|
||||
context "A path-based artist url" do
|
||||
setup do
|
||||
@site = Sources::Site.new("https://www.deviantart.com/aeror404/art/Holiday-Elincia-424551484")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://www.deviantart.com/aeror404/art/Holiday-Elincia-424551484")
|
||||
end
|
||||
|
||||
should "work" do
|
||||
@@ -20,8 +19,7 @@ module Sources
|
||||
|
||||
context "The source for a private DeviantArt image URL" do
|
||||
setup do
|
||||
@site = Sources::Site.new("https://pre00.deviantart.net/423b/th/pre/i/2017/281/e/0/mindflayer_girl01_by_nickbeja-dbpxdt8.png")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://pre00.deviantart.net/423b/th/pre/i/2017/281/e/0/mindflayer_girl01_by_nickbeja-dbpxdt8.png")
|
||||
end
|
||||
|
||||
should "work" do
|
||||
@@ -31,25 +29,24 @@ module Sources
|
||||
|
||||
context "The source for a download-disabled DeviantArt artwork page" do
|
||||
should "get the image url" do
|
||||
@site = Sources::Site.new("https://noizave.deviantart.com/art/test-no-download-697415967")
|
||||
@site = Sources::Strategies.find("https://noizave.deviantart.com/art/test-no-download-697415967")
|
||||
assert_equal(["https://img00.deviantart.net/56ee/i/2017/219/2/3/test__no_download_by_noizave-dbj81lr.jpg"], @site.image_urls)
|
||||
end
|
||||
end
|
||||
|
||||
context "The source for a DeviantArt image url" do
|
||||
should "fetch the source data" do
|
||||
@site = Sources::Site.new("https://pre00.deviantart.net/b5e6/th/pre/f/2016/265/3/5/legend_of_galactic_heroes_by_hideyoshi-daihpha.jpg")
|
||||
@site = Sources::Strategies.find("https://pre00.deviantart.net/b5e6/th/pre/f/2016/265/3/5/legend_of_galactic_heroes_by_hideyoshi-daihpha.jpg")
|
||||
|
||||
assert_equal("hideyoshi", @site.artist_name)
|
||||
assert_equal("https://hideyoshi.deviantart.com", @site.profile_url)
|
||||
assert_equal("https://orig00.deviantart.net/9e1f/f/2016/265/3/5/legend_of_galactic_heroes_by_hideyoshi-daihpha.jpg", @site.image_url)
|
||||
assert_equal("https://www.deviantart.com/hideyoshi", @site.profile_url)
|
||||
assert_equal("https://pre00.deviantart.net/b5e6/th/pre/f/2016/265/3/5/legend_of_galactic_heroes_by_hideyoshi-daihpha.jpg", @site.image_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "The source for an DeviantArt artwork page" do
|
||||
setup do
|
||||
@site = Sources::Site.new("http://noizave.deviantart.com/art/test-post-please-ignore-685436408")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("http://noizave.deviantart.com/art/test-post-please-ignore-685436408")
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
@@ -107,8 +104,7 @@ module Sources
|
||||
|
||||
context "The source for a login-only DeviantArt artwork page" do
|
||||
setup do
|
||||
@site = Sources::Site.new("http://noizave.deviantart.com/art/hidden-work-685458369")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("http://noizave.deviantart.com/art/hidden-work-685458369")
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
@@ -118,8 +114,7 @@ module Sources
|
||||
|
||||
context "A source with malformed links in the artist commentary" do
|
||||
should "fix the links" do
|
||||
@site = Sources::Site.new("https://teemutaiga.deviantart.com/art/Kisu-620666655")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://teemutaiga.deviantart.com/art/Kisu-620666655")
|
||||
|
||||
assert_match(%r!"Print available at Inprnt":\[http://www.inprnt.com/gallery/teemutaiga/kisu\]!, @site.dtext_artist_commentary_desc)
|
||||
end
|
||||
|
||||
@@ -4,11 +4,8 @@ module Sources
|
||||
class NicoSeigaTest < ActiveSupport::TestCase
|
||||
context "The source site for nico seiga" do
|
||||
setup do
|
||||
@site_1 = Sources::Site.new("http://lohas.nicoseiga.jp/o/910aecf08e542285862954017f8a33a8c32a8aec/1433298801/4937663")
|
||||
@site_1.get
|
||||
|
||||
@site_2 = Sources::Site.new("http://seiga.nicovideo.jp/seiga/im4937663")
|
||||
@site_2.get
|
||||
@site_1 = Sources::Strategies.find("http://lohas.nicoseiga.jp/o/910aecf08e542285862954017f8a33a8c32a8aec/1433298801/4937663")
|
||||
@site_2 = Sources::Strategies.find("http://seiga.nicovideo.jp/seiga/im4937663")
|
||||
end
|
||||
|
||||
should "get the profile" do
|
||||
@@ -34,11 +31,11 @@ module Sources
|
||||
should "get the tags" do
|
||||
assert(@site_1.tags.size > 0)
|
||||
first_tag = @site_1.tags.first
|
||||
assert_equal(["アニメ", "http://seiga.nicovideo.jp/tag/%E3%82%A2%E3%83%8B%E3%83%A1"], first_tag)
|
||||
assert_equal(["アニメ", "https://seiga.nicovideo.jp/tag/%E3%82%A2%E3%83%8B%E3%83%A1"], first_tag)
|
||||
|
||||
assert(@site_2.tags.size > 0)
|
||||
first_tag = @site_2.tags.first
|
||||
assert_equal(["アニメ", "http://seiga.nicovideo.jp/tag/%E3%82%A2%E3%83%8B%E3%83%A1"], first_tag)
|
||||
assert_equal(["アニメ", "https://seiga.nicovideo.jp/tag/%E3%82%A2%E3%83%8B%E3%83%A1"], first_tag)
|
||||
end
|
||||
|
||||
should "convert a page into a json representation" do
|
||||
@@ -51,8 +48,7 @@ module Sources
|
||||
end
|
||||
|
||||
should "work for a https://lohas.nicoseiga.jp/thumb/${id}i url" do
|
||||
site = Sources::Site.new("https://lohas.nicoseiga.jp/thumb/6844226i")
|
||||
site.get
|
||||
site = Sources::Strategies.find("https://lohas.nicoseiga.jp/thumb/6844226i")
|
||||
|
||||
full_image_url = %r!https?://lohas.nicoseiga.jp/priv/[a-f0-9]{40}/[0-9]+/6844226!
|
||||
assert_match(full_image_url, site.image_url)
|
||||
|
||||
@@ -7,9 +7,7 @@ module Sources
|
||||
CurrentUser.user = FactoryBot.create(:user)
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
@site = Sources::Site.new("http://nijie.info/view.php?id=213043")
|
||||
@site.get
|
||||
sleep(5)
|
||||
@site = Sources::Strategies.find("https://nijie.info/view.php?id=213043")
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
@@ -17,7 +15,7 @@ module Sources
|
||||
end
|
||||
|
||||
should "get the profile" do
|
||||
assert_equal("http://nijie.info/members.php?id=728995", @site.profile_url)
|
||||
assert_equal("https://nijie.info/members.php?id=728995", @site.profile_url)
|
||||
end
|
||||
|
||||
should "get the artist name" do
|
||||
@@ -25,15 +23,14 @@ module Sources
|
||||
end
|
||||
|
||||
should "get the tags" do
|
||||
assert_equal([["眼鏡", "http://nijie.info/search.php?word=%E7%9C%BC%E9%8F%A1"], ["リトルウィッチアカデミア", "http://nijie.info/search.php?word=%E3%83%AA%E3%83%88%E3%83%AB%E3%82%A6%E3%82%A3%E3%83%83%E3%83%81%E3%82%A2%E3%82%AB%E3%83%87%E3%83%9F%E3%82%A2"], ["アーシュラ先生", "http://nijie.info/search.php?word=%E3%82%A2%E3%83%BC%E3%82%B7%E3%83%A5%E3%83%A9%E5%85%88%E7%94%9F"]], @site.tags)
|
||||
assert_equal([["眼鏡", "https://nijie.info/search.php?word=%E7%9C%BC%E9%8F%A1"], ["リトルウィッチアカデミア", "https://nijie.info/search.php?word=%E3%83%AA%E3%83%88%E3%83%AB%E3%82%A6%E3%82%A3%E3%83%83%E3%83%81%E3%82%A2%E3%82%AB%E3%83%87%E3%83%9F%E3%82%A2"], ["アーシュラ先生", "https://nijie.info/search.php?word=%E3%82%A2%E3%83%BC%E3%82%B7%E3%83%A5%E3%83%A9%E5%85%88%E7%94%9F"]], @site.tags)
|
||||
end
|
||||
|
||||
should "normalize ()characters in tags" do
|
||||
FactoryBot.create(:tag, :name => "kaga")
|
||||
FactoryBot.create(:wiki_page, :title => "kaga", :other_names => "加賀(艦これ)")
|
||||
|
||||
@site = Sources::Site.new("http://nijie.info/view.php?id=208316")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://nijie.info/view.php?id=208316")
|
||||
|
||||
assert_includes(@site.tags.map(&:first), "加賀(艦これ)")
|
||||
assert_includes(@site.translated_tags.map(&:first), "kaga")
|
||||
@@ -50,16 +47,15 @@ module Sources
|
||||
|
||||
context "The source site for a nijie referer url" do
|
||||
setup do
|
||||
@site = Sources::Site.new("http://pic03.nijie.info/nijie_picture/728995_20170505014820_0.jpg", referer_url: "https://nijie.info/view_popup.php?id=213043")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("http://pic03.nijie.info/nijie_picture/728995_20170505014820_0.jpg", "https://nijie.info/view_popup.php?id=213043")
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal("https://pic03.nijie.info/nijie_picture/728995_20170505014820_0.jpg", @site.image_url)
|
||||
assert_equal("http://pic03.nijie.info/nijie_picture/728995_20170505014820_0.jpg", @site.image_url)
|
||||
end
|
||||
|
||||
should "get the profile" do
|
||||
assert_equal("http://nijie.info/members.php?id=728995", @site.profile_url)
|
||||
assert_equal("https://nijie.info/members.php?id=728995", @site.profile_url)
|
||||
end
|
||||
|
||||
should "get the artist name" do
|
||||
@@ -69,8 +65,7 @@ module Sources
|
||||
|
||||
context "The source site for a nijie popup" do
|
||||
setup do
|
||||
@site = Sources::Site.new("https://nijie.info/view_popup.php?id=213043")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://nijie.info/view_popup.php?id=213043")
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
@@ -78,7 +73,7 @@ module Sources
|
||||
end
|
||||
|
||||
should "get the profile" do
|
||||
assert_equal("http://nijie.info/members.php?id=728995", @site.profile_url)
|
||||
assert_equal("https://nijie.info/members.php?id=728995", @site.profile_url)
|
||||
end
|
||||
|
||||
should "get the artist name" do
|
||||
@@ -88,8 +83,7 @@ module Sources
|
||||
|
||||
context "The source site for a nijie gallery" do
|
||||
setup do
|
||||
@site = Sources::Site.new("http://nijie.info/view.php?id=218856")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://nijie.info/view.php?id=218856")
|
||||
end
|
||||
|
||||
should "get the image urls" do
|
||||
|
||||
@@ -5,8 +5,7 @@ module Sources
|
||||
context "The source site for a https://pawoo.net/web/status/$id url" do
|
||||
setup do
|
||||
skip "Pawoo keys not set" unless Danbooru.config.pawoo_client_id
|
||||
@site = Sources::Site.new("https://pawoo.net/web/statuses/1202176")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://pawoo.net/web/statuses/1202176")
|
||||
end
|
||||
|
||||
should "get the profile" do
|
||||
@@ -35,8 +34,7 @@ module Sources
|
||||
context "The source site for a https://pawoo.net/$user/$id url" do
|
||||
setup do
|
||||
skip "Pawoo keys not set" unless Danbooru.config.pawoo_client_id
|
||||
@site = Sources::Site.new("https://pawoo.net/@evazion/19451018")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://pawoo.net/@evazion/19451018")
|
||||
end
|
||||
|
||||
should "get the profile" do
|
||||
@@ -89,8 +87,7 @@ module Sources
|
||||
skip "Pawoo keys not set" unless Danbooru.config.pawoo_client_id
|
||||
@url = "https://img.pawoo.net/media_attachments/files/001/298/028/original/55a6fd252778454b.mp4"
|
||||
@ref = "https://pawoo.net/@evazion/19451018"
|
||||
@site = Sources::Site.new(@url, referer_url: @ref)
|
||||
@site.get
|
||||
@site = Sources::Strategies.find(@url, @ref)
|
||||
end
|
||||
|
||||
should "fetch the source data" do
|
||||
|
||||
@@ -3,8 +3,8 @@ require 'test_helper'
|
||||
module Sources
|
||||
class PixivTest < ActiveSupport::TestCase
|
||||
def get_source(source)
|
||||
@site = Sources::Site.new(source)
|
||||
@site.get
|
||||
@site = Sources::Strategies.find(source)
|
||||
|
||||
@site
|
||||
rescue Net::OpenTimeout
|
||||
skip "Remote connection to #{source} failed"
|
||||
@@ -23,19 +23,22 @@ module Sources
|
||||
context "in all cases" do
|
||||
context "A touch page" do
|
||||
setup do
|
||||
@site = Sources::Site.new("http://touch.pixiv.net/member_illust.php?mode=medium&illust_id=59687915")
|
||||
@image_urls = @site.get
|
||||
@site = Sources::Strategies.find("http://touch.pixiv.net/member_illust.php?mode=medium&illust_id=59687915")
|
||||
@image_urls = @site.image_urls
|
||||
end
|
||||
|
||||
should "get all the image urls" do
|
||||
assert_equal("https://i.pximg.net/img-original/img/2016/10/29/17/13/23/59687915_p0.png", @image_urls)
|
||||
expected_urls = [
|
||||
"https://i.pximg.net/img-original/img/2016/10/29/17/13/23/59687915_p0.png",
|
||||
"https://i.pximg.net/img-original/img/2016/10/29/17/13/23/59687915_p1.png"
|
||||
].sort
|
||||
assert_equal(expected_urls, @image_urls.sort)
|
||||
end
|
||||
end
|
||||
|
||||
context "A gallery page" do
|
||||
setup do
|
||||
@site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=49270482")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=49270482")
|
||||
@image_urls = @site.image_urls
|
||||
end
|
||||
|
||||
@@ -46,8 +49,7 @@ module Sources
|
||||
|
||||
context "An ugoira source site for pixiv" do
|
||||
setup do
|
||||
@site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364")
|
||||
end
|
||||
|
||||
should "get the file url" do
|
||||
@@ -66,8 +68,7 @@ module Sources
|
||||
|
||||
context "A https://i.pximg.net/img-zip/ugoira/* source" do
|
||||
should "get the metadata" do
|
||||
@site = Sources::Site.new("https://i.pximg.net/img-zip-ugoira/img/2017/04/04/08/57/38/62247364_ugoira1920x1080.zip")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://i.pximg.net/img-zip-ugoira/img/2017/04/04/08/57/38/62247364_ugoira1920x1080.zip")
|
||||
|
||||
assert_equal("uroobnad2", @site.artist_name)
|
||||
end
|
||||
@@ -79,7 +80,7 @@ module Sources
|
||||
end
|
||||
|
||||
should "get the profile" do
|
||||
assert_equal("http://www.pixiv.net/member.php?id=696859", @site.profile_url)
|
||||
assert_equal("https://www.pixiv.net/member.php?id=696859", @site.profile_url)
|
||||
end
|
||||
|
||||
should "get the artist name" do
|
||||
@@ -142,12 +143,17 @@ module Sources
|
||||
should "get the full size image url" do
|
||||
assert_equal("https://i.pximg.net/img-original/img/2017/08/18/00/09/21/64476642_p0.jpg", @site.image_url)
|
||||
end
|
||||
|
||||
should "get the full size image url for the canonical url" do
|
||||
assert_equal("https://i.pximg.net/img-original/img/2017/08/18/00/09/21/64476642_p0.jpg", @site.canonical_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "fetching source data for a deleted work" do
|
||||
should "raise a bad id error" do
|
||||
assert_raise(::PixivApiClient::BadIDError) do
|
||||
get_source("https://i.pximg.net/img-original/img/2017/11/22/01/06/44/65991677_p0.png")
|
||||
@site.image_urls
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,8 +9,7 @@ module Sources
|
||||
|
||||
context "The source for a 'http://*.tumblr.com/post/*' photo post with a single image" do
|
||||
setup do
|
||||
@site = Sources::Site.new("https://noizave.tumblr.com/post/162206271767")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://noizave.tumblr.com/post/162206271767")
|
||||
end
|
||||
|
||||
should "get the artist name" do
|
||||
@@ -22,7 +21,7 @@ module Sources
|
||||
end
|
||||
|
||||
should "get the tags" do
|
||||
tags = [["tag", "https://tumblr.com/tagged/tag"], ["red_hair", "https://tumblr.com/tagged/red-hair"]]
|
||||
tags = [["tag", "https://tumblr.com/tagged/tag"], ["red_hair", "https://tumblr.com/tagged/red_hair"]]
|
||||
assert_equal(tags, @site.tags)
|
||||
end
|
||||
|
||||
@@ -68,7 +67,7 @@ module Sources
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal("http://data.tumblr.com/3bbfcbf075ddf969c996641b264086fd/tumblr_os2buiIOt51wsfqepo1_raw.png", @site.image_url)
|
||||
assert_equal("https://media.tumblr.com/3bbfcbf075ddf969c996641b264086fd/tumblr_os2buiIOt51wsfqepo1_1280.png", @site.image_url)
|
||||
end
|
||||
|
||||
should "get the artist" do
|
||||
@@ -82,16 +81,15 @@ module Sources
|
||||
|
||||
context "The source for a 'http://*.tumblr.com/image/*' image page" do
|
||||
setup do
|
||||
@site = Sources::Site.new("https://noizave.tumblr.com/image/162206271767")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://noizave.tumblr.com/image/162206271767")
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal("http://data.tumblr.com/3bbfcbf075ddf969c996641b264086fd/tumblr_os2buiIOt51wsfqepo1_raw.png", @site.image_url)
|
||||
assert_equal("https://media.tumblr.com/3bbfcbf075ddf969c996641b264086fd/tumblr_os2buiIOt51wsfqepo1_1280.png", @site.image_url)
|
||||
end
|
||||
|
||||
should "get the tags" do
|
||||
tags = [["tag", "https://tumblr.com/tagged/tag"], ["red_hair", "https://tumblr.com/tagged/red-hair"]]
|
||||
tags = [["tag", "https://tumblr.com/tagged/tag"], ["red_hair", "https://tumblr.com/tagged/red_hair"]]
|
||||
assert_equal(tags, @site.tags)
|
||||
end
|
||||
end
|
||||
@@ -100,20 +98,19 @@ module Sources
|
||||
setup do
|
||||
@url = "https://78.media.tumblr.com/7c4d2c6843466f92c3dd0516e749ec35/tumblr_orwwptNBCE1wsfqepo2_1280.jpg"
|
||||
@ref = "https://noizave.tumblr.com/post/162094447052"
|
||||
@site = Sources::Site.new(@url, referer_url: @ref)
|
||||
@site.get
|
||||
@site = Sources::Strategies.find(@url, @ref)
|
||||
end
|
||||
|
||||
should "get the image urls" do
|
||||
urls = %w[
|
||||
http://data.tumblr.com/afed9f5b3c33c39dc8c967e262955de2/tumblr_orwwptNBCE1wsfqepo1_raw.png
|
||||
http://data.tumblr.com/7c4d2c6843466f92c3dd0516e749ec35/tumblr_orwwptNBCE1wsfqepo2_raw.jpg
|
||||
http://data.tumblr.com/d2ed224f135b0c81f812df81a0a8692d/tumblr_orwwptNBCE1wsfqepo3_raw.gif
|
||||
http://data.tumblr.com/3bbfcbf075ddf969c996641b264086fd/tumblr_inline_os3134mABB1v11u29_raw.png
|
||||
http://data.tumblr.com/34ed9d0ff4a21625981372291cb53040/tumblr_nv3hwpsZQY1uft51jo1_raw.gif
|
||||
https://media.tumblr.com/afed9f5b3c33c39dc8c967e262955de2/tumblr_orwwptNBCE1wsfqepo1_1280.png
|
||||
https://media.tumblr.com/7c4d2c6843466f92c3dd0516e749ec35/tumblr_orwwptNBCE1wsfqepo2_1280.jpg
|
||||
https://media.tumblr.com/d2ed224f135b0c81f812df81a0a8692d/tumblr_orwwptNBCE1wsfqepo3_1280.gif
|
||||
https://media.tumblr.com/3bbfcbf075ddf969c996641b264086fd/tumblr_inline_os3134mABB1v11u29_1280.png
|
||||
https://media.tumblr.com/34ed9d0ff4a21625981372291cb53040/tumblr_nv3hwpsZQY1uft51jo1_1280.gif
|
||||
]
|
||||
|
||||
assert_equal(urls, @site.image_urls)
|
||||
assert_equal(urls.sort, @site.image_urls.sort)
|
||||
end
|
||||
|
||||
should "get the tags" do
|
||||
@@ -129,17 +126,16 @@ module Sources
|
||||
|
||||
context "The source for a 'http://*.tumblr.com/post/*' text post with inline images" do
|
||||
setup do
|
||||
@site = Sources::Site.new("https://noizave.tumblr.com/post/162221502947")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://noizave.tumblr.com/post/162221502947")
|
||||
end
|
||||
|
||||
should "get the image urls" do
|
||||
urls = %w[
|
||||
http://data.tumblr.com/afed9f5b3c33c39dc8c967e262955de2/tumblr_inline_os2zhkfhY01v11u29_raw.png
|
||||
http://data.tumblr.com/7c4d2c6843466f92c3dd0516e749ec35/tumblr_inline_os2zkg02xH1v11u29_raw.jpg
|
||||
https://media.tumblr.com/afed9f5b3c33c39dc8c967e262955de2/tumblr_inline_os2zhkfhY01v11u29_1280.png
|
||||
https://media.tumblr.com/7c4d2c6843466f92c3dd0516e749ec35/tumblr_inline_os2zkg02xH1v11u29_1280.jpg
|
||||
]
|
||||
|
||||
assert_equal(urls, @site.image_urls)
|
||||
assert_equal(urls.sort, @site.image_urls.sort)
|
||||
end
|
||||
|
||||
should "get the commentary" do
|
||||
@@ -151,14 +147,13 @@ module Sources
|
||||
|
||||
context "The source for a 'http://*.tumblr.com/post/*' video post with inline images" do
|
||||
setup do
|
||||
@site = Sources::Site.new("https://noizave.tumblr.com/post/162222617101")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://noizave.tumblr.com/post/162222617101")
|
||||
end
|
||||
|
||||
should "get the image urls" do
|
||||
urls = %w[
|
||||
https://vtt.tumblr.com/tumblr_os31dkexhK1wsfqep.mp4
|
||||
http://data.tumblr.com/afed9f5b3c33c39dc8c967e262955de2/tumblr_inline_os31dclyCR1v11u29_raw.png
|
||||
https://media.tumblr.com/afed9f5b3c33c39dc8c967e262955de2/tumblr_inline_os31dclyCR1v11u29_1280.png
|
||||
]
|
||||
|
||||
assert_equal(urls, @site.image_urls)
|
||||
@@ -167,12 +162,11 @@ module Sources
|
||||
|
||||
context "The source for a 'http://*.tumblr.com/post/*' answer post with inline images" do
|
||||
setup do
|
||||
@site = Sources::Site.new("https://noizave.tumblr.com/post/171237880542/test-ask")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://noizave.tumblr.com/post/171237880542/test-ask")
|
||||
end
|
||||
|
||||
should "get the image urls" do
|
||||
urls = ["http://data.tumblr.com/cb481f031010e8ddad564b2150149c9a/tumblr_inline_p4nxoyLrSh1v11u29_raw.png"]
|
||||
urls = ["https://media.tumblr.com/cb481f031010e8ddad564b2150149c9a/tumblr_inline_p4nxoyLrSh1v11u29_1280.png"]
|
||||
assert_equal(urls, @site.image_urls)
|
||||
end
|
||||
|
||||
|
||||
@@ -2,79 +2,16 @@ require 'test_helper'
|
||||
|
||||
module Sources
|
||||
class TwitterTest < ActiveSupport::TestCase
|
||||
context "A video" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://twitter.com/CincinnatiZoo/status/859073537713328129")
|
||||
@site.get
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal("https://video.twimg.com/ext_tw_video/859073467769126913/pu/vid/1280x720/cPGgVROXHy3yrK6u.mp4", @site.image_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "An animated gif" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://twitter.com/DaniStrawberry1/status/859435334765088769")
|
||||
@site.get
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal("https://video.twimg.com/tweet_video/C-1Tns7WsAAqvqn.mp4", @site.image_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "A twitter summary card" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://twitter.com/NatGeo/status/932700115936178177")
|
||||
@site.get
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal("https://pmdvod.nationalgeographic.com/NG_Video/205/302/smpost_1510342850295.jpg", @site.image_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "A twitter summary card from twitter" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://twitter.com/masayasuf/status/870734961778630656/photo/1")
|
||||
@site.get
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal("https://pbs.twimg.com/media/DBV40M2UIAAHYlt.jpg:orig", @site.image_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "A twitter summary card from twitter with a :large image" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://twitter.com/aranobu/status/817736083567820800")
|
||||
@site.get
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal("https://pbs.twimg.com/media/C1kt72yVEAEGpOv.jpg:orig", @site.image_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "An extended tweet" do
|
||||
should "extract the correct image url" do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://twitter.com/onsen_musume_jp/status/865534101918330881")
|
||||
@site.get
|
||||
|
||||
@site = Sources::Strategies.find("https://twitter.com/onsen_musume_jp/status/865534101918330881")
|
||||
assert_equal(["https://pbs.twimg.com/media/DAL-ntWV0AEbhes.jpg:orig"], @site.image_urls)
|
||||
end
|
||||
|
||||
should "extract all the image urls" do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://twitter.com/aoimanabu/status/892370963630743552")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://twitter.com/aoimanabu/status/892370963630743552")
|
||||
|
||||
urls = %w[
|
||||
https://pbs.twimg.com/media/DGJWp59UIAA_-en.jpg:orig
|
||||
@@ -85,12 +22,72 @@ module Sources
|
||||
assert_equal(urls, @site.image_urls)
|
||||
end
|
||||
end
|
||||
|
||||
context "A video" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Strategies.find("https://twitter.com/CincinnatiZoo/status/859073537713328129")
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal("https://video.twimg.com/ext_tw_video/859073467769126913/pu/vid/1280x720/cPGgVROXHy3yrK6u.mp4", @site.image_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "An animated gif" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Strategies.find("https://twitter.com/DaniStrawberry1/status/859435334765088769")
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal("https://video.twimg.com/tweet_video/C-1Tns7WsAAqvqn.mp4", @site.image_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "A twitter summary card" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Strategies.find("https://twitter.com/NatGeo/status/932700115936178177")
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal("https://pmdvod.nationalgeographic.com/NG_Video/205/302/smpost_1510342850295.jpg", @site.image_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "A twitter summary card from twitter" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Strategies.find("https://twitter.com/masayasuf/status/870734961778630656/photo/1")
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
skip "Find another url, the masayasuf tweet no longer exists"
|
||||
assert_equal("https://pbs.twimg.com/media/DBV40M2UIAAHYlt.jpg:orig", @site.image_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "A twitter summary card from twitter with a :large image" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Strategies.find("https://twitter.com/aranobu/status/817736083567820800")
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal("https://pbs.twimg.com/media/C1kt72yVEAEGpOv.jpg:orig", @site.image_url)
|
||||
end
|
||||
|
||||
should "get the canonical url" do
|
||||
assert_equal("https://twitter.com/aranobu/status/817736083567820800", @site.canonical_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "The source site for a restricted twitter" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://mobile.twitter.com/Strangestone/status/556440271961858051")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://mobile.twitter.com/Strangestone/status/556440271961858051")
|
||||
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
@@ -101,8 +98,7 @@ module Sources
|
||||
context "The source site for twitter" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://mobile.twitter.com/nounproject/status/540944400767922176")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://mobile.twitter.com/nounproject/status/540944400767922176")
|
||||
end
|
||||
|
||||
should "get the profile" do
|
||||
@@ -135,8 +131,7 @@ module Sources
|
||||
context "The source site for a direct image and a referer" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:large", referer_url: "https://twitter.com/nounproject/status/540944400767922176")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:large", "https://twitter.com/nounproject/status/540944400767922176")
|
||||
end
|
||||
|
||||
should "get the artist name" do
|
||||
@@ -151,8 +146,7 @@ module Sources
|
||||
context "The source site for a https://twitter.com/i/web/status/:id url" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://twitter.com/i/web/status/943446161586733056")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://twitter.com/i/web/status/943446161586733056")
|
||||
end
|
||||
|
||||
should "fetch the source data" do
|
||||
@@ -163,8 +157,7 @@ module Sources
|
||||
context "A tweet" do
|
||||
setup do
|
||||
skip "Twitter key is not set" unless Danbooru.config.twitter_api_key
|
||||
@site = Sources::Site.new("https://twitter.com/noizave/status/875768175136317440")
|
||||
@site.get
|
||||
@site = Sources::Strategies.find("https://twitter.com/noizave/status/875768175136317440")
|
||||
end
|
||||
|
||||
should "convert urls, hashtags, and mentions to dtext" do
|
||||
|
||||
@@ -17,6 +17,7 @@ class TagAliasCorrectionTest < ActiveSupport::TestCase
|
||||
|
||||
context "with a bad cache and post counts" do
|
||||
setup do
|
||||
Cache.delete("ta:#{Cache.hash('bbb')}")
|
||||
Cache.put("ta:#{Cache.hash('aaa')}", "zzz")
|
||||
Tag.where(:name => "aaa").update_all("post_count = -3")
|
||||
@correction = TagAliasCorrection.new(@tag_alias.id)
|
||||
|
||||
Reference in New Issue
Block a user