From cb6196c259f84677352595414ef9049025f62445 Mon Sep 17 00:00:00 2001 From: nonamethanks Date: Tue, 6 Apr 2021 14:08:49 +0200 Subject: [PATCH] Nicoseiga: auto-add spoiler tags to commentary --- app/logical/sources/strategies/nico_seiga.rb | 6 ++++- test/unit/sources/nico_seiga_test.rb | 25 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/logical/sources/strategies/nico_seiga.rb b/app/logical/sources/strategies/nico_seiga.rb index 858c496cc..666f860f1 100644 --- a/app/logical/sources/strategies/nico_seiga.rb +++ b/app/logical/sources/strategies/nico_seiga.rb @@ -134,7 +134,11 @@ module Sources end def dtext_artist_commentary_desc - DText.from_html(artist_commentary_desc).gsub(/[^\w]im(\d+)/, ' seiga #\1 ') + DText.from_html(artist_commentary_desc) do |element| + if element.name == "font" && element["color"] == "white" + element.content = "[spoiler]#{element.content}[/spoiler]" + end + end.gsub(/[^\w]im(\d+)/, ' seiga #\1 ').chomp end def normalize_for_source diff --git a/test/unit/sources/nico_seiga_test.rb b/test/unit/sources/nico_seiga_test.rb index 906ba09b0..fb517076a 100644 --- a/test/unit/sources/nico_seiga_test.rb +++ b/test/unit/sources/nico_seiga_test.rb @@ -129,6 +129,31 @@ module Sources end end + context "A commentary with spoiler" do + should "correctly add spoiler tags" do + site = Sources::Strategies.find("https://seiga.nicovideo.jp/seiga/im8992650") + + commentary = <<~COMM.chomp + SLVN大好き。ホントニアコガレテル。 + + [spoiler] + 「魔理沙とアリスのクッキーKiss」 + 企画者HZNの企画した東方合同動画企画 + 苦行を称する東方ボイスドラマ + 遥か昔、東方界隈のはずれ + その偏境に消えぬボイスドラマの火を見出したとき + 若き健常者HZNの心にも + 消えぬ野心が灯ったのだろう + 戦技は「義務教育」 + クッキー☆を終わるまで視聴させる技 + 27分にわたる苦行からのエンディングで視聴者はぬわ疲に包まれる + [/spoiler] + COMM + + assert_equal(commentary, site.dtext_artist_commentary_desc) + end + end + context "normalizing for source" do should "normalize correctly" do source1 = "http://lohas.nicoseiga.jp/priv/3521156?e=1382558156&h=f2e089256abd1d453a455ec8f317a6c703e2cedf"