2018-05-13 21:57:36 +08:00
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
from asyncio import get_event_loop
|
|
|
|
|
|
|
|
|
|
from blivedm import BLiveClient
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MyBLiveClient(BLiveClient):
|
|
|
|
|
|
|
|
|
|
async def _on_get_popularity(self, popularity):
|
|
|
|
|
print('当前人气值:', popularity)
|
|
|
|
|
|
|
|
|
|
async def _on_get_danmaku(self, content, user_name):
|
|
|
|
|
print(user_name, '说:', content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2018-05-13 23:49:32 +08:00
|
|
|
|
loop = get_event_loop()
|
2018-05-15 19:31:58 +08:00
|
|
|
|
|
2018-06-02 22:09:55 +08:00
|
|
|
|
# 如果SSL验证失败或连接卡死就把第二个参数设为False
|
|
|
|
|
client = MyBLiveClient(139, True, loop)
|
2018-05-13 23:49:32 +08:00
|
|
|
|
client.start()
|
2018-06-02 22:09:55 +08:00
|
|
|
|
|
|
|
|
|
# 5秒后停止,测试用
|
|
|
|
|
# loop.call_later(5, client.stop, loop.stop)
|
|
|
|
|
# 按Ctrl+C停止
|
|
|
|
|
# import signal
|
|
|
|
|
# signal.signal(signal.SIGINT, lambda signum, frame: client.stop(loop.stop))
|
2018-05-15 19:31:58 +08:00
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
loop.run_forever()
|
|
|
|
|
finally:
|
|
|
|
|
loop.run_until_complete(loop.shutdown_asyncgens())
|
|
|
|
|
loop.close()
|
2018-05-13 21:57:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main()
|