whiteleaf7 / narou

Narou.rb - 小説家になろうのダウンローダ&縦書き整形&管理アプリ。Kindle(などの電子書籍端末)でなろうを読む場合に超便利です!
Other
483 stars 56 forks source link

narou.rb is unable to download from Kakuyomu anymore #412

Closed Rich-Richie closed 3 months ago

Rich-Richie commented 7 months ago

The tool is unable to update any works from Kakuyomu anymore. It can't read the title nor the number of chapters anymore.

To provide clarity, this happens when you try to update a work from Kakuyomu.

<h1 id="workTitle"><a href=".+?">(?<title>.+?)</a></h1>
更新後の話数が保存されている話数より減少していることを検知しました。
ダイジェスト化されている可能性があるので、更新に関しての処理を選択して下さい。

保存済み話数: 266
更新後の話数: 0

1: このまま更新する
2: 更新をキャンセル
3: 更新をキャンセルして小説を凍結する
4: バックアップを作成する
5: 最新のあらすじを表示する
6: 小説ページをブラウザで開く
7: 保存フォルダを開く
8: 変換する
ID:136 不良少年が魔法少女になったら最強ですか? の更新はキャンセルされました

And this is what happens if you try to download a Kakuyomu work.

[ERROR] <h1 id="workTitle"><a href=".+?">(?<title>.+?)</a></h1> の目次がありません

This implies that the tool is unable to find the title and the table of content anymore.

I don't know how to fix this, but I thought I will raise this issue to notify the author of the tool about it.

whiteleaf7 commented 7 months ago

目次の構造が変わりすぎててすぐには対応は難しそう

Rich-Richie commented 7 months ago

It is okay, you can take your time. It doesn't have to be immediate.

Thank you for looking at it.

topstone commented 7 months ago

I forked narou with contributed kakuyomu file and released as "narouq" gem (tested not well).

You can install "narouq" side by side with original "narou".

happynow commented 7 months ago

topstoneさんの修正版は「1話、1章、2話, 3話…」のように目次の順番がおかしくなる場合があります。 参考までに、その問題を解消した修正版を添付させて頂きます。 あまり綺麗なやり方ではありませんが、downloader.rb にカクヨム用の特殊処理を実装しました。 なお、新しいカクヨムのHTMLテキストは、yamlの正規表現だけでは完全な解析は出来ないでしょう。 narou_20231210.zip

happynow commented 7 months ago

すいません。 掲示板にも返信しますが目次情報が正しく取得できないというバグがありました。 修正版を添付させて頂きます。

それから、narou-3.8.2 をインストール時には既にいくつかの作品のsetting.iniがpresetに入ってます(GitHubのmasterにもあります)。掲示板で指摘された作品のものもあり、enable_yokogaki = true になっています。 そのまま作ると横書きのもが出来上がります。ご注意ください。 narou_20231222.zip

happynow commented 6 months ago

掲示板で指摘された WEB.UI で作品情報が取れないという不具合を修正しましたので、また添付させて頂きます。 何度も差し替えの修正版を貼り付けるとか、GitHubで何やってんだ、という感じで申し訳ありませんが。。

今回は作品情報のダウンロード処理が downloader.rb の他に novelinfo.rb にもあり、そちらの修正が漏れていました。 たまたまかもしれませんが、コマンドラインからの実行だと上手く動いていたので気づくのが遅れました。 narou_20231226.zip

追記(勝手に紹介) その後、私の修正版より出来の良さそうなものがリリースされました。 https://github.com/rogenobl/narou/releases/ にある sitesettinghandler と Pagination の各パッチの最新版を当てて下さい。

happynow commented 6 months ago

度々すいません。 掲示板で「narou_20231226.zip の update_option フォルダの helper.rb を適用してもエラーが発生する」と報告があったので、改めて修正しました。 update_option_20240103.zip

このトラブルは次の課題に関連しています。

Windows で使っている Java が Adopt Open JDK だと "AozoraEpub3でEPUBに変換" するときにエラーになる #399

修正方法について、以下にコメントさせて頂きました。 https://github.com/whiteleaf7/narou/issues/399#issuecomment-1875320540

U5376 commented 6 months ago

度々すいません。 掲示板で「narou_20231226.zip の update_option フォルダの helper.rb を適用してもエラーが発生する」と報告があったので、改めて修正しました。 update_option_20240103.zip

このトラブルは次の課題に関連しています。

Windows で使っている Java が Adopt Open JDK だと "AozoraEpub3でEPUBに変換" するときにエラーになる #399

修正方法について、以下にコメントさせて頂きました。 #399 (comment)

~~目次にsubchapterの第一章、第二章を追加するにはどうすればいいですか? ttps://kakuyomu.jp/works/16817139555810310315 この目次では第一部、幕間、第二部…のみが生成されてます~~ しみません AozoraEpub3の目次抽出設定の問題だったです

Rich-Richie commented 6 months ago

@whiteleaf7 How is your progress with your fix? There are fixes by others in this thread, but I want to know about your progress.

yose-touhu commented 6 months ago

作法が分からないので失礼がありましたらすみません。

素人のため詳しい分析は出来ず、報告だけになりますが 「小説家になろう」の方でも更新時にRich-Richieさんが貼られた画像と 同じメニューが表示されます。

おそらくカクヨムと同様で、目次の表示方法の変更によるものと思われます。

取り急ぎ失礼致しました。

happynow commented 5 months ago

なろうサイトで100話しか取れない件、個人的にですが対応しました。 毎度すいませんが、修正版を貼り付けさせて頂きます。 narou_20240124.zip

私のものよりこちらをお薦めします。 https://github.com/rogenobl/narou/releases/ にある sitesettinghandler(カクヨム対応)と Pagination(なろう100話対応)の各パッチの最新版を当てて下さい。

今回のリニューアルでは、目次インデックスがページネイトされました。 それぞれの目次ページは以下のようなURLでアクセス可能です。

https://ncode.syosetu.com/n4830bu/
https://ncode.syosetu.com/n4830bu/?p=2
https://ncode.syosetu.com/n4830bu/?p=3
        :

修正方法は「各目次ページからダウンロードしたものを、ひとつのテキストに結合して解析処理にまわす」という感じです。 ただ、あまり綺麗に直せていません。 それにしても、リニューアルしたサイトが javascriptとかで動的に目次を作ったりしてなくて良かったです。

なお下記の点、ご注意ください。

【修正版のべっぱん(別版のほう)を作られる方へ】 なろうサイトは連続DLに対して規制が掛かっています。 ウェイト(待機)なしで連続DLを行うと、503 Service Unavailable エラーが発生して、暫くアクセスできなくなります。 ウェイト処理をしっかり実装して下さい。 既存ロジックでは、作品情報や目次情報のダウンロードは連続DLとしてカウントされていません。見直しが必要です。 参考までにいうと「デスマーチからはじまる異世界狂想曲」などは目次ページだけで8回のダウンロードが必要になります。

あと、今更ですがRich-Richieさんが英語で書かれているのにバリバリの日本語ですいません。

happynow commented 5 months ago

rogenoblさんの、なろう100話対応版(※) が公式採用されるかもしれないので、気づいたこと書かさせて頂きます。

(※) 次のURLからダウンロードできます https://github.com/rogenobl/narou/releases/tag/p0.1

既存ロジックの問題

narou-3.8.2のオリジナルコードとrogenoblさんの修正版には下記の問題があります(行番号も同じ) とはいえ、大した問題ではなさそうです。

$\texttt{downloader.rb}$

$\texttt{759}$  $\texttt{\#}$ $\texttt{760}$  $\texttt{\# 目次データを取得する}$ $\texttt{761}$  $\texttt{\#}$ $\texttt{762}$  $\texttt{def get\_latest\_table\_of\_contents(old\_toc, through\_error: false)}$ $\texttt{763}$    $\textcolor{red}{\texttt{toc\_source = get\_toc\_source ← ここと}}$ $\texttt{764}$    $\texttt{return nil unless toc\_source}$ $\texttt{765}$    $\texttt{@}$$\texttt{setting.multi\_match(toc\_source, "tcode")}$ $\texttt{766}$    $\textcolor{red}{\texttt{info = NovelInfo.load(}}$$\textcolor{red}{\texttt{@}}$$\textcolor{red}{\texttt{setting, toc\_source: toc\_source) ← ここのダウンロード処理で}}$ $\texttt{767}$    $\texttt{if info}$ $\texttt{768}$      $\texttt{raise DownloaderNotFoundError unless info["title"]}$

ウェイト処理($\texttt{sleep\_for\_download}$)が呼び出されていません。

rogenoblさんの downloader.rb の修正案

下記のとおり、792行目の $\texttt{sleep\_for\_download}$ を削除して727行目に挿入します。 これで $\texttt{get\_toc\_source}$ の初回呼び出しのときもウェイト処理のための情報が更新されます。 もうひとつの $\texttt{NovelInfo.load}$ はキャッシュされたデータを返すこともあり、必ずダウンロード処理を行うわけではありません。この対応は少し手間が掛かりそうです。ただ、デフォルトのウェイト(0.7秒)でも503エラーの発生をある程度抑えられるので、このままでも良いかも知れません。

720   def get_toc_source
721     toc_url = @setting["toc_url"]
722     return nil unless toc_url
723     max_retry = 5
724     toc_source = ""
725     cookie = @setting["cookie"] || ""
726     open_uri_options = make_open_uri_options("Cookie" => cookie, allow_redirections: :safe)
+       sleep_for_download
727     begin
728       URI.open(toc_url, open_uri_options) do |toc_fp|

758 
759   #
760   # 目次データを取得する
761   #
762   def get_latest_table_of_contents(old_toc, through_error: false)
763     toc_source = get_toc_source

788       source = toc_source
789       100.times do
790         subtitles.concat(get_subtitles(source, old_toc))
791         break unless @setting.multi_match(source, "next_toc")
-           sleep_for_download
793         @setting["toc_url"] = @setting["next_url"]
794         begin
795           source = get_toc_source
796         ensure
797           @setting["toc_url"] = toc_url
798         end
799       end
800     else

(参考)なろうサイトのDL規制について

何もウェイトなしで連続DLすると、下記のようになりました。

ソースコードで「1話ごとに1秒待機を10回繰り返そうと、11回目に規制が入るため、ウェイトは必ず必要」というコメントを見たので実験してみました。 その結果、各ダウンロード処理の間に0.7秒(Narou.rbのデフォルトの待機時間)のウェイトを入れておくことで、下記のコードで 100回の連続DLが出来ました。というわけで、あまりシビアに実装しなくてもよいのかもしれません。

require 'open-uri'

count = 0
100.times do
  count += 1
  begin
    tm = Time.now
    url = "https://ncode.syosetu.com/n4830bu/#{count}/"
    URI.open(url) do |f|
      sec = Time.now - tm
      #リクエストしてからリターンするまでの経過秒を出力
      puts "#{count}\t#{sprintf("%.3f", sec)} sec\t#{url}"
    end
    sleep(0.7)
  rescue OpenURI::HTTPError => e
    p e.io.status
    puts "count: #{count}"
    exit
  end
end
Rich-Richie commented 5 months ago

あと、今更ですがRich-Richieさんが英語で書かれているのにバリバリの日本語ですいません。

あ、大丈夫です。自分が使いやすい言語で書けばいい。

By the way, whose update should I implement? Happynow's or rogenobl's? It seems like using rogenobl's update will require me to modify the code, so happynow's would be more preferable, but I'm unsure.

Grinchii commented 5 months ago

あと、今更ですがRich-Richieさんが英語で書かれているのにバリバリの日本語ですいません。

あ、大丈夫です。自分が使いやすい言語で書けばいい。

By the way, whose update should I implement? Happynow's or rogenobl's? It seems like using rogenobl's update will require me to modify the code, so happynow's would be more preferable, but I'm unsure.

Just take the files from https://github.com/rogenobl/narou/releases and put them in your Narou (gem) folder, overwrite the old files and it should work.

using this with Ubuntu Server and FreeBSD and both working fine till now.

Rich-Richie commented 5 months ago

But happynow mentioned that the pagination mechanism doesn't have a delay feature, so it may trigger a 503 error. While I don't follow any webnovel with more than 700 chapters, I'm not comfortable with the chance that I may be overloading their service and have my ip address suspended for a while. How long is the longest novel you are following?

On Mon, Jan 29, 2024, 8:55 PM Grinchii @.***> wrote:

あと、今更ですがRich-Richieさんが英語で書かれているのにバリバリの日本語ですいません。

あ、大丈夫です。自分が使いやすい言語で書けばいい。

By the way, whose update should I implement? Happynow's or rogenobl's? It seems like using rogenobl's update will require me to modify the code, so happynow's would be more preferable, but I'm unsure.

Just take the files from https://github.com/rogenobl/narou/releases and put them in your Narou (gem) folder, overwrite the old files and it should work.

using this with Ubuntu Server and FreeBSD and both working fine till now.

— Reply to this email directly, view it on GitHub https://github.com/whiteleaf7/narou/issues/412#issuecomment-1914743775, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASVCGZUUAIBZQET4LFDSFTDYQ6S37AVCNFSM6AAAAAA75IONZGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJUG42DGNZXGU . You are receiving this because you authored the thread.Message ID: @.***>

sszk commented 5 months ago

@Rich-Richie FYI I don't see any problem even with a novel which has over 1800 episodes while I'm using rogenobl's version.

rogenobl commented 5 months ago

rogenoblさんの downloader.rb の修正案

下記のとおり、792行目の sleep_for_download を削除して727行目に挿入します。 これで get_toc_source の初回呼び出しのときもウェイト処理のための情報が更新されます。 もうひとつの NovelInfo.load はキャッシュされたデータを返すこともあり、必ずダウンロード処理を行うわけではありません。この対応は少し手間が掛かりそうです。ただ、デフォルトのウェイト(0.7秒)でも503エラーの発生をある程度抑えられるので、このままでも良いかも知れません。

この修正を採用して更新しました。 ご指摘ありがとうございます。 https://github.com/rogenobl/narou/releases/tag/p0.3

追記:これは「カクヨム」ではなく「小説家になろう」への対応です あと、流れでここに書きましたが、本来別のissueにすべきかもしれません。

happynow commented 5 months ago

@Rich-Richie おすすめしたいのは「本好きの下剋上(全677話)」、「人狼への転生、魔王の副官(全415話)」あたりです。それほど長大な作品は読んでません。503エラーはこれまで出たことないので、あまり不都合を感じてません。

Narou.rb には download.interval や update.interval、download.wait-steps ※ など待機処理用のパラメーターが用意されています。気になるなら、それらを設定するのもひとつです。

※なろう向けに独自に設定するなら10未満の値を設定することになる