niconicolibs / niconico.py

niconico.py is a Python library for retrieving Niconico video content and information, and is compatible with the latest version of Niconico.
MIT License
42 stars 5 forks source link

[Feature] Add a function to get comments #17

Closed Negima1072 closed 2 years ago

Negima1072 commented 2 years ago

Overview

Currently, there is a function to download the video, but there is no function to get the comment of the video, so I suggest adding it.

Required functions

Remarks

Comment acquisition is possible with a GET request in the unauthenticated state, so use that.

Negima1072 commented 2 years ago

つぎにやりまーす

tasuren commented 2 years ago

wow

Negima1072 commented 2 years ago

@tasuren videoオブジェクト以下にget_comments(~~)(return List(Comment))を作ろうと思うのですがそれで大丈夫ですか? また関数内でニコ動のAPIにアクセスしたい場合、self.client.niconico.requestからリクエストで大丈夫ですか?

tasuren commented 2 years ago

videoオブジェクト以下にget_comments(~~)(return List(Comment))を作ろうと思うのですがそれで大丈夫ですか?

動画のコメントを取得するのに使うAPIは少しづつ取得が可能ですか? もし可能ならばyieldを使って少しづつ返すと言う感じの方がメモリを占領しないようにできるのでよさそうです。

また関数内でニコ動のAPIにアクセスしたい場合、self.client.niconico.requestからリクエストで大丈夫ですか?

はい、大丈夫です。

Negima1072 commented 2 years ago

コメント取得APIは1度に最新1000件(ニコ動上で読み込まれる上限)を送信する使用です。 恐らくコメントデータにする際に取得データをforで回すことになると思うので単純にList[Comment]で返すのならばyieldが使えそうです。 ただ、threadの内容(例えばticketの値や合計コメ数last_res)などを返したい場合はCommentsオブジェクトを作ってその中にitems(List)要素を作るほうがいいかもしれません。ただ別関数で用意してもいいと思いますが。 ご意見を聞かせてもらえれば幸いです。

参考URL: https://nvcomment.nicovideo.jp/legacy/api.json/thread?nicoru=3&res_from=-1000&scores=1&thread=1173108780&version=20090904&with_global=1

下のようなjsonが帰ってきます。chat要素が複数ある感じです。

[
    {"thread": { //threadは必ず返ってくる
        "resultcode": 0,  //成功したかどうか 失敗の場合は1以上
        "thread": "1173108780",  //thread id
        "last_res": 5186301, //コメント数(一番最新のコメントNo)
        ~~~
    }},
    {"leaf": {~~~}},
    ~~~
    {"chat": {
        "thread": "1173108780",  //thread id
        "no": 5185302,  //コメントNo
        "vpos": 2909,  //投稿された場所(1/100秒 よって左は29.09秒)
        "date": 1627567608,  //投稿時間(UNIX)
        "date_usec": 673929,  //投稿時間マイクロ秒
        "score": -12350, //NGスコア
        "anonymity": 1, 
        "user_id": "2kNzkNewE7Y6DzwzeJhfB997mcE", 
        "mail": "green big 184", //コマンド
        "content": "▒▓████▓▒░悪霊退散▒▓████▓▒░悪霊退散▒▓████▓▒░悪霊退散▒▓████▓▒░悪霊退散▒▓████▓▒░悪霊退散▒▓████▓▒" //内容
    }}
    ~~~
]
tasuren commented 2 years ago
data.thread
data.leaf
data.chats: list[...]

みたいな感じに使えるオブジェクトが良さそうです。

それと、関係ない質問なんですが、今のniconico.pyの構成はどう思いますか? 今のままで良いと思いますか?

Negima1072 commented 2 years ago

みたいな感じに使えるオブジェクトが良さそうです。

了解しました。そんな感じでやってみます。

niconico.pyの構成はどう思いますか?

良いと思います。このライブラリの最終形態は以下のような感じになると予想しています。

NicoNico
|-client.video
   |-Video =client.video.get()
      |-download()
      |-get_comments()
      :
|-client.live
|-client.seiga
|-client.dic
|-client.user
|-client.com
|-client.repo
:

つまり今のまま横に増えていく感じ? その上で新規コントリビューターの為にやっておくべきこととして、以下のことが挙げられると思います。

非公式ライブラリの中でコードやファイル、クラス構成が綺麗だなぁと思ったLINEのライブラリを置いておきます。(現在は使えません) https://github.com/fadhiilrachman/line-py

またオープンソースローンチマニュアルを置いておきます。 https://ja-opensource-guide.github.io/starting-a-project/

branchに関してはこちらを https://qiita.com/trsn_si/items/cfecbf7dff20c64628ea

tasuren commented 2 years ago

了解です。参考にします。