diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..59fb926 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*/__pycache__/ \ No newline at end of file diff --git a/README.md b/README.md index 40c869b..078fcdb 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ **26** 个直播平台的直播源获取:斗鱼直播、虎牙直播、哔哩哔哩直播、战旗直播、网易 CC 直播、火猫直播、企鹅电竞、YY 直播、一直播、快手直播、花椒直播、映客直播、西瓜直播、触手直播、NOW 直播、抖音直播,爱奇艺直播、酷狗直播、龙珠直播、PPS 奇秀直播、六间房、17 直播、来疯直播、优酷轮播台、网易 look 直播、千帆直播。 - **4** 个直播平台的弹幕获取:斗鱼直播、虎牙直播、哔哩哔哩直播、快手直播。 + **5** 个直播平台的弹幕获取:斗鱼直播、虎牙直播、哔哩哔哩直播、快手直播、火猫直播。 ## 运行 @@ -23,7 +23,9 @@ ## 更新 -### 2020.06.18:新增弹幕功能 +### 2020.06.19:新增火猫直播弹幕获取 + +2020.06.18:新增弹幕功能 - 添加斗鱼、虎牙、哔哩哔哩和快手 4 个平台的弹幕获取。后续添加其他平台。 - 实现弹幕功能的代码和思路主要来自:[danmaku](https://github.com/IsoaSFlus/danmaku) 和 [ks_barrage](https://github.com/py-wuhao/ks_barrage),感谢两位大佬! diff --git a/danmu/danmaku/__init__.py b/danmu/danmaku/__init__.py index 9e3cee7..cd26fa4 100644 --- a/danmu/danmaku/__init__.py +++ b/danmu/danmaku/__init__.py @@ -6,6 +6,7 @@ from .bilibili import Bilibili from .douyu import Douyu from .huya import Huya from .kuaishou import KuaiShou +from .huomao import HuoMao __all__ = ['DanmakuClient'] @@ -26,7 +27,8 @@ class DanmakuClient: for u, s in {'douyu.com': Douyu, 'live.bilibili.com': Bilibili, 'huya.com': Huya, - 'kuaishou.com': KuaiShou}.items(): + 'huomao.com': HuoMao, + 'kuaishou.com': KuaiShou,}.items(): if re.match(r'^(?:http[s]?://)?.*?%s/(.+?)$' % u, url): self.__site = s break diff --git a/danmu/danmaku/__pycache__/__init__.cpython-38.pyc b/danmu/danmaku/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 701c26a..0000000 Binary files a/danmu/danmaku/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/danmu/danmaku/__pycache__/bilibili.cpython-38.pyc b/danmu/danmaku/__pycache__/bilibili.cpython-38.pyc deleted file mode 100644 index ed65ea8..0000000 Binary files a/danmu/danmaku/__pycache__/bilibili.cpython-38.pyc and /dev/null differ diff --git a/danmu/danmaku/__pycache__/douyu.cpython-38.pyc b/danmu/danmaku/__pycache__/douyu.cpython-38.pyc deleted file mode 100644 index 296c315..0000000 Binary files a/danmu/danmaku/__pycache__/douyu.cpython-38.pyc and /dev/null differ diff --git a/danmu/danmaku/__pycache__/huya.cpython-38.pyc b/danmu/danmaku/__pycache__/huya.cpython-38.pyc deleted file mode 100644 index f01a694..0000000 Binary files a/danmu/danmaku/__pycache__/huya.cpython-38.pyc and /dev/null differ diff --git a/danmu/danmaku/__pycache__/kuaishou.cpython-38.pyc b/danmu/danmaku/__pycache__/kuaishou.cpython-38.pyc deleted file mode 100644 index fdc23c6..0000000 Binary files a/danmu/danmaku/__pycache__/kuaishou.cpython-38.pyc and /dev/null differ diff --git a/danmu/danmaku/huomao.py b/danmu/danmaku/huomao.py new file mode 100644 index 0000000..43a5709 --- /dev/null +++ b/danmu/danmaku/huomao.py @@ -0,0 +1,49 @@ +import struct +import aiohttp +import json + + +class HuoMao: + heartbeat = b'\x00\x00\x00\x10\x00\x10\x00\x01\x00\x00\x00\x02\x00\x00\x00\x01' + # heartbeat = struct.pack('!ihhii', 16,16,1,2,1) + heartbeatInterval = 30 + + @staticmethod + async def get_ws_info(url): + goim = 'http://www.huomao.com/ajax/goimConf?type=h5' + headers = { + 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, ' + 'like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'} + async with aiohttp.ClientSession() as session: + async with session.get(goim, headers=headers) as resp: + info = json.loads(await resp.text()) + webSocketUrls = info.get('host_wss', 0) + rid = int(url.split('/')[-1]) + reg_datas = [] + tokenBody = json.dumps({"Uid": 0, "Rid": rid}, separators=(',', ':')) + bodyBuf = tokenBody.encode('ascii') + headerBuf = struct.pack('!ihhii', (16 + len(bodyBuf)), 16, 1, 7, 1) + data = headerBuf + bodyBuf + reg_datas.append(data) + return webSocketUrls, reg_datas + + @staticmethod + def decode_msg(data): + packetLen, headerLen, ver, op, seq = struct.unpack('!ihhii', data[0:16]) + msgs = [] + msg = {'name': '', 'content': '', 'msg_type': 'other'} + if op == 5: + offset = 0 + while offset < len(data): + packetLen, headerLen, ver = struct.unpack('!ihh', data[offset:(offset + 8)]) + msgBody = data[offset + headerLen:offset + packetLen] + offset += packetLen + body = json.loads(msgBody.decode('utf8')) + if body.get('code', 0) == '100001': + msg['name'] = body['speak']['user']['name'] + msg['content'] = body['speak']['barrage']['msg'] + msg['msg_type'] = 'danmaku' + msgs.append(msg.copy()) + return msgs + msgs.append(msg) + return msgs diff --git a/danmu/danmaku/tars/__pycache__/__init__.cpython-38.pyc b/danmu/danmaku/tars/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 799222d..0000000 Binary files a/danmu/danmaku/tars/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/danmu/danmaku/tars/__pycache__/__packet.cpython-38.pyc b/danmu/danmaku/tars/__pycache__/__packet.cpython-38.pyc deleted file mode 100644 index 8252029..0000000 Binary files a/danmu/danmaku/tars/__pycache__/__packet.cpython-38.pyc and /dev/null differ diff --git a/danmu/danmaku/tars/__pycache__/__tars.cpython-38.pyc b/danmu/danmaku/tars/__pycache__/__tars.cpython-38.pyc deleted file mode 100644 index 59cc6f5..0000000 Binary files a/danmu/danmaku/tars/__pycache__/__tars.cpython-38.pyc and /dev/null differ diff --git a/danmu/danmaku/tars/__pycache__/__tup.cpython-38.pyc b/danmu/danmaku/tars/__pycache__/__tup.cpython-38.pyc deleted file mode 100644 index 762d73c..0000000 Binary files a/danmu/danmaku/tars/__pycache__/__tup.cpython-38.pyc and /dev/null differ diff --git a/danmu/danmaku/tars/__pycache__/__util.cpython-38.pyc b/danmu/danmaku/tars/__pycache__/__util.cpython-38.pyc deleted file mode 100644 index ecb77c6..0000000 Binary files a/danmu/danmaku/tars/__pycache__/__util.cpython-38.pyc and /dev/null differ diff --git a/danmu/danmaku/tars/__pycache__/exception.cpython-38.pyc b/danmu/danmaku/tars/__pycache__/exception.cpython-38.pyc deleted file mode 100644 index 6b63689..0000000 Binary files a/danmu/danmaku/tars/__pycache__/exception.cpython-38.pyc and /dev/null differ