From ac071b147f1ad8dd6e5035474c7969e862831a4b Mon Sep 17 00:00:00 2001 From: nonamethanks Date: Sun, 23 May 2021 18:05:16 +0200 Subject: [PATCH] Lofter: fix strategy for additional type of html theme --- app/logical/sources/strategies/lofter.rb | 7 ++++--- test/unit/sources/lofter_test.rb | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/logical/sources/strategies/lofter.rb b/app/logical/sources/strategies/lofter.rb index 9340e0787..eb2d872cb 100644 --- a/app/logical/sources/strategies/lofter.rb +++ b/app/logical/sources/strategies/lofter.rb @@ -10,6 +10,7 @@ # Page URLs # # * https://gengar563.lofter.com/post/1e82da8c_1c98dae1b +# * https://yuli031458.lofter.com/post/3163d871_1cbdc5f6d (different theme/css selectors) # # Profile URLs # @@ -45,7 +46,7 @@ module Sources end def image_urls - images = page&.search(".pic img") + images = page&.search(".pic img, .content img") images.to_a.map { |img| get_full_version(img["src"]) } end @@ -73,7 +74,7 @@ module Sources end def tags - tags = page&.search(".info .tag") + tags = page&.search(".info .tag, .main .tag a") tags.to_a.map do |tag| [tag.text, tag.attr("href")] @@ -81,7 +82,7 @@ module Sources end def artist_commentary_desc - page&.search(".ct .text")&.to_html + page&.search(".ct .text, .content .text").to_a.compact.first&.to_html end def normalize_for_source diff --git a/test/unit/sources/lofter_test.rb b/test/unit/sources/lofter_test.rb index aa88e33f5..bc0e662b9 100644 --- a/test/unit/sources/lofter_test.rb +++ b/test/unit/sources/lofter_test.rb @@ -44,6 +44,14 @@ module Sources end end + context "A different CSS schema" do + should "still find all the data" do + source = Sources::Strategies.find("https://yuli031458.lofter.com/post/3163d871_1cbdc5f6d") + assert_equal(["https://imglf5.lf127.net/img/Mm55d3lNK2tJUWpNTjVLN0MvaTRDc1UvQUFLMGszOHRvSjV6S3VSa1lwa3BDWUtVOWpBTHBnPT0.jpg"], source.image_urls) + assert_not_empty(source.tags) + end + end + context "A bad link" do should "correctly get the full size" do source = Sources::Strategies.find("https://imglf4.lf127.net/img/S1d2QlVsWkJhSW1qcnpIS0ZSa3ZJUFczb2RKSVlpMHJkNy9kc3BSQVQvQm5DNzB4eVhxay9nPT0.png?imageView&thumbnail=1680x0&quality=96&stripmeta=0")