-
Notifications
You must be signed in to change notification settings - Fork 1
/
原生弹幕基.py
217 lines (210 loc) · 6.12 KB
/
原生弹幕基.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import pygame
from langconv import *
import sys
import requests
import time
def cht_to_chs(line):
line = Converter('zh-hans').convert(line)
line.encode('utf-8')
return line
def chs_to_cht(line):
line = Converter('zh-hant').convert(line)
line.encode('utf-8')
return line
##############################################################################
def Put_Out(m,n):
n_1 = word_type.render(b[-i][m * l:((m + 1) * l)], True, word_color)
h = int(n * 1.5 * size)
screen.blit(n_1, (0, h))
return(m+1 ,n+1)
def Put_Out_2(m,n,v,Tick):
n_1 = word_type.render(b[-i-1][m * l:((m + 1) * l)], True, word_color)
h = int(n * 1.5 * size+v*Tick)
screen.blit(n_1, (0, h))
return(m+1 ,n+1)
def move(i,n,v,Tick):
m = 0
w_n = len(b[-i-1])
if w_n < l:
m, n = Put_Out_2(m, n, v, Tick)
elif w_n < 2 * l:
m, n = Put_Out_2(m, n, v, Tick)
m, n = Put_Out_2(m, n, v, Tick)
else:
m, n = Put_Out_2(m, n, v, Tick)
m, n = Put_Out_2(m, n, v, Tick)
m, n = Put_Out_2(m, n, v, Tick)
return (i+1,n+1)
def judge (i , n):
m = 0
w_n = len(b[-i])
if w_n < l:
m, n = Put_Out(m, n)
elif w_n < 2 * l:
m, n = Put_Out(m, n)
m, n = Put_Out(m, n)
else:
m, n = Put_Out(m, n)
m, n = Put_Out(m, n)
m, n = Put_Out(m, n)
return (i+1,n+1)
###############################################################################
def edge_judge(a, b, c):
while a > b:
return int(input(c))
else:
return a
headers={
'Content-Type':'application/x-www-form-urlencoded',
'Origin': 'https://live.bilibili.com',
'Referer':'https://live.bilibili.com/5225369?spm_id_from=333.334.b_62696c695f6c697665.5',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36',
}
new =''
av=input('room number: ')
data={
'roomid': av,
'csrf_token': 'fa56950667934cf5a3479ca94abc1f9a',
'csrf': 'fa56950667934cf5a3479ca94abc1f9a',
'visit_id': '',
}
url='https://api.live.bilibili.com/ajax/msg'
j=0
while True:
try:
size=int(input("选择字体大小(0~64):"))
size=edge_judge(size, 64, "选择字体大小(0~64):")
break
except :
j=0
while True:
try:
s=int(input('选择窗口宽(宽高1:2): '))
s=edge_judge(s,9999,'选择窗口大小: ')
break
except:
j=0
print("颜色调节仅支持红绿蓝的深度(0~255)")
print("例如需要青色则 红=0 绿=255 蓝=255")
while True:
try:
word_color_r = int(input("字体颜色红:"))
word_color_r=edge_judge(word_color_r, 255, "字体颜色红:")
break
except :
j=0
while True:
try:
word_color_g = int(input("字体颜色绿:"))
word_color_g= edge_judge(word_color_g, 255, "字体颜色绿:")
break
except :
j=0
while True:
try:
word_color_b = int(input("字体颜色蓝:"))
word_color_b=edge_judge(word_color_b,255,"字体颜色蓝:")
break
except :
j=0
word_color = [word_color_r,word_color_g,word_color_b]
while True:
try:
bg_color_r = int(input('背景颜色红:'))
bg_color_r=edge_judge(bg_color_r,255,'背景颜色红:')
break
except :
j=0
while True:
try:
bg_color_g = int(input('背景颜色绿:'))
bg_color_g = edge_judge(bg_color_g,255,'背景颜色绿:')
break
except :
j=0
while True:
try:
bg_color_b = int(input('背景颜色蓝:'))
bg_color_b = edge_judge(bg_color_b,255,'背景颜色蓝:')
break
except :
j=0
while True:
try:
num=int(input('选择保留弹幕数量(仅支持1~8):'))
num=edge_judge(num,8,'选择保留弹幕数量(仅支持1~8):')
break
except :
j=0
bg_color = [bg_color_r,bg_color_g,bg_color_b]
pygame.init()
screen = pygame.display.set_mode((s, 2*s))
clock = pygame.time.Clock()
pygame.display.set_caption('弹幕基')
k='' #刷新检测标准
tick = int(input('请输入动画完成帧数')) #动画帧数控制
Tick = 0 #动画循环计数
# 输出设置模块
word_type = pygame.font.SysFont('华文仿宋',size) # 选择输出字体
l = int(s/ size) # 长度检测
v = 2*(size * 1.5)/tick
print('已经开始运行')
while True:
time.sleep(0.1)
#爬取弹幕模块
response=requests.post(url=url,headers=headers,data=data)
dic_data=response.json()
content=[item['text'] for item in dic_data['data']['room']]
screen.fill(bg_color)
b = content
#刷新检测
if k!=b[-1]:
while Tick <= tick:
screen.fill(bg_color)
i=0
n=-2
if num>0:
i,n=move(i,n,v,Tick)
if num>1:
i,n=move(i,n,v,Tick)
if num>2:
i,n=move(i,n,v,Tick)
if num>3:
i,n=move(i,n,v,Tick)
if num>4:
i,n=move(i,n,v,Tick)
if num>5:
i,n=move(i,n,v,Tick)
if num>6:
i,n=move(i,n,v,Tick)
if num>7:
i,n=move(i,n,v,Tick)
Tick+=1
pygame.display.update()
k=b[-1]
Tick = 0
else:
n = 0 # 高度计数
i = 1 # 弹幕计数
#输出模块
if num>0:
i,n=judge(i,n)
if num>1:
i, n = judge(i, n)
if num>2:
i, n = judge(i, n)
if num>3:
i, n = judge(i, n)
if num>4:
i, n = judge(i, n)
if num>5:
i, n = judge(i, n)
if num>6:
i, n = judge(i, n)
if num>7:
i, n = judge(i, n)
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
sys.exit()
pygame.display.update()