sources: add image_url?, page_url?, and profile_url? methods.

Add methods to Source::URL for determining whether a URL is an image
URL, a page URL, or a profile URL.

Also add more source URL tests and fix various URL parsing bugs.
This commit is contained in:
evazion
2022-05-01 17:55:58 -05:00
parent d54ad9103b
commit 23b8350320
47 changed files with 571 additions and 165 deletions

View File

@@ -47,5 +47,12 @@ module Sources
context "A deleted or non-existing anifty post" do
strategy_should_work("https://anifty.jp/zh/creations/373123123", deleted: true, profile_url: nil)
end
should "Parse Anifty URLs correctly" do
assert(Source::URL.image_url?("https://anifty.imgix.net/creation/0x961d09077b4a9f7a27f6b7ee78cb4c26f0e72c18/20d5ce5b5163a71258e1d0ee152a0347bf40c7da.png?w=660&h=660&fit=crop&crop=focalpoint&fp-x=0.76&fp-y=0.5&fp-z=1&auto=compress"))
assert(Source::URL.image_url?("https://storage.googleapis.com/anifty-media/creation/0x961d09077b4a9f7a27f6b7ee78cb4c26f0e72c18/20d5ce5b5163a71258e1d0ee152a0347bf40c7da.png"))
assert(Source::URL.page_url?("https://anifty.jp/creations/373"))
assert(Source::URL.profile_url?("https://anifty.jp/@hightree"))
end
end
end

View File

@@ -192,14 +192,24 @@ module Sources
assert_equal("sa-dui", site.artist_name)
end
context "generating page urls" do
should "work" do
assert_equal("https://www.artstation.com/artwork/ghost-in-the-shell-fandom", Source::URL.page_url("https://www.artstation.com/artwork/ghost-in-the-shell-fandom"))
assert_equal("https://www.artstation.com/artwork/qPVGP", Source::URL.page_url("https://anubis1982918.artstation.com/projects/qPVGP/"))
assert_equal("https://www.artstation.com/artwork/NoNmD", Source::URL.page_url("https://dudeunderscore.artstation.com/projects/NoNmD?album_id=23041"))
assert_nil(Source::URL.page_url("http://cdna.artstation.com/p/assets/images/images/005/804/224/large/titapa-khemakavat-sa-dui-srevere.jpg?1493887236"))
assert_nil(Source::URL.page_url("https://www.artstation.com"))
end
should "Parse ArtStation URLs correctly" do
assert_equal("https://www.artstation.com/artwork/ghost-in-the-shell-fandom", Source::URL.page_url("https://www.artstation.com/artwork/ghost-in-the-shell-fandom"))
assert_equal("https://www.artstation.com/artwork/qPVGP", Source::URL.page_url("https://anubis1982918.artstation.com/projects/qPVGP/"))
assert_equal("https://www.artstation.com/artwork/NoNmD", Source::URL.page_url("https://dudeunderscore.artstation.com/projects/NoNmD?album_id=23041"))
assert(Source::URL.page_url?("https://www.artstation.com/artwork/ghost-in-the-shell-fandom"))
assert(Source::URL.page_url?("https://artstation.com/artwork/04XA4"))
assert(Source::URL.image_url?("http://cdna.artstation.com/p/assets/images/images/005/804/224/large/titapa-khemakavat-sa-dui-srevere.jpg?1493887236"))
assert(Source::URL.image_url?("https://cdn-animation.artstation.com/p/video_sources/000/466/622/workout.mp4"))
assert(Source::URL.profile_url?("https://www.artstation.com/sa-dui"))
assert(Source::URL.profile_url?("https://artstation.com/artist/sa-dui"))
assert(Source::URL.profile_url?("https://anubis1982918.artstation.com"))
refute(Source::URL.profile_url?("https://anubis1982918.artstation.com/projects/qPVGP"))
refute(Source::URL.profile_url?("https://www.artstation.com"))
refute(Source::URL.profile_url?("https://artstation.com"))
end
end
end

View File

@@ -68,5 +68,18 @@ module Sources
context "A non-existing or deleted post" do
strategy_should_work("https://booth.pm/en/items/2003079", deleted: true)
end
should "Parse Booth URLs correctly" do
assert(Source::URL.image_url?("https://booth.pximg.net/8bb9e4e3-d171-4027-88df-84480480f79d/i/2864768/00cdfef0-e8d5-454b-8554-4885a7e4827d_base_resized.jpg"))
assert(Source::URL.image_url?("https://s2.booth.pm/b242a7bd-0747-48c4-891d-9e8552edd5d7/i/3746752/52dbee27-7ad2-4048-9c1d-827eee36625c_base_resized.jpg"))
assert(Source::URL.image_url?("https://s.booth.pm/1c9bc77f-8ac1-4fa4-94e5-839772ab72cb/i/750997/774dc881-ce6e-45c6-871b-f6c3ca6914d5.png"))
assert(Source::URL.image_url?("https://booth.pximg.net/users/3193929/icon_image/5be9eff4-1d9e-4a79-b097-33c1cd4ad314.png"))
assert(Source::URL.image_url?("https://s2.booth.pm/8bb9e4e3-d171-4027-88df-84480480f79d/3d70de06-8e7c-444e-b8eb-a8a95bf20638.png"))
assert(Source::URL.page_url?("https://booth.pm/en/items/2864768"))
assert(Source::URL.page_url?("https://re-face.booth.pm/items/3435711"))
assert(Source::URL.profile_url?("https://re-face.booth.pm"))
refute(Source::URL.profile_url?("https://www.booth.pm"))
refute(Source::URL.profile_url?("https://booth.pm"))
end
end
end

View File

@@ -365,28 +365,35 @@ module Sources
end
end
context "generating page urls " do
should "work" do
source1 = "http://fc06.deviantart.net/fs71/f/2013/295/d/7/you_are_already_dead__by_mar11co-d6rgm0e.jpg"
source2 = "https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/8b472d70-a0d6-41b5-9a66-c35687090acc/d23jbr4-8a06af02-70cb-46da-8a96-42a6ba73cdb4.jpg/v1/fill/w_786,h_1017,q_70,strp/silverhawks_quicksilver_by_edsfox_d23jbr4-pre.jpg"
source3 = "http://orig12.deviantart.net/9b69/f/2017/023/7/c/illustration___tokyo_encount_oei__by_melisaongmiqin-dawi58s.png"
source4 = "http://fc00.deviantart.net/fs71/f/2013/337/3/5/35081351f62b432f84eaeddeb4693caf-d6wlrqs.jpg"
source5 = "https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/76098ac8-04ab-4784-b382-88ca082ba9b1/d9x7lmk-595099de-fe8f-48e5-9841-7254f9b2ab8d.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOiIsImlzcyI6InVybjphcHA6Iiwib2JqIjpbW3sicGF0aCI6IlwvZlwvNzYwOThhYzgtMDRhYi00Nzg0LWIzODItODhjYTA4MmJhOWIxXC9kOXg3bG1rLTU5NTA5OWRlLWZlOGYtNDhlNS05ODQxLTcyNTRmOWIyYWI4ZC5wbmcifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6ZmlsZS5kb3dubG9hZCJdfQ.KFOVXAiF8MTlLb3oM-FlD0nnDvODmjqEhFYN5I2X5Bc"
source6 = "https://fav.me/dbc3a48"
should "Parse DeviantArt URLs correctly" do
source1 = "http://fc06.deviantart.net/fs71/f/2013/295/d/7/you_are_already_dead__by_mar11co-d6rgm0e.jpg"
source2 = "https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/8b472d70-a0d6-41b5-9a66-c35687090acc/d23jbr4-8a06af02-70cb-46da-8a96-42a6ba73cdb4.jpg/v1/fill/w_786,h_1017,q_70,strp/silverhawks_quicksilver_by_edsfox_d23jbr4-pre.jpg"
source3 = "http://orig12.deviantart.net/9b69/f/2017/023/7/c/illustration___tokyo_encount_oei__by_melisaongmiqin-dawi58s.png"
source4 = "http://fc00.deviantart.net/fs71/f/2013/337/3/5/35081351f62b432f84eaeddeb4693caf-d6wlrqs.jpg"
source5 = "https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/76098ac8-04ab-4784-b382-88ca082ba9b1/d9x7lmk-595099de-fe8f-48e5-9841-7254f9b2ab8d.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOiIsImlzcyI6InVybjphcHA6Iiwib2JqIjpbW3sicGF0aCI6IlwvZlwvNzYwOThhYzgtMDRhYi00Nzg0LWIzODItODhjYTA4MmJhOWIxXC9kOXg3bG1rLTU5NTA5OWRlLWZlOGYtNDhlNS05ODQxLTcyNTRmOWIyYWI4ZC5wbmcifV1dLCJhdWQiOlsidXJuOnNlcnZpY2U6ZmlsZS5kb3dubG9hZCJdfQ.KFOVXAiF8MTlLb3oM-FlD0nnDvODmjqEhFYN5I2X5Bc"
source6 = "https://fav.me/dbc3a48"
assert_equal("https://www.deviantart.com/mar11co/art/You-Are-Already-Dead-408921710", Source::URL.page_url(source1))
assert_equal("https://www.deviantart.com/edsfox/art/Silverhawks-Quicksilver-126872896", Source::URL.page_url(source2))
assert_equal("https://www.deviantart.com/melisaongmiqin/art/Illustration-Tokyo-Encount-Oei-659256076", Source::URL.page_url(source3))
assert_equal("https://www.deviantart.com/deviation/417560500", Source::URL.page_url(source4))
assert_equal("https://www.deviantart.com/deviation/599977532", Source::URL.page_url(source5))
assert_equal("https://www.deviantart.com/deviation/685436408", Source::URL.page_url(source6))
end
assert(Source::URL.image_url?(source1))
assert(Source::URL.image_url?(source2))
assert(Source::URL.image_url?(source3))
assert(Source::URL.image_url?(source4))
assert(Source::URL.image_url?(source5))
assert(Source::URL.page_url?(source6))
should "handle inconvertible urls" do
assert_nil(Source::URL.page_url("http://fc08.deviantart.net/images3/i/2004/088/8/f/Blackrose_for_MuzicFreq.jpg"))
assert_nil(Source::URL.page_url("http://prnt00.deviantart.net/9b74/b/2016/101/4/468a9d89f52a835d4f6f1c8caca0dfb2-pnjfbh.jpg"))
assert_nil(Source::URL.page_url("https://deviantart.net"))
end
assert_equal("https://www.deviantart.com/mar11co/art/You-Are-Already-Dead-408921710", Source::URL.page_url(source1))
assert_equal("https://www.deviantart.com/edsfox/art/Silverhawks-Quicksilver-126872896", Source::URL.page_url(source2))
assert_equal("https://www.deviantart.com/melisaongmiqin/art/Illustration-Tokyo-Encount-Oei-659256076", Source::URL.page_url(source3))
assert_equal("https://www.deviantart.com/deviation/417560500", Source::URL.page_url(source4))
assert_equal("https://www.deviantart.com/deviation/599977532", Source::URL.page_url(source5))
assert_equal("https://www.deviantart.com/deviation/685436408", Source::URL.page_url(source6))
assert(Source::URL.image_url?("http://www.deviantart.com/download/135944599/Touhou___Suwako_Moriya_Colored_by_Turtle_Chibi.png"))
assert(Source::URL.image_url?("http://fc08.deviantart.net/images3/i/2004/088/8/f/Blackrose_for_MuzicFreq.jpg"))
assert(Source::URL.image_url?("http://prnt00.deviantart.net/9b74/b/2016/101/4/468a9d89f52a835d4f6f1c8caca0dfb2-pnjfbh.jpg"))
assert(Source::URL.page_url?("https://sta.sh/0wxs31o7nn2"))
assert(Source::URL.profile_url?("https://www.deviantart.com/noizave"))
assert(Source::URL.profile_url?("https://noizave.deviantart.com"))
refute(Source::URL.profile_url?("https://deviantart.net"))
end
end
end

View File

@@ -144,16 +144,22 @@ module Sources
end
end
context "generating page urls" do
should "convert cover images to the profile url" do
cover = "https://pixiv.pximg.net/c/400x400_90_a2_g5/fanbox/public/images/creator/1566167/profile/Ix6bnJmTaOAFZhXHLbWyIY1e.jpeg"
assert_equal("https://www.pixiv.net/fanbox/creator/1566167", Source::URL.page_url(cover))
end
should "Parse Fanbox URLs correctly" do
assert_equal("https://www.pixiv.net/fanbox/creator/1566167", Source::URL.page_url("https://pixiv.pximg.net/c/400x400_90_a2_g5/fanbox/public/images/creator/1566167/profile/Ix6bnJmTaOAFZhXHLbWyIY1e.jpeg"))
should "handle inconvertible urls" do
assert_nil(Source::URL.page_url("https://pixiv.pximg.net/c/936x600_90_a2_g5/fanbox/public/images/plan/4635/cover/L6AZNneFuHW6r25CHHlkpHg4.jpeg"))
assert_nil(Source::URL.page_url("https://downloads.fanbox.cc/images/post/39714/JvjJal8v1yLgc5DPyEI05YpT.png"))
end
assert(Source::URL.image_url?("https://pixiv.pximg.net/c/936x600_90_a2_g5/fanbox/public/images/plan/4635/cover/L6AZNneFuHW6r25CHHlkpHg4.jpeg"))
assert(Source::URL.image_url?("https://pixiv.pximg.net/c/400x400_90_a2_g5/fanbox/public/images/creator/1566167/profile/Ix6bnJmTaOAFZhXHLbWyIY1e.jpeg"))
assert(Source::URL.image_url?("https://downloads.fanbox.cc/images/post/39714/JvjJal8v1yLgc5DPyEI05YpT.png"))
assert(Source::URL.page_url?("https://www.fanbox.cc/@tsukiori/posts/1080657"))
assert(Source::URL.page_url?("https://www.pixiv.net/fanbox/creator/1566167/post/39714"))
assert(Source::URL.page_url?("https://omu001.fanbox.cc/posts/39714"))
assert(Source::URL.profile_url?("https://www.pixiv.net/fanbox/creator/1566167"))
assert(Source::URL.profile_url?("https://www.pixiv.net/fanbox/member.php?user_id=3410642"))
assert(Source::URL.profile_url?("https://omu001.fanbox.cc"))
refute(Source::URL.profile_url?("https://www.fanbox.cc"))
refute(Source::URL.profile_url?("https://fanbox.cc"))
end
end
end

View File

@@ -157,5 +157,20 @@ module Sources
assert_nothing_raised { source2.to_h }
end
end
should "Parse Fantia URLs correctly" do
assert(Source::URL.image_url?("https://c.fantia.jp/uploads/post/file/1070093/16faf0b1-58d8-4aac-9e86-b243063eaaf1.jpeg"))
assert(Source::URL.image_url?("https://c.fantia.jp/uploads/product/image/249638/main_fd5aef8f-c217-49d0-83e8-289efb33dfc4.jpg"))
assert(Source::URL.image_url?("https://c.fantia.jp/uploads/product_image/file/219407/bd7419c2-2450-4c53-a28a-90101fa466ab.jpg"))
assert(Source::URL.image_url?("https://cc.fantia.jp/uploads/post_content_photo/file/4563389/main_a9763427-3ccd-4e51-bcde-ff5e1ce0aa56.jpg?Key-Pair-Id=APKAIOCKYZS7WKBB6G7A&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9jYy5mYW50aWEuanAvdXBsb2Fkcy9wb3N0X2NvbnRlbnRfcGhvdG8vZmlsZS80NTYzMzg5L21haW5fYTk3NjM0MjctM2NjZC00ZTUxLWJjZGUtZmY1ZTFjZTBhYTU2LmpwZyIsIkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTY0NjkxMzk3OH19fV19&Signature=jyW5ankfO9uCHlKkozYU9RPpO3jzKTW2HuyXgS81i~cRgrXcI9orYU0IXuiit~0TznIyXbB7F~6Z790t7lX948PYAb9luYIREJC2u7pRMP3OBbsANbbFE0o4VR-6O3ZKbYQ4aG~ofVEZfiFVGoKoVtdJxj0bBNQV29eeFylGQATkFmywne1YMtJMqDirRBFMIatqNuunGsiWCQHqLYNHCeS4dZXlOnV8JQq0u1rPkeAQBmDCStFMA5ywjnWTfSZK7RN6RXKCAsMTXTl5X~I6EZASUPoGQy2vHUj5I-veffACg46jpvqTv6mLjQEw8JG~JLIOrZazKZR9O2kIoLNVGQ__"))
assert(Source::URL.image_url?("https://cc.fantia.jp/uploads/post_content/file/1830956/cbcdfcbe_20220224_120_040_100.png?Key-Pair-Id=APKAIOCKYZS7WKBB6G7A&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9jYy5mYW50aWEuanAvdXBsb2Fkcy9wb3N0X2NvbnRlbnQvZmlsZS8xODMwOTU2L2NiY2RmY2JlXzIwMjIwMjI0XzEyMF8wNDBfMTAwLnBuZyIsIkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTY0NjkxNDU4Nn19fV19&Signature=d1nw8gs9vcshIAeEH4oESm9-7z6y4A7MfoIRRvtUtV9iqTNA8KM0ORuCI7NwEoYc1VHsxy9ByeuSBpNaJoknnc3TOmHFhVRcLn~OWpnWqiHEPpMcSEG7uGlorysjEPmYYRGHjE7LJYcWiiJxjZ~fSBbYzxxwsjroPm-fyGUtNhdJWEMNp52vHe5P9KErb7M8tP01toekGdOqO-pkWm1t9xm2Tp5P7RWcbtQPOixgG4UgOhE0f3LVwHGHYJV~-lB5RjrDbTTO3ezVi7I7ybZjjHotVUK5MbHHmXzC1NqI-VN3vHddTwTbTK9xEnPMR27NHSlho3-O18WcNs1YgKD48w__"))
assert(Source::URL.image_url?("https://fantia.jp/posts/1143951/download/1830956"))
assert(Source::URL.page_url?("https://fantia.jp/posts/1148334"))
assert(Source::URL.page_url?("https://fantia.jp/products/249638"))
assert(Source::URL.profile_url?("https://fantia.jp/fanclubs/64496"))
assert(Source::URL.profile_url?("https://fantia.jp/asanagi"))
end
end
end

View File

@@ -0,0 +1,25 @@
require 'test_helper'
module Sources
class Fc2Test < ActiveSupport::TestCase
context "FC2:" do
should "Parse FC2 URLs correctly" do
assert(Source::URL.image_url?("http://onidocoro.blog14.fc2.com/file/20071003061150.png"))
assert(Source::URL.image_url?("http://blog23.fc2.com/m/mosha2/file/uru.jpg"))
assert(Source::URL.image_url?("http://blog.fc2.com/g/genshi/file/20070612a.jpg"))
assert(Source::URL.image_url?("http://blog-imgs-63-origin.fc2.com/y/u/u/yuukyuukikansya/140817hijiri02.jpg"))
assert(Source::URL.image_url?("http://blog-imgs-61.fc2.com/o/m/o/omochi6262/20130402080220583.jpg"))
assert(Source::URL.image_url?("http://blog.fc2.com/g/b/o/gbot/20071023195141.jpg"))
assert(Source::URL.image_url?("http://diary.fc2.com/user/yuuri/img/2005_12/26.jpg"))
assert(Source::URL.profile_url?("http://silencexs.blog.fc2.com"))
assert(Source::URL.profile_url?("http://794ancientkyoto.web.fc2.com"))
assert(Source::URL.profile_url?("http://yorokobi.x.fc2.com"))
assert(Source::URL.profile_url?("https://lilish28.bbs.fc2.com"))
assert(Source::URL.profile_url?("http://jpmaid.h.fc2.com"))
assert(Source::URL.profile_url?("http://swordsouls.blog131.fc2blog.net"))
assert(Source::URL.profile_url?("http://swordsouls.blog131.fc2blog.us"))
end
end
end
end

View File

@@ -125,5 +125,20 @@ module Sources
EOS
end
should "parse Foundation URLs correctly" do
assert(Source::URL.image_url?("https://f8n-ipfs-production.imgix.net/QmX4MotNAAj9Rcyew43KdgGDxU1QtXemMHoUTNacMLLSjQ/nft.png"))
assert(Source::URL.image_url?("https://f8n-production-collection-assets.imgix.net/0x3B3ee1931Dc30C1957379FAc9aba94D1C48a5405/128711/QmcBfbeCMSxqYB3L1owPAxFencFx3jLzCPFx6xUBxgSCkH/nft.png"))
assert(Source::URL.image_url?("https://f8n-production-collection-assets.imgix.net/0xFb0a8e1bB97fD7231Cd73c489dA4732Ae87995F0/4/nft.png"))
assert(Source::URL.image_url?("https://assets.foundation.app/0x21Afa9aB02B6Fb7cb483ff3667c39eCdd6D9Ea73/4/nft.mp4"))
assert(Source::URL.image_url?("https://assets.foundation.app/7i/gs/QmU8bbsjaVQpEKMDWbSZdDD6GsPmRYBhQtYRn8bEGv7igs/nft_q4.mp4"))
assert(Source::URL.image_url?("https://d2ybmb80bbm9ts.cloudfront.net/zd/BD/QmXiCEoBLcpfvpEwAEanLXe3Tjr5ykYJFzCVfpzDDQzdBD/nft_q4.mp4"))
assert(Source::URL.page_url?("https://foundation.app/@asuka111art/dinner-with-cats-82426"))
assert(Source::URL.page_url?("https://foundation.app/@mochiiimo/~/97376"))
assert(Source::URL.profile_url?("https://foundation.app/@mochiiimo"))
assert(Source::URL.profile_url?("https://foundation.app/0x7E2ef75C0C09b2fc6BCd1C68B6D409720CcD58d2"))
end
end
end

View File

@@ -41,5 +41,14 @@ module Sources
context "A deleted or non-existing furaffinity post" do
strategy_should_work("https://www.furaffinity.net/view/3404111", deleted: true, profile_url: nil)
end
should "Parse Furaffinity URLs correctly" do
assert(Source::URL.image_url?("https://d.furaffinity.net/art/iwbitu/1650222955/1650222955.iwbitu_yubi.jpg"))
assert(Source::URL.page_url?("https://www.furaffinity.net/view/46821705/"))
assert(Source::URL.page_url?("https://www.furaffinity.net/full/46821705/"))
assert(Source::URL.profile_url?("https://www.furaffinity.net/user/iwbitu"))
assert(Source::URL.profile_url?("https://www.furaffinity.net/gallery/iwbitu"))
assert(Source::URL.profile_url?("https://www.furaffinity.net/gallery/iwbitu/folder/133763/Regular-commissions"))
end
end
end

View File

@@ -96,5 +96,19 @@ module Sources
assert_nothing_raised { @source.to_h }
end
end
should "Parse HentaiFoundry URLs correctly" do
assert(Source::URL.image_url?("https://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png"))
assert(Source::URL.image_url?("http://pictures.hentai-foundry.com//s/soranamae/363663.jpg"))
assert(Source::URL.image_url?("http://www.hentai-foundry.com/piccies/d/dmitrys/1183.jpg"))
assert(Source::URL.image_url?("https://thumbs.hentai-foundry.com/thumb.php?pid=795025&size=350"))
assert(Source::URL.page_url?("https://www.hentai-foundry.com/pictures/user/Afrobull/795025"))
assert(Source::URL.page_url?("http://www.hentai-foundry.com/pic-795025"))
assert(Source::URL.profile_url?("https://www.hentai-foundry.com/user/kajinman"))
assert(Source::URL.profile_url?("https://www.hentai-foundry.com/pictures/user/kajinman"))
assert(Source::URL.profile_url?("http://www.hentai-foundry.com/profile-sawao.php"))
end
end
end

View File

@@ -0,0 +1,19 @@
require 'test_helper'
module Sources
class Instagram < ActiveSupport::TestCase
context "Instagram:" do
should "Parse Instagram URLs correctly" do
assert(Source::URL.image_url?("https://scontent-lga3-1.cdninstagram.com/v/t51.2885-15/sh0.08/e35/s640x640/202831473_394388808595845_6890631933098833028_n.jpg?_nc_ht=scontent-lga3-1.cdninstagram.com&_nc_cat=109&_nc_ohc=Fcle68OyC80AX8VTGxs&edm=AABBvjUBAAAA&ccb=7-4&oh=00_AT_DYX0zhyNR9vo6ZFKfXjzEWqwFLLfEd3qcpAds5KIvnA&oe=6216DDB5&_nc_sid=83d603"))
assert(Source::URL.image_url?("https://instagram.fgyn2-1.fna.fbcdn.net/v/t51.2885-15/260126945_125485689990401_3753783352853967169_n.webp?stp=dst-jpg_e35_s750x750_sh0.08&_nc_ht=instagram.fgyn2-1.fna.fbcdn.net&_nc_cat=105&_nc_ohc=7njl7WM7D1cAX_oe4xv&tn=ZvUMUWKqovKgvpX-&edm=AABBvjUBAAAA&ccb=7-4&ig_cache_key=Mjc2NTM3ODUzMDE2MTA4OTMyNw==.2-ccb7-4&oh=00_AT9T3WAiFaHEf1labFFZiXHjy-8nacOA13AWl6hDEPz_EQ&oe=6230B686&_nc_sid=83d603"))
assert(Source::URL.page_url?("https://www.instagram.com/p/CbDW9mVuEnn/"))
assert(Source::URL.page_url?("https://www.instagram.com/reel/CV7mHEwgbeF/?utm_medium=copy_link"))
assert(Source::URL.page_url?("https://www.instagram.com/tv/CMjUD1epVWW/"))
assert(Source::URL.profile_url?("https://www.instagram.com/itomugi/"))
assert(Source::URL.profile_url?("https://www.instagram.com/stories/itomugi/"))
end
end
end
end

View File

@@ -68,5 +68,17 @@ module Sources
assert_nothing_raised { source.to_h }
end
end
should "Parse Lofter URLs correctly" do
assert(Source::URL.image_url?("https://imglf3.lf127.net/img/S1d2QlVsWkJhSW1qcnpIS0ZSa3ZJSzFCWFlnUWgzb01DcUdpT1lreG5yQjJVMkhGS09HNGR3PT0.png?imageView&thumbnail=1680x0&quality=96&stripmeta=0"))
assert(Source::URL.image_url?("http://imglf0.nosdn.127.net/img/cHl3bXNZdDRaaHBnNWJuN1Y4OXBqR01CeVBZSVNmU2FWZWtHc1h4ZTZiUGxlRzMwZnFDM1JnPT0.jpg "))
assert(Source::URL.page_url?("https://gengar563.lofter.com/post/1e82da8c_1c98dae1b"))
assert(Source::URL.profile_url?("https://www.lofter.com/front/blog/home-page/noshiqian"))
assert(Source::URL.profile_url?("http://www.lofter.com/app/xiaokonggedmx"))
assert(Source::URL.profile_url?("http://www.lofter.com/blog/semblance"))
assert(Source::URL.profile_url?("http://gengar563.lofter.com"))
end
end
end

View File

@@ -152,5 +152,27 @@ module Sources
assert_equal([@artist], @site1.artists)
end
end
should "Parse Pawoo URLs correctly" do
assert(Source::URL.image_url?("https://img.pawoo.net/media_attachments/files/001/297/997/small/c4272a09570757c2.png"))
assert(Source::URL.image_url?("https://pawoo.net/media/lU2uV7C1MMQSb1czwvg"))
assert(Source::URL.page_url?("https://pawoo.net/@evazion/19451018"))
assert(Source::URL.page_url?("https://pawoo.net/web/statuses/19451018"))
assert(Source::URL.profile_url?("https://pawoo.net/@evazion"))
assert(Source::URL.profile_url?("https://pawoo.net/users/esoraneko"))
assert(Source::URL.profile_url?("https://pawoo.net/web/accounts/47806"))
end
should "Parse Baraag URLs correctly" do
assert(Source::URL.image_url?("https://baraag.net/system/media_attachments/files/107/866/084/749/942/932/original/a9e0f553e332f303.mp4"))
assert(Source::URL.page_url?("https://baraag.net/@curator/102270656480174153"))
assert(Source::URL.page_url?("https://baraag.net/web/statuses/102270656480174153"))
assert(Source::URL.profile_url?("https://baraag.net/@danbooru"))
assert(Source::URL.profile_url?("https://baraag.net/web/accounts/107862785324786980"))
end
end
end

View File

@@ -110,30 +110,32 @@ module Sources
end
end
context "generating page urls" do
should "generate yande.re urls correctly" do
source1 = "https://files.yande.re/image/b66909b940e8d77accab7c9b25aa4dc3/yande.re%20377828.png"
source2 = "https://files.yande.re/image/2a5d1d688f565cb08a69ecf4e35017ab/yande.re%20349790%20breast_hold%20kurashima_tomoyasu%20mahouka_koukou_no_rettousei%20naked%20nipples.jpg"
source3 = "https://files.yande.re/image/e4c2ba38de88ff1640aaebff84c84e81/469784.jpg"
source4 = "https://yande.re/image/b4b1d11facd1700544554e4805d47bb6/.png"
source5 = "https://yande.re/jpeg/22577d2344fe694cf47f80563031b3cd.jpg"
should "Parse yande.re URLs correctly" do
assert_equal("https://yande.re/post/show/377828", Source::URL.page_url("https://files.yande.re/image/b66909b940e8d77accab7c9b25aa4dc3/yande.re%20377828.png"))
assert_equal("https://yande.re/post/show/349790", Source::URL.page_url("https://files.yande.re/image/2a5d1d688f565cb08a69ecf4e35017ab/yande.re%20349790%20breast_hold%20kurashima_tomoyasu%20mahouka_koukou_no_rettousei%20naked%20nipples.jpg"))
assert_equal("https://yande.re/post/show/469784", Source::URL.page_url("https://files.yande.re/image/e4c2ba38de88ff1640aaebff84c84e81/469784.jpg"))
assert_equal("https://yande.re/post/show?md5=b4b1d11facd1700544554e4805d47bb6", Source::URL.page_url("https://yande.re/image/b4b1d11facd1700544554e4805d47bb6/.png"))
assert_equal("https://yande.re/post/show?md5=22577d2344fe694cf47f80563031b3cd", Source::URL.page_url("https://yande.re/jpeg/22577d2344fe694cf47f80563031b3cd.jpg"))
assert_equal("https://yande.re/post/show/377828", Source::URL.page_url(source1))
assert_equal("https://yande.re/post/show/349790", Source::URL.page_url(source2))
assert_equal("https://yande.re/post/show/469784", Source::URL.page_url(source3))
assert_equal("https://yande.re/post/show?md5=b4b1d11facd1700544554e4805d47bb6", Source::URL.page_url(source4))
assert_equal("https://yande.re/post/show?md5=22577d2344fe694cf47f80563031b3cd", Source::URL.page_url(source5))
end
assert(Source::URL.image_url?("https://yande.re/sample/ceb6a12e87945413a95b90fada406f91/.jpg"))
assert(Source::URL.image_url?("https://yande.re/jpeg/22577d2344fe694cf47f80563031b3cd.jpg"))
assert(Source::URL.image_url?("https://assets.yande.re/data/preview/7e/cf/7ecfdead705d7b956b26b1d37b98d089.jpg"))
assert(Source::URL.image_url?("https://ayase.yande.re/image/2d0d229fd8465a325ee7686fcc7f75d2/yande.re%20192481%20animal_ears%20bunny_ears%20garter_belt%20headphones%20mitha%20stockings%20thighhighs.jpg"))
assert(Source::URL.image_url?("https://yuno.yande.re/image/1764b95ae99e1562854791c232e3444b/yande.re%20281544%20cameltoe%20erect_nipples%20fundoshi%20horns%20loli%20miyama-zero%20sarashi%20sling_bikini%20swimsuits.jpg"))
should "generate konachan.com urls correctly" do
source1 = "https://konachan.com/image/5d633771614e4bf5c17df19a0f0f333f/Konachan.com%20-%20270807%20black_hair%20bokuden%20clouds%20grass%20landscape%20long_hair%20original%20phone%20rope%20scenic%20seifuku%20skirt%20sky%20summer%20torii%20tree.jpg"
source2 = "https://konachan.com/sample/e2e2994bae738ff52fff7f4f50b069d5/Konachan.com%20-%20270803%20sample.jpg"
source3 = "https://konachan.com/image/99a3c4f10c327d54486259a74173fc0b.jpg"
assert(Source::URL.page_url?("https://yande.re/post/show/3"))
end
assert_equal("https://konachan.com/post/show/270807", Source::URL.page_url(source1))
assert_equal("https://konachan.com/post/show/270803", Source::URL.page_url(source2))
assert_equal("https://konachan.com/post/show?md5=99a3c4f10c327d54486259a74173fc0b", Source::URL.page_url(source3))
end
should "Parse konachan.com URLs correctly" do
assert_equal("https://konachan.com/post/show/270807", Source::URL.page_url("https://konachan.com/image/5d633771614e4bf5c17df19a0f0f333f/Konachan.com%20-%20270807%20black_hair%20bokuden%20clouds%20grass%20landscape%20long_hair%20original%20phone%20rope%20scenic%20seifuku%20skirt%20sky%20summer%20torii%20tree.jpg"))
assert_equal("https://konachan.com/post/show/270803", Source::URL.page_url("https://konachan.com/sample/e2e2994bae738ff52fff7f4f50b069d5/Konachan.com%20-%20270803%20sample.jpg"))
assert_equal("https://konachan.com/post/show?md5=99a3c4f10c327d54486259a74173fc0b", Source::URL.page_url("https://konachan.com/image/99a3c4f10c327d54486259a74173fc0b.jpg"))
assert(Source::URL.image_url?("https://konachan.com/data/preview/5d/63/5d633771614e4bf5c17df19a0f0f333f.jpg"))
assert(Source::URL.image_url?("https://konachan.com/sample/e2e2994bae738ff52fff7f4f50b069d5/Konachan.com%20-%20270803%20sample.jpg"))
assert(Source::URL.image_url?("https://konachan.com/jpeg/e2e2994bae738ff52fff7f4f50b069d5/Konachan.com%20-%20270803%20banishment%20bicycle%20grass%20group%20male%20night%20original%20rooftop%20scenic%20signed%20stars%20tree.jpg"))
assert(Source::URL.page_url?("https://konachan.com/post/show/270803/banishment-bicycle-grass-group-male-night-original"))
end
end
end

View File

@@ -122,11 +122,18 @@ module Sources
end
end
context "generating page urls" do
should "work" do
assert_equal("https://www.newgrounds.com/art/view/natthelich/fire-emblem-marth-plus-progress-pic", Source::URL.page_url("https://art.ngfiles.com/images/1033000/1033622_natthelich_fire-emblem-marth-plus-progress-pic.png?f1569487181"))
assert_nil(Source::URL.page_url("https://art.ngfiles.com/comments/57000/iu_57615_7115981.jpg"))
end
should "Parse Newgrounds URLs correctly" do
assert_equal("https://www.newgrounds.com/art/view/natthelich/fire-emblem-marth-plus-progress-pic", Source::URL.page_url("https://art.ngfiles.com/images/1033000/1033622_natthelich_fire-emblem-marth-plus-progress-pic.png?f1569487181"))
assert(Source::URL.image_url?("https://art.ngfiles.com/images/1254000/1254722_natthelich_pandora.jpg"))
assert(Source::URL.image_url?("https://art.ngfiles.com/comments/57000/iu_57615_7115981.jpg"))
assert(Source::URL.image_url?("https://art.ngfiles.com/thumbnails/1254000/1254985.png?f1588263349"))
assert(Source::URL.page_url?("https://www.newgrounds.com/art/view/puddbytes/costanza-at-bat"))
assert(Source::URL.profile_url?("https://natthelich.newgrounds.com"))
refute(Source::URL.profile_url?("https://www.newgrounds.com"))
refute(Source::URL.profile_url?("https://newgrounds.com"))
end
end
end

View File

@@ -184,19 +184,38 @@ module Sources
end
end
context "generating page urls" do
should "work" do
source1 = "http://lohas.nicoseiga.jp/priv/3521156?e=1382558156&h=f2e089256abd1d453a455ec8f317a6c703e2cedf"
source2 = "http://lohas.nicoseiga.jp/priv/b80f86c0d8591b217e7513a9e175e94e00f3c7a1/1384936074/3583893"
source3 = "http://lohas.nicoseiga.jp/o/910aecf08e542285862954017f8a33a8c32a8aec/1433298801/4937663"
source4 = "http://seiga.nicovideo.jp/image/source?id=3312222"
should "Parse NicoSeiga URLs correctly" do
assert_equal("https://seiga.nicovideo.jp/seiga/im4937663", Source::URL.page_url("http://lohas.nicoseiga.jp/o/910aecf08e542285862954017f8a33a8c32a8aec/1433298801/4937663"))
assert_nil(Source::URL.page_url(source1))
assert_nil(Source::URL.page_url(source2))
assert_equal("https://seiga.nicovideo.jp/seiga/im4937663", Source::URL.page_url(source3))
assert_nil(Source::URL.page_url(source4))
assert_nil(Source::URL.page_url("https://seiga.nicovideo.jp"))
end
assert(Source::URL.image_url?("http://lohas.nicoseiga.jp/priv/3521156?e=1382558156&h=f2e089256abd1d453a455ec8f317a6c703e2cedf"))
assert(Source::URL.image_url?("http://lohas.nicoseiga.jp/priv/b80f86c0d8591b217e7513a9e175e94e00f3c7a1/1384936074/3583893"))
assert(Source::URL.image_url?("https://lohas.nicoseiga.jp/o/971eb8af9bbcde5c2e51d5ef3a2f62d6d9ff5552/1589933964/3583893"))
assert(Source::URL.image_url?("http://seiga.nicovideo.jp/image/source?id=3312222"))
assert(Source::URL.image_url?("https://seiga.nicovideo.jp/image/source/3521156"))
assert(Source::URL.image_url?("https://seiga.nicovideo.jp/image/redirect?id=3583893"))
assert(Source::URL.image_url?("https://lohas.nicoseiga.jp/thumb/2163478i"))
assert(Source::URL.image_url?("https://lohas.nicoseiga.jp/thumb/4744553p"))
assert(Source::URL.image_url?("https://dcdn.cdn.nimg.jp/priv/62a56a7f67d3d3746ae5712db9cac7d465f4a339/1592186183/10466669"))
assert(Source::URL.image_url?("https://drm.cdn.nicomanga.jp/image/d4a2faa68ec34f95497db6601a4323fde2ccd451_9537/8017978p?1570012695"))
assert(Source::URL.page_url?("https://seiga.nicovideo.jp/seiga/im520647"))
assert(Source::URL.page_url?("https://sp.seiga.nicovideo.jp/seiga/im3521156"))
assert(Source::URL.page_url?("https://seiga.nicovideo.jp/watch/mg316708"))
assert(Source::URL.page_url?("https://nico.ms/im10922621"))
assert(Source::URL.page_url?("https://nico.ms/mg310193"))
assert(Source::URL.profile_url?("https://seiga.nicovideo.jp/user/illust/456831"))
assert(Source::URL.profile_url?("https://ext.seiga.nicovideo.jp/user/illust/20542122"))
assert(Source::URL.profile_url?("http://seiga.nicovideo.jp/manga/list?user_id=23839737"))
assert(Source::URL.profile_url?("https://www.nicovideo.jp/user/4572975"))
assert(Source::URL.profile_url?("https://commons.nicovideo.jp/user/696839"))
assert(Source::URL.profile_url?("https://q.nicovideo.jp/users/18700356"))
assert(Source::URL.profile_url?("https://dic.nicovideo.jp/u/11141663"))
assert(Source::URL.profile_url?("https://3d.nicovideo.jp/users/109584"))
assert(Source::URL.profile_url?("https://3d.nicovideo.jp/u/siobi"))
assert(Source::URL.profile_url?("http://game.nicovideo.jp/atsumaru/users/7757217"))
refute(Source::URL.profile_url?("https://seiga.nicovideo.jp"))
end
context "downloading a 'http://seiga.nicovideo.jp/seiga/:id' url" do

View File

@@ -314,31 +314,33 @@ module Sources
end
end
context "generating page urls" do
should "work" do
source1 = "https://pic01.nijie.info/nijie_picture/diff/main/218856_0_236014_20170620101329.png"
source2 = "https://pic04.nijie.info/nijie_picture/diff/main/287736_161475_20181112032855_1.png"
assert_equal("https://nijie.info/view.php?id=218856", Source::URL.page_url(source1))
assert_equal("https://nijie.info/view.php?id=287736", Source::URL.page_url(source2))
end
should "Parse Nijie URLs correctly" do
assert_equal("https://nijie.info/view.php?id=218856", Source::URL.page_url("https://pic01.nijie.info/nijie_picture/diff/main/218856_0_236014_20170620101329.png"))
assert_equal("https://nijie.info/view.php?id=287736", Source::URL.page_url("https://pic04.nijie.info/nijie_picture/diff/main/287736_161475_20181112032855_1.png"))
should "handle inconvertible urls" do
bad_source1 = "https://pic01.nijie.info/nijie_picture/20120211210359.jpg"
bad_source2 = "https://pic04.nijie.info/omata/4829_20161128012012.png"
bad_source3 = "https://pic03.nijie.info/nijie_picture/28310_20131101215959.jpg"
assert(Source::URL.image_url?("https://pic04.nijie.info/omata/4829_20161128012012.png"))
assert(Source::URL.image_url?("https://pic01.nijie.info/nijie_picture/20120211210359.jpg"))
assert(Source::URL.image_url?("https://pic03.nijie.info/nijie_picture/28310_20131101215959.jpg"))
assert(Source::URL.image_url?("https://pic01.nijie.info/nijie_picture/diff/main/218856_0_236014_20170620101329.png "))
assert(Source::URL.image_url?("https://pic.nijie.net/07/nijie/17/95/728995/illust/0_0_403fdd541191110c_c25585.jpg"))
assert(Source::URL.image_url?("https://pic.nijie.net/06/nijie/17/14/236014/illust/218856_1_7646cf57f6f1c695_f2ed81.png"))
assert(Source::URL.image_url?("https://pic.nijie.net/03/nijie_picture/236014_20170620101426_0.png "))
assert(Source::URL.image_url?("https://pic.nijie.net/01/nijie_picture/diff/main/196201_20150201033106_0.jpg"))
assert_nil(Source::URL.page_url(bad_source1))
assert_nil(Source::URL.page_url(bad_source2))
assert_nil(Source::URL.page_url(bad_source3))
end
assert(Source::URL.page_url?("https://nijie.info/view.php?id=218856"))
assert(Source::URL.page_url?("https://nijie.info/view_popup.php?id=218856"))
assert(Source::URL.page_url?("https://www.nijie.info/view.php?id=218856"))
assert(Source::URL.page_url?("https://sp.nijie.info/view.php?id=218856"))
assert(Source::URL.profile_url?("https://nijie.info/members.php?id=236014"))
assert(Source::URL.profile_url?("https://nijie.info/members_illust.php?id=236014"))
end
context "an unsupported image url" do
should "not break the bookmarklet" do
image_url = "https://pic.nijie.net/01/nijie_picture/diff/main/201207181053373205_0.jpg"
ref = "https://nijie.info/view_popup.php?id=18858&#diff_1"
source = Source::Extractor.find(image_url, ref)
source = Source::Extractor.find(image_url, "https://nijie.info/view_popup.php?id=18858&#diff_1")
assert_equal([image_url], source.image_urls)
end

View File

@@ -130,6 +130,14 @@ module Sources
assert_equal(%w[制作過程 このすば この素晴らしい世界に祝福を セナ バニー 3月3日 巨乳 黒髪巨乳 タイツ], source.tags.map(&:first))
assert_nothing_raised { source.to_h }
end
should "Parse Pixiv Sketch URLs correctly" do
assert(Source::URL.image_url?("https://img-sketch.pixiv.net/uploads/medium/file/4463372/8906921629213362989.jpg "))
assert(Source::URL.image_url?("https://img-sketch.pximg.net/c!/w=540,f=webp:jpeg/uploads/medium/file/4463372/8906921629213362989.jpg"))
assert(Source::URL.image_url?("https://img-sketch.pixiv.net/c/f_540/uploads/medium/file/9986983/8431631593768139653.jpg"))
assert(Source::URL.page_url?("https://sketch.pixiv.net/items/5835314698645024323"))
assert(Source::URL.profile_url?("https://sketch.pixiv.net/@user_ejkv8372"))
end
end
end
end

View File

@@ -347,20 +347,38 @@ module Sources
end
end
context "generating page urls" do
should "work" do
source1 = "http://i2.pixiv.net/img12/img/zenze/39749565.png"
source2 = "http://i1.pixiv.net/img53/img/themare/39735353_big_p1.jpg"
source3 = "http://i1.pixiv.net/c/150x150/img-master/img/2010/11/30/08/39/58/14901720_p0_master1200.jpg"
source4 = "http://i1.pixiv.net/img-original/img/2010/11/30/08/39/58/14901720_p0.png"
source5 = "http://i2.pixiv.net/img-zip-ugoira/img/2014/08/05/06/01/10/44524589_ugoira1920x1080.zip"
should "Parse Pixiv URLs correctly" do
assert_equal("https://www.pixiv.net/artworks/39749565", Source::URL.page_url("http://i2.pixiv.net/img12/img/zenze/39749565.png"))
assert_equal("https://www.pixiv.net/artworks/39735353", Source::URL.page_url("http://i1.pixiv.net/img53/img/themare/39735353_big_p1.jpg"))
assert_equal("https://www.pixiv.net/artworks/14901720", Source::URL.page_url("http://i1.pixiv.net/c/150x150/img-master/img/2010/11/30/08/39/58/14901720_p0_master1200.jpg"))
assert_equal("https://www.pixiv.net/artworks/14901720", Source::URL.page_url("http://i1.pixiv.net/img-original/img/2010/11/30/08/39/58/14901720_p0.png"))
assert_equal("https://www.pixiv.net/artworks/44524589", Source::URL.page_url("http://i2.pixiv.net/img-zip-ugoira/img/2014/08/05/06/01/10/44524589_ugoira1920x1080.zip"))
assert_equal("https://www.pixiv.net/artworks/39749565", Source::URL.page_url(source1))
assert_equal("https://www.pixiv.net/artworks/39735353", Source::URL.page_url(source2))
assert_equal("https://www.pixiv.net/artworks/14901720", Source::URL.page_url(source3))
assert_equal("https://www.pixiv.net/artworks/14901720", Source::URL.page_url(source4))
assert_equal("https://www.pixiv.net/artworks/44524589", Source::URL.page_url(source5))
end
assert(Source::URL.image_url?("https://i.pximg.net/img-original/img/2014/10/03/18/10/20/46324488_p0.png"))
assert(Source::URL.image_url?("https://i.pximg.net/img-master/img/2014/10/03/18/10/20/46324488_p0_master1200.jpg"))
assert(Source::URL.image_url?("https://i.pximg.net/img-zip-ugoira/img/2016/04/09/14/25/29/56268141_ugoira1920x1080.zip"))
assert(Source::URL.image_url?("https://i.pximg.net/c/250x250_80_a2/img-master/img/2014/10/29/09/27/19/46785915_p0_square1200.jpg"))
assert(Source::URL.image_url?("https://i-f.pximg.net/img-original/img/2020/02/19/00/40/18/79584713_p0.png"))
assert(Source::URL.image_url?("http://i1.pixiv.net/img-inf/img/2011/05/01/23/28/04/18557054_64x64.jpg"))
assert(Source::URL.image_url?("https://tc-pximg01.techorus-cdn.com/img-original/img/2017/09/18/03/18/24/65015428_p4.png"))
assert(Source::URL.image_url?("http://img18.pixiv.net/img/evazion/14901720.png"))
assert(Source::URL.image_url?("http://i2.pixiv.net/img18/img/evazion/14901720.png"))
assert(Source::URL.page_url?("https://www.pixiv.net/en/artworks/46324488"))
assert(Source::URL.page_url?("https://www.pixiv.net/artworks/46324488"))
assert(Source::URL.page_url?("http://www.pixiv.net/i/18557054"))
assert(Source::URL.page_url?("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=18557054"))
assert(Source::URL.page_url?("http://www.pixiv.net/member_illust.php?mode=big&illust_id=18557054"))
assert(Source::URL.page_url?("http://www.pixiv.net/member_illust.php?mode=manga&illust_id=18557054"))
assert(Source::URL.page_url?("http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id=18557054&page=1"))
assert(Source::URL.profile_url?("https://www.pixiv.net/member.php?id=339253"))
assert(Source::URL.profile_url?("https://www.pixiv.net/u/9202877"))
assert(Source::URL.profile_url?("https://www.pixiv.net/users/9202877"))
assert(Source::URL.profile_url?("https://www.pixiv.net/en/users/9202877"))
assert(Source::URL.profile_url?("https://www.pixiv.net/stacc/noizave"))
assert(Source::URL.profile_url?("http://www.pixiv.me/noizave"))
assert(Source::URL.profile_url?("https://pixiv.cc/zerousagi/"))
end
end
end

View File

@@ -102,5 +102,19 @@ module Sources
assert_equal([@adult_artist], @post4.artists)
end
end
should "Parse Plurk URLs correctly" do
assert(Source::URL.image_url?("https://images.plurk.com/5wj6WD0r6y4rLN0DL3sqag.jpg"))
assert(Source::URL.image_url?("https://images.plurk.com/mx_5wj6WD0r6y4rLN0DL3sqag.jpg"))
assert(Source::URL.page_url?("https://www.plurk.com/p/om6zv4"))
assert(Source::URL.page_url?("https://www.plurk.com/m/p/okxzae"))
assert(Source::URL.profile_url?("https://www.plurk.com/m/redeyehare"))
assert(Source::URL.profile_url?("https://www.plurk.com/u/ddks2923"))
assert(Source::URL.profile_url?("https://www.plurk.com/m/u/leiy1225"))
assert(Source::URL.profile_url?("https://www.plurk.com/s/u/salmonroe13"))
assert(Source::URL.profile_url?("https://www.plurk.com/redeyehare"))
end
end
end

View File

@@ -0,0 +1,27 @@
require 'test_helper'
module Sources
class RedditTest < ActiveSupport::TestCase
context "Reddit:" do
should "Parse Reddit URLs correctly" do
assert(Source::URL.image_url?("https://i.redd.it/p5utgk06ryq81.png"))
assert(Source::URL.image_url?("https://preview.redd.it/qoyhz3o8yde71.jpg?width=1440&format=pjpg&auto=webp&s=5cbe3b0b097d6e7263761c461dae19a43038db22"))
assert(Source::URL.image_url?("https://external-preview.redd.it/92G2gkb545UNlA-PywJqM_F-4TT0xngvmf_gb9sFDqk.jpg?auto=webp&s=0f1e3d0603dbaabe1ead7352202d0de1653d76f6"))
assert(Source::URL.image_url?("https://g.redditmedia.com/f-OWw5C5aVumPS4HXVFhTspgzgQB4S77mO-6ad0rzpg.gif?fm=mp4&mp4-fragmented=false&s=ed3d767bf3b0360a50ddd7f503d46225"))
assert(Source::URL.image_url?("https://i.redditmedia.com/9cYFBDQ3QsqWnF9v7EhW5uOcQNHz1Ak9_E1zVNeSLek.png?s=6fee1bb56e7d926847dc3ece01a1ffd4"))
assert(Source::URL.page_url?("https://www.reddit.com/r/arknights/comments/ttyccp/maria_nearl_versus_the_leftarmed_knight_dankestsin/"))
assert(Source::URL.page_url?("https://old.reddit.com/r/arknights/comments/ttyccp/maria_nearl_versus_the_leftarmed_knight_dankestsin/"))
assert(Source::URL.page_url?("https://i.reddit.com/r/arknights/comments/ttyccp/maria_nearl_versus_the_leftarmed_knight_dankestsin/"))
assert(Source::URL.page_url?("https://www.reddit.com/r/arknights/comments/ttyccp/"))
assert(Source::URL.page_url?("https://www.reddit.com/comments/ttyccp"))
assert(Source::URL.page_url?("https://www.reddit.com/gallery/ttyccp"))
assert(Source::URL.page_url?("https://www.reddit.com/ttyccp"))
assert(Source::URL.page_url?("https://redd.it/ttyccp"))
assert(Source::URL.profile_url?("https://www.reddit.com/user/xSlimes"))
assert(Source::URL.profile_url?("https://www.reddit.com/u/Valshier"))
end
end
end
end

View File

@@ -99,11 +99,12 @@ module Sources
end
end
context "generating page urls" do
should "handle inconvertible urls" do
bad_source = "https://skeb.imgix.net/requests/229088_2?bg=%23fff&auto=format&w=800&s=9cac8b76c0838f2df4f19ebc41c1ae0a"
assert_nil(Source::URL.page_url(bad_source))
end
should "Parse Skeb URLs correctly" do
assert(Source::URL.image_url?("https://skeb.imgix.net/requests/229088_2?bg=%23fff&auto=format&w=800&s=9cac8b76c0838f2df4f19ebc41c1ae0a"))
assert(Source::URL.image_url?("https://skeb.imgix.net/uploads/origins/04d62c2f-e396-46f9-903a-3ca8bd69fc7c?bg=%23fff&auto=format&w=800&s=966c5d0389c3b94dc36ac970f812bef4"))
assert(Source::URL.image_url?("https://skeb-production.s3.ap-northeast-1.amazonaws.com/uploads/outputs/20f9d68f-50ec-44ae-8630-173fc38a2d6a?response-content-disposition=attachment%3B%20filename%3D%22458093-1.output.mp4%22%3B%20filename%2A%3DUTF-8%27%27458093-1.output.mp4&response-content-type=video%2Fmp4&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIVPUTFQBBL7UDSUA%2F20220221%2Fap-northeast-1%2Fs3%2Faws4_request&X-Amz-Date=20220221T200057Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=7f028cfd9a56344cf1d42410063fad3ef30a1e47b83cef047247e0c37df01df0"))
assert(Source::URL.page_url?("https://skeb.jp/@OrvMZ/works/3 "))
assert(Source::URL.profile_url?("https://skeb.jp/@asanagi"))
end
end
end

View File

@@ -106,6 +106,19 @@ module Sources
assert_equal("", source.artist_commentary_desc)
end
end
should "Parse Tinami URLs correctly" do
assert(Source::URL.image_url?("https://img.tinami.com/illust/img/287/497c8a9dc60e6.jpg"))
assert(Source::URL.image_url?("https://img.tinami.com/comic/naomao/naomao_001_01.jpg"))
assert(Source::URL.image_url?("https://www.tinami.com/view/tweet/card/461459"))
assert(Source::URL.page_url?("https://www.tinami.com/view/461459"))
assert(Source::URL.profile_url?("http://www.tinami.com/creator/profile/1624"))
assert(Source::URL.profile_url?("https://www.tinami.com/search/list?prof_id=1624"))
refute(Source::URL.profile_url?("http://www.tinami.com/profile/1182"))
end
end
end
end

View File

@@ -2,11 +2,17 @@ require 'test_helper'
module Sources
class TwitPicTest < ActiveSupport::TestCase
context "generating page urls" do
should "work" do
context "TwitPic:" do
should "Parse TwitPic URLs correctly" do
assert_equal("https://twitpic.com/dks0tb", Source::URL.page_url("http://d3j5vwomefv46c.cloudfront.net/photos/large/820960031.jpg?1384107199"))
assert_equal("https://twitpic.com/dvitq3", Source::URL.page_url("https://dn3pm25xmtlyu.cloudfront.net/photos/large/839006715.jpg?Expires=1646850828&Signature=d60CmLlmNqZJvOTteTOan13QWZ8gY3C4rUWCkh-IUoRr012vYtUYtip74GslGwCG0dxV5mpUpVFkaVZf16PiY7CsTdpAlA8Pmu2tN98D2dmC5FuW9KhhygDv6eFC8faoaGEyj~ArLuwz-8lC6Y05TVf0FgweeWwsRxFOfD5JHgCeIB0iZqzUx1t~eb6UMAWvbaKpfgvcp2oaDuCdZlMNi9T5OUBFoTh2DfnGy8t5COys1nOYYfZ9l69TDvVb2PKBaV8lsKK9xMwjoJNaWa1HL5S4MgODS5hiNDvycoBpu9KUvQ7q~rhC8cV6ZNctB5H9u~MmvBPoTKfy4w37cSc5uw__&Key-Pair-Id=APKAJROXZ7FN26MABHYA"))
assert_equal("https://twitpic.com/dtnuru", Source::URL.page_url("https://o.twimg.com/2/proxy.jpg?t=HBgpaHR0cHM6Ly90d2l0cGljLmNvbS9zaG93L2xhcmdlL2R0bnVydS5qcGcUsAkU0ggAFgASAA&s=dnN4DHCdnojC-iCJWdvZ-UZinrlWqAP7k7lmll2fTxs"))
assert(Source::URL.image_url?("https://twitpic.com/show/large/carwkf.jpg"))
assert(Source::URL.image_url?("https://o.twimg.com/1/proxy.jpg?t=FQQVBBgpaHR0cHM6Ly90d2l0cGljLmNvbS9zaG93L2xhcmdlL2NhcndrZi5qcGcUBBYAEgA&s=y8haxddqxJYpWql9uVnP3aoFFS7rA10vOGPdTO5HXvk"))
assert(Source::URL.image_url?("http://d3j5vwomefv46c.cloudfront.net/photos/large/820960031.jpg?1384107199"))
assert(Source::URL.page_url?("https://twitpic.com/carwkf"))
assert(Source::URL.profile_url?("http://twitpic.com/photos/Type10TK "))
end
end
end

View File

@@ -289,19 +289,26 @@ module Sources
end
end
context "generating page urls" do
should "work" do
source1 = "https://twitter.com/i/web/status/1261877313349640194"
source2 = "https://twitter.com/BOW999/status/1261877313349640194"
source3 = "https://twitter.com/BOW999/status/1261877313349640194/photo/1"
source4 = "https://twitter.com/BOW999/status/1261877313349640194?s=19"
should "Parse Twitter URLs correctly" do
assert(Source::URL.image_url?("https://pbs.twimg.com/media/EBGbJe_U8AA4Ekb.jpg"))
assert(Source::URL.image_url?("https://pbs.twimg.com/media/EBGbJe_U8AA4Ekb.jpg:small"))
assert(Source::URL.image_url?("https://pbs.twimg.com/media/EBGbJe_U8AA4Ekb?format=jpg&name=900x900"))
assert(Source::URL.image_url?("https://pbs.twimg.com/tweet_video_thumb/ETkN_L3X0AMy1aT.jpg"))
assert(Source::URL.image_url?("https://pbs.twimg.com/ext_tw_video_thumb/1243725361986375680/pu/img/JDA7g7lcw7wK-PIv.jpg"))
assert(Source::URL.image_url?("https://pbs.twimg.com/amplify_video_thumb/1215590775364259840/img/lolCkEEioFZTb5dl.jpg"))
assert_equal(source1, Source::URL.page_url(source1))
assert_equal(source2, Source::URL.page_url(source2))
assert_equal(source2, Source::URL.page_url(source3))
assert_equal(source2, Source::URL.page_url(source4))
assert_nil(Source::URL.page_url("https://www.twitter.com/irt_5433"))
end
assert(Source::URL.page_url?("https://twitter.com/i/web/status/1261877313349640194"))
assert(Source::URL.page_url?("https://twitter.com/BOW999/status/1261877313349640194"))
assert(Source::URL.page_url?("https://twitter.com/BOW999/status/1261877313349640194/photo/1"))
assert(Source::URL.page_url?("https://twitter.com/BOW999/status/1261877313349640194?s=19"))
assert(Source::URL.profile_url?("https://www.twitter.com/irt_5433"))
assert(Source::URL.profile_url?("https://www.twitter.com/irt_5433/likes"))
assert(Source::URL.profile_url?("https://twitter.com/intent/user?user_id=1485229827984531457"))
assert(Source::URL.profile_url?("https://twitter.com/intent/user?screen_name=ryuudog_NFT"))
assert(Source::URL.profile_url?("https://twitter.com/i/user/889592953"))
refute(Source::URL.profile_url?("https://twitter.com/home"))
end
end
end

View File

@@ -112,20 +112,34 @@ module Sources
end
end
context "generating page urls" do
should "work" do
source1 = "https://www.weibo.com/3150932560/H4cFbeKKA?from=page_1005053150932560_profile&wvr=6&mod=weibotime"
source2 = "https://photo.weibo.com/2125874520/wbphotos/large/mid/4242129997905387/pid/7eb64558ly1friyzhj44lj20dw2qxe81"
source3 = "https://m.weibo.cn/status/4173757483008088?luicode=20000061&lfid=4170879204256635"
source4 = "https://tw.weibo.com/SEINEN/4098035921690224"
should "Parse Weibo URLs correctly" do
assert_equal("https://www.weibo.com/3150932560/H4cFbeKKA", Source::URL.page_url("https://www.weibo.com/3150932560/H4cFbeKKA?from=page_1005053150932560_profile&wvr=6&mod=weibotime"))
assert_equal("https://m.weibo.cn/detail/4242129997905387", Source::URL.page_url("https://photo.weibo.com/2125874520/wbphotos/large/mid/4242129997905387/pid/7eb64558ly1friyzhj44lj20dw2qxe81"))
assert_equal("https://m.weibo.cn/status/4173757483008088", Source::URL.page_url("https://m.weibo.cn/status/4173757483008088?luicode=20000061&lfid=4170879204256635"))
assert_equal("https://m.weibo.cn/detail/4098035921690224", Source::URL.page_url("https://tw.weibo.com/SEINEN/4098035921690224"))
assert_equal("https://www.weibo.com/3150932560/H4cFbeKKA", Source::URL.page_url(source1))
assert_equal("https://m.weibo.cn/detail/4242129997905387", Source::URL.page_url(source2))
assert_equal("https://m.weibo.cn/status/4173757483008088", Source::URL.page_url(source3))
assert_equal("https://m.weibo.cn/detail/4098035921690224", Source::URL.page_url(source4))
assert_nil(Source::URL.page_url("https://weibo.com/u/"))
assert_nil(Source::URL.page_url("https://www.weibo.com/4ubergine/photos"))
end
assert(Source::URL.image_url?("http://ww1.sinaimg.cn/large/69917555gw1f6ggdghk28j20c87lbhdt.jpg"))
assert(Source::URL.image_url?("http://ww4.sinaimg.cn/mw690/77a2d531gw1f4u411ws3aj20m816fagg.jpg"))
assert(Source::URL.image_url?("https://wx4.sinaimg.cn/orj360/e3930166gy1g546bz86cij20u00u040y.jpg"))
assert(Source::URL.image_url?("https://wx1.sinaimg.cn/original/7004ec1cly1ge9dcbsw4lj20jg2ir7wh.jpg"))
assert(Source::URL.page_url?("http://tw.weibo.com/1300957955/3786333853668537"))
assert(Source::URL.page_url?("http://photo.weibo.com/2125874520/wbphotos/large/mid/4194742441135220/pid/7eb64558gy1fnbryb5nzoj20dw10419t"))
assert(Source::URL.page_url?("http://weibo.com/3357910224/EEHA1AyJP"))
assert(Source::URL.page_url?("https://www.weibo.com/5501756072/IF9fugHzj?from=page_1005055501756072_profile&wvr=6&mod=weibotime"))
assert(Source::URL.page_url?("https://www.weibo.com/detail/4676597657371957"))
assert(Source::URL.page_url?("https://m.weibo.cn/detail/4506950043618873"))
assert(Source::URL.page_url?("https://m.weibo.cn/status/J33G4tH1B"))
assert(Source::URL.profile_url?("https://www.weibo.com/u/5501756072"))
assert(Source::URL.profile_url?("https://m.weibo.cn/u/5501756072"))
assert(Source::URL.profile_url?("https://m.weibo.cn/profile/5501756072"))
assert(Source::URL.profile_url?("https://www.weibo.com/p/1005055399876326"))
assert(Source::URL.profile_url?("https://www.weibo.com/5501756072"))
assert(Source::URL.profile_url?("https://www.weibo.com/endlessnsmt"))
assert(Source::URL.profile_url?("https://www.weibo.com/4ubergine/photos"))
refute(Source::URL.profile_url?("https://weibo.com/u/"))
end
end
end