伊地知ニジカ放送局だぬ゛ん゛. https://www.youtube.com/@deerjika
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.py 2.6 KiB

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import pygame
  2. from pygame.locals import *
  3. import sys
  4. import pytchat
  5. import time
  6. import random
  7. from talk import Talk
  8. import subprocess
  9. from aques import Aques
  10. from playsound import playsound
  11. from common_module import CommonModule
  12. from youtube import *
  13. class Main:
  14. @classmethod
  15. def main (cls) -> None:
  16. pygame.init ()
  17. screen: pygame.Surface = pygame.display.set_mode ((1024, 768))
  18. balloon = pygame.transform.scale (pygame.image.load ('talking.png'),
  19. (1024, 384))
  20. pygame.mixer.init (frequency = 44100)
  21. noon = pygame.mixer.Sound ('noon.wav')
  22. live_chat = pytchat.create (video_id = YOUTUBE_ID)
  23. system_font = pygame.font.SysFont ('notosanscjkjp', 24, bold = True)
  24. user_font = pygame.font.SysFont ('notosanscjkjp', 32,
  25. italic = True)
  26. nizika_font = pygame.font.SysFont ('07nikumarufont', 50)
  27. while (True):
  28. screen.fill ((0, 255, 0))
  29. if live_chat.is_alive ():
  30. messages: list[str] = [c.message
  31. for c in live_chat.get ().items]
  32. if messages:
  33. message: str = random.choice (messages)
  34. answer: str = Talk.main (message)
  35. screen.blit (balloon, (0, 0))
  36. screen.blit (
  37. user_font.render ('> ' + message, True, (0, 0, 0)),
  38. (120, 70))
  39. screen.blit (
  40. nizika_font.render (answer, True, (192, 0, 0)),
  41. (100, 150))
  42. pygame.display.update ()
  43. noon.play ()
  44. time.sleep (2)
  45. wav: bytearray | None = Aques.main (answer)
  46. if wav is not None:
  47. with open ('./nizika_talking.wav', 'wb') as f:
  48. f.write (wav)
  49. playsound ('./nizika_talking.wav')
  50. time.sleep (10)
  51. else:
  52. live_chat = pytchat.create (video_id = YOUTUBE_ID)
  53. for i in range (4):
  54. screen.blit (
  55. system_font.render (
  56. f'live_chat.is_alive () == {live_chat.is_alive ()}',
  57. True, (0, 0, 0)),
  58. (i % 2, i // 2 * 2))
  59. pygame.display.update ()
  60. for event in pygame.event.get ():
  61. if event.type == QUIT:
  62. pygame.quit ()
  63. sys.exit ()
  64. if __name__ == '__main__':
  65. Main.main ()