-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader.py
48 lines (40 loc) · 1.27 KB
/
reader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
import pygame
import live_function.audioplay as player
import time
from collections import deque
class Reader:
def __init__(self):
self.danmaku_queue = deque()
self.danmaku_len = 0
player.initial()
def reader(self):
print('[read]wait initial')
time.sleep(1)
while True:
with open('./files/danmaku.txt', mode='r', encoding='utf-8') as f:
lines = f.readlines()
with open('./files/danmaku.txt', mode='w', encoding='utf-8'):
pass
if len(lines) != 0:
for line in lines:
line = line.strip()
self.danmaku_queue.append(line)
self.danmaku_len += 1
print(self.danmaku_queue)
if self.danmaku_len != 0:
now = self.danmaku_queue.popleft()
print(now)
self.danmaku_len -= 1
try:
player.play('./audio/'+now+'.mp3')
except pygame.error:
print('bad stream')
player.delete('./audio/'+now+'.mp3')
else:
time.sleep(3)
def main():
read = Reader()
read.reader()
if __name__ == '__main__':
main()