I displayed the chat of YouTube Live and tried playing

This article is the 25th day article of VTuber Tech # 1 Advent Calendar 2019. I usually work as a Vtuber under the name Soki Tamaki.

I got a chat, displayed it on a green background and played

I made an app that allows chat to flow from right to left. We also implemented commands to change the font color, play voice, and make it rain.

でも.PNG

Functional test Actual use (latest delivery)

↓ Please use it as you like. Source code The one that was converted to exe with pyinstaller

How to use (copy and paste of README)

Enter the delivery ID (the one in the URL) next to the window ID that appears when you start it, and press the ok button. If there is nothing, the comment will flow on the green screen.

--You can set voice commands with "sound_commands". You can also add new ones.

--You can set commands to change the speed of characters with "speed_commands". If you specify a minus for "speed", the flow will be reversed.

--You can set the command to change the text color with "color_commands". Specify with [R, G, B]. "outline_color" is a border color setting with only one dot.

--You can set commands that randomly drop characters with "rain_commands". One of the characters in "drops" will randomly drop from the top for the number of seconds of "time". You can set the initial velocity and acceleration.

What i did

  1. Get YouTube Live chat using ** pychat **
  2. Draw honestly with pygame

~~ At first, I was forced to get a chat with Selenium ~~

Get chat

I was able to afford it by using pychat (thanks). It worked just by passing the ID in the delivery URL.

Sample code


from pytchat import LiveChat
import time

def main()
  chat = LiveChat("Put id here", callback = func)
  while chat.is_alive():
    time.sleep(3)
    #Write your favorite process
   
#If you pass a function to the callback argument, you will receive chats on a regular basis.
def func(data):
  for c in data.items:
    print(f"{c.datetime} [{c.author.name}]-{c.message} {c.amountString}")
    data.tick()

However, there was a bug that python did not quit when it was incorporated into the app.

When I called chat.terminate (), it ended normally.

Draw with pygame

There is a Japanese translation reference, so I did it while looking at it.

--pygame can put both strings and images on Surface objects --I stumbled upon specifying the installed font, so I loaded .ttf directly. --When emoji comes in, it will be killed, so Destroy emoji --Since character edging is not implemented as standard, I used ** here **.

Other features

--Command function --Simply prepare a process for comments that include character strings such as / red --By rewriting json, you can increase the number of commands that play text colors and sounds as you like.

--Play audio --Of course you can do it with pygame --Using the mixer.Sound class for sound effects

--ID input ――Pygame doesn't have familiar input forms and buttons --Display a window to enter ID with tkinter at startup

Finally

--Chat is fun ――It's fun to increase the number of commands as much as you want --The delivery screen is lively and fun

Recommended Posts

I displayed the chat of YouTube Live and tried playing
I tried the asynchronous server of Django 3.0
I tried playing with the image with Pillow
I tried to visualize the age group and rate distribution of Atcoder
I tried to extract and illustrate the stage of the story using COTOHA
I tried to verify and analyze the acceleration of Python by Cython
I tried the pivot table function of pandas
I tried playing with PartiQL and MongoDB connected
I tried to touch the API of ebay
I tried to correct the keystone of the image
I tried morphological analysis and vectorization of words
I read and implemented the Variants of UKR
I tried using the image filter of OpenCV
I tried playing with the calculator on tkinter
I tried to predict the price of ETF
I tried to vectorize the lyrics of Hinatazaka46!
I tried to notify the update of "Hamelin" using "Beautiful Soup" and "IFTTT"
[LIVE] I tried to deliver the sunrise and sunset times nationwide every day
[Introduction to AWS] I tried porting the conversation app and playing with text2speech @ AWS ♪
I tried to summarize the basic form of GPLVM
I tried the MNIST tutorial for beginners of tensorflow.
I checked the default OS and shell of docker-machine
I tried using the API of the salmon data project
I tried to visualize the spacha information of VTuber
I tried to erase the negative part of Meros
I tried the simplest method of multi-label document classification
I tried to classify the voices of voice actors
I tried running the sample code of the Ansible module
I tried to summarize the string operations of Python
[Linux] I learned LPIC lv1 in 10 days and tried to understand the mechanism of Linux.
I tried to notify the update of "Become a novelist" using "IFTTT" and "Become a novelist API"
I tried to automate the article update of Livedoor blog with Python and selenium.
I tried to compare the processing speed with dplyr of R and pandas of Python
I tried to find the entropy of the image with python
[Horse Racing] I tried to quantify the strength of racehorses
I tried to get the location information of Odakyu Bus
I tried to automatically post to ChatWork at the time of deployment with fabric and ChatWork Api
I tried the accuracy of three Stirling's approximations in python
I tried to find the average of the sequence with TensorFlow
I tried refactoring the CNN model of TensorFlow using TF-Slim
I tried face recognition of the laughter problem using Keras.
I tried to get the number of days of the month holidays (Saturdays, Sundays, and holidays) with python
I tried morphological analysis of the general review of Kusoge of the Year
I tried to illustrate the time and time in C language
I tried to verify the yin and yang classification of Hololive members by machine learning
I tried the changefinder library!
I tried programming the chi-square test in Python and Java.
I tried to display the time and today's weather w
[Introduction to infectious disease model] I tried fitting and playing ♬
[Python] I tried to visualize the follow relationship of Twitter
When I tried to install Ubuntu 18.04, "Initramfs unpacking failed: Decoding failed" was displayed and the startup failed.
I tried a little bit of the behavior of the zip function
[Machine learning] I tried to summarize the theory of Adaboost
I want to know the features of Python and pip
[Python] I tried collecting data using the API of wikipedia
I tried to fight the Local Minimum of Goldstein-Price Function
I tried ranking the user name and password of phpMyAdmin that was targeted by the server attack
I became horror when I tried to detect the features of anime faces using PCA and NMF.
I tried to predict the up and down of the closing price of Gurunavi's stock price using TensorFlow (progress)
I tried fitting the exponential function and logistics function to the number of COVID-19 positive patients in Tokyo
I compared the speed of Hash with Topaz, Ruby and Python