LoginSignup
1
0

コメントを収集するライブラリChatDownloaderを使ってみた

Posted at

コメントを収集するライブラリChatDownloaderの紹介

徐々に寒さが増し、単位の結果が気になる季節ですね。皆さんは単位をしっかり取得できましたか?私は残念ながらいくつか落としてしまいました。

さて、今回はちょっと面白いライブラリ、ChatDownloaderについて紹介します。Pythonの環境構築などはまた別の機会に触れるとして…

ChatDownloaderを使う理由
近頃、ライブ配信の動画の長さに疑問を感じ始めました。コメントを収集して解析することで、見どころを抽出できないかと思い至りました。しかし、YouTube APIの使用は少し敷居が高いため、代わりにChatDownloaderを見つけました。

導入と使用例

ということで、四の五の言わずにpip install
使用環境はPython3.8です。

コマンド
pip install chat-downloader

ダウンロードするコメント付きの動画は
LIVE: Bahrain Grand Prix Build-Up and Drivers Parade
という海外のレーシングの選手インタビューの動画をしようしました。ここで好きな配信者(Vtuber)の動画でも良かったのですが、起業部として記事を発信しているため皆さんに布教できないのが残念です。

chat_downloader.py
from chat_downloader import ChatDownloader

url = 'https://www.youtube.com/watch?v=fdUL1wzSC1g'
chat = ChatDownloader().get_chat(url)  # create a generator
for message in chat:  # iterate over messages
    chat.print_formatted(message)  # print the formatted message

結果は以下のようになります。
マイナスからスタートしているのは待機中のコメントであるためです。

結果
-1:45 | Solomon: Dont gamble burn rubber 
-1:42 | Proliwier: Max Verstappen 
-1:41 | flavi3nse: than than than
-1:36 | Shivam: AND ITS LIGHTS OU- ...(skips)..max wins the bahrain gp
-1:35 | Qylus: Haas 1-2 coming
-1:33 | kstfsy: Max
-1:33 | Nekkusu: @Kylian Mbappé Yeah thats what i'm talking about (We about to 3-peat the Champions league again)
-1:29 | Cakeplays21 : landoooooo 

以下同様に続く

スタートを0:00からしたいのであれば

- chat = ChatDownloader().get_chat(url)
+ chat = ChatDownloader().get_chat(url, start_time='0:00')

とすると0:00からスタートできます。

終わりに

いかがでしたでしょうか。
このライブラリの魅力は、YouTube、Twitch、Zoomなどのプラットフォームから認証なしでチャットメッセージを取得できる点にあります。

公式ドキュメントはこちらから参照できます。

それでは、岐阜大学起業部からお送りしました。また次回お会いしましょう。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0