Get comments on youtube Live with [python] and [pytchat]!

See all the live comments

I got live comments of all videos of Hinano Tachibana (vtuber). See ./Thinano/data/0IFEp1Bt3qw.json. The data is all https://github.com/1k-ct/Thinano here.

The name is the name of the person who commented, and the message is the comment. : _naa :: _noo: ← This is a stamp that can only be used by members.

--See comments on other videos -Click here. --Click comment. --Select the file you want to see https://www.youtube.com/watch?v=oQmgxXbT8OE is like this oQmgxXbT8OE.json --Press View raw to see the file.

Super chat amount

Here is the amount of each video of Spacha. The video with the most spachas is [Celebration] Monetization! !! Thank you to 6000 people ♡ [IBG / Hinano Tachibana] Is this video about 400,000 yen?

Maximum total amount


{
        "oQmgxXbT8OE": {
            "¥": 371203.0,
            "PHP ": 500.0,
            "₩": 2000.0,
            "CA$": 55.0,
            "A$": 10.0
        }
}

From here, we will introduce the survey method. From now on, I will introduce some of the two URLs below. https://github.com/taizan-hokuto/pytchat https://github.com/taizan-hokuto/pytchat/wiki/Home_jp

environment

Python 3.8.5
pytchat 0.4.2

Installation


$ pip install pytchat

Get live comments

Please see officially. https://github.com/taizan-hokuto/pytchat/wiki/PytchatCore_

main.py



import pytchat
import time
#Get PytchatCore object
livechat = pytchat.create(video_id = "Zvp1pJpie4I")# video_id is https://....watch?v=Behind

while livechat.is_alive():
    #Get chat data
    chatdata = livechat.get()
    for c in chatdata.items:
        print(f"{c.datetime} {c.author.name} {c.message} {c.amountString}")
        '''
Get as JSON string:
        print(c.json())
        '''
    time.sleep(5)

Super chat

See also officially. https://github.com/taizan-hokuto/pytchat/wiki/SuperchatCalculator_

--Install progress bar

It's good to know the progress


$ pip install tqdm

main.py


from tqdm import tqdm
from pytchat import Extractor, VideoInfo, SuperchatCalculator
import signal

'''
Progress bar showing progress
'''
class ProgressBar:
    def __init__(self,total):
        self.total = total*1000
        self.pbar = tqdm(total = self.total, ncols = 80, unit_scale = 1,
            bar_format='{desc}{percentage:3.1f}%|{bar}|'
                       '[{n_fmt:>7}/{total_fmt}]{elapsed}<{remaining}')
        
    def callback(self, actions, fetched):
        if self.total - fetched < 0:
            fetched = self.total
        self.total -= fetched
        self.pbar.update(fetched)
    
    def close(self):
        self.pbar.update(self.total)
        self.pbar.close()
    
    def cancel(self):
        self.pbar.close()

if __name__ == '__main__':
    video_id = "GY-LSsYVpJ4"
    info  = VideoInfo(video_id)
    print('Calculate Superchat: [title] ', info.get_title())    

    #Prepare a progress bar.
    pbar = ProgressBar(info.get_duration())
 
    #Extractor generation
    ex = Extractor(
        video_id,
        callback = pbar.callback,
        div = 10,
        processor = SuperchatCalculator()
    )

    #Ctrl+Cancel with C
    signal.signal(signal.SIGINT,  
        (lambda a, b: ex.cancel()))

    #Perform extraction
    result = ex.extract()

    #Display of aggregation results
    pbar.close()
    print(result)

Quote

in conclusion

All explanations can be found at the URL above. I was wondering if I could write an article just by introducing it. Also, it's hard to see json in super chat. I'll fix it. Please contact me if you have any questions. Thank you very much.

Recommended Posts

Get comments on youtube Live with [python] and [pytchat]!
Get YouTube Comments in Python
Get Youtube data with python
Get comments and subscribers with the YouTube Data API
Get comments on Nico Nico Live Broadcasting
A memo with Python2.7 and Python3 on CentOS
Get data from MySQL on a VPS with Python 3 and SQLAlchemy
Automatically search and download YouTube videos with Python
[Python] Get all comments using Youtube Data API
Get git branch name and tag name with python
Get started with Python on macOS Big Sur
Get Gmail subject and body with Python and Gmail API
Get date with python
Notes on HDR and RAW image processing with Python
Install selenium on Mac and try it with python
Automatic follow on Twitter with python and selenium! (RPA)
Get mail from Gmail and label it with Python3
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Email hipchat with postfix, fluentd and python on Azure
Automate Chrome with Python and Selenium on your Chromebook
[Python] Get user information and article information with Qiita API
Get country code with python
Programming with Python and Tkinter
Encryption and decryption with Python
Python and hardware-Using RS232C with Python-
Python on Ruby and angry Ruby on Python
Get Twitter timeline with python
YouTube video management with Python 3
Get thread ID with python
Get started with Python! ~ ② Grammar ~
python with pyenv and venv
[python] Get quotient and remainder
Get stock price with Python
Get home directory with python
Get keyboard events with python
Get Alembic information with Python
Works with Python and R
Let's get started with Python ~ Building an environment on Windows 10 ~
IP spoof using tor on macOS and check with python
Test Python with Miniconda on OS X and Linux with travis-ci
Get rid of dirty data with Python and regular expressions
Create youtube ad auto skip tool with python and OCR
Get YouTube Live chat field in real time with API
Notes on deploying pyenv with Homebrew and managing Python versions
Sample of HTTP GET and JSON parsing with python of pepper
[Python x Zapier] Get alert information and notify with Slack
Get additional data to LDAP with python (Writer and Reader)
Get the matched string with a regular expression and reuse it when replacing on Python3
Communicate with FX-5204PS with Python and PyUSB
Shining life with Python and OpenCV
How is the progress? Let's get on with the boom ?? in Python
Notes on Python and dictionary types
Get started with Python! ~ ① Environment construction ~
Python 3.6 on Windows ... and to Xamarin.
Install Python 2.7.9 and Python 3.4.x with pip.
Neural network with OpenCV 3 and Python 3
AM modulation and demodulation with python
Link to get started with python
[Python] font family and font with matplotlib
Scraping with Node, Ruby and Python
Get started with the Python framework Django on Mac OS X