|
@@ -0,0 +1,80 @@
|
|
|
+import asyncio
|
|
|
+import json
|
|
|
+import argparse
|
|
|
+import os
|
|
|
+import time
|
|
|
+import traceback
|
|
|
+
|
|
|
+from bilibili_api import settings
|
|
|
+
|
|
|
+from core.listener import Listener
|
|
|
+from core.recorder import Recorder
|
|
|
+import aiohttp
|
|
|
+import bilibili_api
|
|
|
+
|
|
|
+ROOM_DISPLAY_ID=22647787
|
|
|
+
|
|
|
+def print_json(data):
|
|
|
+ print(json.dumps(data, sort_keys=True, indent=4, separators=(', ', ': '), ensure_ascii=False))
|
|
|
+
|
|
|
+def startRecoder(_id,outputNameTemplate):
|
|
|
+ print('监听到房间'+str(_id)+'正在直播,开始录制!')
|
|
|
+ Recorder(_id).start(outputNameTemplate,True)
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ parser = argparse.ArgumentParser()
|
|
|
+ parser.add_argument("ids",type=int,nargs="+")
|
|
|
+ parser.add_argument("--file-name-template",type=str,default='【${qn_desc}】${name} - ${datetime}')
|
|
|
+ parser.add_argument("--log",type=bool,default=True)
|
|
|
+
|
|
|
+ args = parser.parse_args()
|
|
|
+
|
|
|
+ print('启动中...')
|
|
|
+
|
|
|
+ proxy = os.getenv("https_proxy") or os.getenv("http_proxy")
|
|
|
+
|
|
|
+ if proxy!=None:
|
|
|
+ settings.proxy = proxy
|
|
|
+
|
|
|
+ while True:
|
|
|
+ try:
|
|
|
+ listener = Listener()
|
|
|
+ for _id in args.ids:
|
|
|
+ print('正在设置对房间'+str(_id)+'的监听...')
|
|
|
+ try:
|
|
|
+ listener.add(_id,lambda :startRecoder(_id,args.file_name_template))
|
|
|
+ except bilibili_api.exceptions.ResponseCodeException as e:
|
|
|
+ if e.code == 60004:
|
|
|
+ print('房间'+str(_id)+'不存在!')
|
|
|
+ elif e.code == 403:
|
|
|
+ raise e
|
|
|
+ except bilibili_api.exceptions.NetworkException as e:
|
|
|
+ print('网络错误:',end='')
|
|
|
+ print(e)
|
|
|
+ time.sleep(1)
|
|
|
+ except aiohttp.client_exceptions.ClientConnectorError as e:
|
|
|
+ print('网络错误:',end='')
|
|
|
+ print(e)
|
|
|
+ time.sleep(1)
|
|
|
+ except bilibili_api.exceptions.ResponseCodeException as e:
|
|
|
+ if(e.code == 403):
|
|
|
+ print('获取直播间信息权限被禁止,将于30分钟后重试...')
|
|
|
+ time.sleep(1800)
|
|
|
+ print('正在重新尝试获取直播间信息...')
|
|
|
+ else:
|
|
|
+ time.sleep(1)
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ asyncio.get_event_loop().stop()
|
|
|
+ time.sleep(60)
|
|
|
+ else:
|
|
|
+ print('启动完毕')
|
|
|
+ asyncio.get_event_loop().run_forever()
|
|
|
+
|
|
|
+ # listener = Listener()
|
|
|
+ # for _id in args.ids:
|
|
|
+ # print('正在设置对房间'+str(_id)+'的监听...')
|
|
|
+ # listener.add(_id,lambda :startRecoder(_id,args.file_name_template))
|
|
|
+ # print('启动完毕')
|
|
|
+ # asyncio.get_event_loop().run_forever()
|