91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 3KB
    文件類型: .zip
    金幣: 2
    下載: 1 次
    發(fā)布日期: 2021-06-17
  • 語言: Python
  • 標簽: 開源??

資源簡介

bilibili_danmu, B 站直播彈幕姬 Python 版

資源截圖

代碼片段和文件信息

import?asyncio
import?aiohttp
import?xml.dom.minidom
import?random
import?json
from?struct?import?*
import?json
import?config
import?re

class?bilibiliClient():
????def?__init__(self):
????????self._CIDInfoUrl?=?‘http://live.bilibili.com/api/player?id=cid:‘
????????self._roomId?=?0
????????self._ChatPort?=?788
????????self._protocolversion?=?1
????????self._reader?=?0
????????self._writer?=?0
????????self.connected?=?False
????????self._UserCount?=?0
????????self._ChatHost?=?‘livecmt-1.bilibili.com‘

????????self._roomId?=?input(‘請輸入房間號:‘)
????????self._roomId?=?int(self._roomId)

????async?def?connectServer(self):
????????print?(‘正在進入房間。。。。。‘)
????????with?aiohttp.ClientSession()?as?s:
????????????async?with?s.get(‘http://live.bilibili.com/‘?+?str(self._roomId))?as?r:
????????????????html?=?await?r.text()
????????????????m?=?re.findall(r‘ROOMID\s=\s(\d+)‘?html)
????????????????ROOMID?=?m[0]
????????????self._roomId?=?int(ROOMID)
????????????async?with?s.get(self._CIDInfoUrl?+?ROOMID)?as?r:
????????????????xml_string?=?‘‘?+?await?r.text()?+?‘
????????????????dom?=?xml.dom.minidom.parseString(xml_string)
????????????????root?=?dom.documentElement
????????????????server?=?root.getElementsByTagName(‘server‘)
????????????????self._ChatHost?=?server[0].firstChild.data



????????reader?writer?=?await?asyncio.open_connection(self._ChatHost?self._ChatPort)
????????self._reader?=?reader
????????self._writer?=?writer
????????print?(‘鏈接彈幕中。。。。。‘)
????????if?(await?self.SendJoinChannel(self._roomId)?==?True):
????????????self.connected?=?True
????????????print?(‘進入房間成功。。。。。‘)
????????????print?(‘鏈接彈幕成功。。。。。‘)
????????????await?self.ReceiveMessageLoop()

????async?def?HeartbeatLoop(self):
????????while?self.connected?==?False:
????????????await?asyncio.sleep(0.5)

????????while?self.connected?==?True:
????????????await?self.SendSocketData(0?16?self._protocolversion?2?1?““)
????????????await?asyncio.sleep(30)


????async?def?SendJoinChannel(self?channelId):
????????self._uid?=?(int)(100000000000000.0?+?200000000000000.0*random.random())
????????body?=?‘{“roomid“:%s“uid“:%s}‘?%?(channelId?self._uid)
????????await?self.SendSocketData(0?16?self._protocolversion?7?1?body)
????????return?True


????async?def?SendSocketData(self?packetlength?magic?ver?action?param?body):
????????bytearr?=?body.encode(‘utf-8‘)
????????if?packetlength?==?0:
????????????packetlength?=?len(bytearr)?+?16
????????sendbytes?=?pack(‘!IHHII‘?packetlength?magic?ver?action?param)
????????if?len(bytearr)?!=?0:
????????????sendbytes?=?sendbytes?+?bytearr
????????self._writer.write(sendbytes)
????????await?self._writer.drain()


????async?def?ReceiveMessageLoop(self):
????????while?self.connected?==?True:
????????????tmp?=?await?self._reader.read(4)
????????????expr?=?unpack(‘!I‘?tmp)
????????????tmp?=?await?self._reader.read(2)
????????????tmp?=?await?self._reader.read(2)
????????????tmp?=?await?self._reader.read(4)
????????????num?=?unpack(‘!I‘?tmp)

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-07-14?13:43??bilibili_danmu-master\
?????文件??????????50??2017-07-14?13:43??bilibili_danmu-master\.gitignore
?????文件?????????720??2017-07-14?13:43??bilibili_danmu-master\README.md
?????文件????????5796??2017-07-14?13:43??bilibili_danmu-master\bilibiliClient.py
?????文件??????????31??2017-07-14?13:43??bilibili_danmu-master\config.py
?????文件?????????423??2017-07-14?13:43??bilibili_danmu-master\main.py

評論

共有 條評論