-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
68 lines (47 loc) · 1.39 KB
/
main.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
import time, sys
import re
from termcolor import *
from danmu import DanMuClient
douyu = {'825': '嘉年华火箭', '195': '飞机', '750': '办卡', '193': '弱鸡', '192': '赞',
'826': '嘉年华蛋糕', '824': '粉丝荧光棒', '712': '棒棒哒', '714': '怂', '713': '辣眼睛',
'520': '稳',
'cq': '酬勤'}
# Generate content
def gift_content(msg):
if re.match(r'^(?:http://)?.*?live.bilibili.com/(.+?)$', sys.argv[1]):
msg['Content'] = msg['data']['giftName']
elif re.match(r'^(?:http://)?.*?douyu.com/(.+?)$', sys.argv[1]):
msg['Content'] = msg['gfid']
if msg['Content'] in douyu:
msg['Content'] = douyu[msg['Content']]
else:
pass
# print format
def pd(msg):
if 'nodanmu' not in sys.argv:
print(msg)
def pg(msg):
if 'nogift' not in sys.argv:
print(colored(msg, 'yellow'))
if sys.argv.__len__() is 1:
print('usage: main.py [url] <parameter>')
exit()
# create client
dmc = DanMuClient(sys.argv[1].strip())
if not dmc.isValid():
print('Url not valid')
exit()
# print action
@dmc.danmu
def danmu_fn(msg):
pd('[%s] %s' % (msg['NickName'], msg['Content']))
# pass
@dmc.gift
def gift_fn(msg):
gift_content(msg)
pg('[%s] 赠送了%s' % (msg['NickName'], msg['Content']))
@dmc.other
def other_fn(msg):
pass
print('Connecting...')
dmc.start(blockThread=True)