|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- import pygame
- from pygame.locals import *
- import sys
- import pytchat
- import time
- import random
- from talk import Talk
- import subprocess
- from aques import Aques
- from playsound import playsound
- from common_module import CommonModule
- from youtube import *
- from datetime import datetime
-
-
- class Main:
- @classmethod
- def main (cls) -> None:
- pygame.init ()
- screen: pygame.Surface = pygame.display.set_mode ((1024, 768))
- balloon = pygame.transform.scale (pygame.image.load ('talking.png'),
- (1024, 384))
- pygame.mixer.init (frequency = 44100)
- noon = pygame.mixer.Sound ('noon.wav')
-
- live_chat = pytchat.create (video_id = YOUTUBE_ID)
-
- system_font = pygame.font.SysFont ('notosanscjkjp', 24, bold = True)
- user_font = pygame.font.SysFont ('notosanscjkjp', 32,
- italic = True)
- nizika_font = pygame.font.SysFont ('07nikumarufont', 50)
-
- while (True):
- screen.fill ((0, 255, 0))
-
- if live_chat.is_alive ():
- messages: list[str] = [c.message
- for c in live_chat.get ().items]
-
- if messages:
- message: str = random.choice (messages)
- answer: str = Talk.main (message)
-
- screen.blit (balloon, (0, 0))
- screen.blit (
- user_font.render (
- '> ' + (message
- if (CommonModule.len_by_full (message)
- <= 21)
- else (CommonModule.mid_by_full (
- message, 0, 19.5)
- + '...')), True, (0, 0, 0)),
- (120, 70))
- screen.blit (
- nizika_font.render (answer, True, (192, 0, 0)),
- (100, 150))
-
- pygame.display.update ()
-
- noon.play ()
-
- time.sleep (2)
-
- wav: bytearray | None = Aques.main (answer)
- if wav is not None:
- with open ('./nizika_talking.wav', 'wb') as f:
- f.write (wav)
-
- playsound ('./nizika_talking.wav')
-
- time.sleep (10)
- else:
- live_chat = pytchat.create (video_id = YOUTUBE_ID)
-
- for i in range (4):
- screen.blit (
- system_font.render (
- f'live_chat.is_alive () == {live_chat.is_alive ()}',
- True, (0, 0, 0)),
- (i % 2, i // 2 * 2))
- screen.blit (
- system_font.render (str (datetime.now ()), True, (0, 0, 0)),
- (i % 2, 32 + i // 2 * 2))
-
- if live_chat.is_alive ():
- screen.blit (
- system_font.render (
- f'messages == {messages}',
- True, (0, 0, 0)),
- (i % 2, 64 + i // 2 * 2))
-
- pygame.display.update ()
-
- for event in pygame.event.get ():
- if event.type == QUIT:
- pygame.quit ()
- sys.exit ()
-
-
- if __name__ == '__main__':
- Main.main ()
-
|