Skip to content

Commit

Permalink
PUSH 4 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
MeowDWing authored Aug 23, 2023
1 parent fe9a2bd commit 9de8579
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
3 changes: 3 additions & 0 deletions initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ def _initial():
def settings_initial():

lines = [
'$直播主属性\n',
'rid=34162\n',
'min_level=1\n',
'$API设置\n',
'API_KEY=\n',
'SECRET_KEY=\n',
f'cuid={cuid()}\n'
Expand Down
23 changes: 22 additions & 1 deletion liveget.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import time

import iosetting as ios
import bilibili_api
from bilibili_api import live, sync, user, exceptions
Expand Down Expand Up @@ -40,6 +42,8 @@ def __init__(self, uid: int = -1, rid: int = -1, # id zone
os.system("cls")

# dictionary & list initial zone
self.settings_dict = {}
self.get_settings()
# badge_dict
self.badge_dict = {0: 'Passer'}
self.badge_dict.update({
Expand All @@ -66,6 +70,23 @@ def __init__(self, uid: int = -1, rid: int = -1, # id zone

self.room_event_stream = live.LiveDanmaku(self.room_id)

def get_settings(self):
should_have = set()
should_have.update(['rid', 'min_level'])
with open('./files/settings.txt', mode='r', encoding='utf-8') as f:
lines = f.readlines()

for line in lines:
if line[0] != '$':
line = line.strip().split('=')
if len(line) > 1:
self.settings_dict[line[0]] = line[1]

for i in should_have:
if i not in self.settings_dict.keys():
ios.print_set(f'{i}似乎设置出错了', tag='WARNING')
time.sleep(3)

def living_on(self):

@self.room_event_stream.on('DANMU_MSG')
Expand Down Expand Up @@ -94,7 +115,7 @@ def live_danmaku(self, event: dict = None):
if user_fans_lvl > 20:
print_flag = 'CAPTAIN'
user_title = self.badge_dict[user_fans_lvl]
if len(danmaku_content) > 0:
if len(danmaku_content) > 0 and user_fans_lvl >= int(self.settings_dict['min_level']):
with open('./files/danmaku.txt', mode='a', encoding='utf-8') as f:
f.write(danmaku_content+'\n')

Expand Down
14 changes: 9 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ def caseB():
for line in lines:
line = line.strip().split('=')
if line[0] == 'rid':
rid = line[1]
rid = int(line[1])

print('正在初始化弹幕获取器...')
x = lg.LiveInfoGet(rid=rid)

print("正在启动阅读器...")
os.startfile('reader.py')
if os.path.exists('reader.py'):
os.startfile('reader.py')
else:
os.startfile('reader.exe')

print("正在启动弹幕获取器...")
x.living_on()
Expand All @@ -46,7 +49,7 @@ def caseC():
os.system('cls')
print('|*===================================================================*|\n'
'|*| DANMAKU READER |*|\n'
'|*| main -> 查看 DEMO 1.0 |*|\n'
'|*| main -> 查看 DEMO 1.1 |*|\n'
'|*===================================================================*|\n'
'|*| |*|\n'
'|*| B(b).禁读词列表 S(s).设置文件 |*|\n'
Expand Down Expand Up @@ -78,7 +81,8 @@ def settings():
'API_KEY': None,
'SECRET_KEY': None,
'cuid': None,
'rid': None
'rid': None,
'min_level': None
}
have = set()
with open('./files/settings.txt', mode='r', encoding='utf-8') as f:
Expand Down Expand Up @@ -151,7 +155,7 @@ def main():
os.system('cls')
print('|*===================================================================*|\n'
'|*| DANMAKU READER |*|\n'
'|*| DEMO 1.0 |*|\n'
'|*| DEMO 1.1 |*|\n'
'|*===================================================================*|\n'
'|*| |*|\n'
'|*| A(a).初始化 B(b).启动 C(c).查看 |*|\n'
Expand Down

0 comments on commit 9de8579

Please sign in to comment.