2 Star 16 Fork 13

Nianwei/抖音弹幕无人直播游戏弹幕获取源码

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
danmu.py 5.09 KB
一键复制 编辑 原始数据 按行查看 历史
Nianwei 提交于 2022-04-24 12:48 . 弹幕互动
import json
import requests
from google.protobuf.json_format import MessageToDict
import base64
from test_pb2 import *
import mitmproxy.http
from bs4 import BeautifulSoup
import urllib.parse
import emoji
import configparser
def get_html(data, cont, leixin):
html4 = requests.post("https://www.douyin.com/user/" + data)
soup = BeautifulSoup(html4.text, 'lxml')
shuju = soup.find("script", type="application/json").text
shuju1 = json.loads(urllib.parse.unquote(shuju),strict=False)
mingzi = shuju1['37']['user']['user']['nickname']
uid1 = shuju1['37']['user']['user']['secUid']
zongfensi = shuju1['37']['user']['user']['mplatformFollowersCount']
share = shuju1['37']['user']['user']['shareQrcodeUrl']
guanzhu = shuju1['37']['user']['user']['followingCount']
userid = shuju1['37']['user']['user']['uniqueId']
if leixin == 1:
file = open("ax.txt", 'a',encoding='utf8')
text = str(str(emoji.demojize(mingzi)) + "====" + str(uid1) + "====" + str(zongfensi) + "====" + str(
share) + "====" + str(guanzhu) + "====" + str(userid) + "====" + str(cont))
file.write(text + '\n')
file.close()
elif leixin == 2:
file = open("ax.txt", 'a',encoding='utf8')
text = str(str(emoji.demojize(mingzi)) + "====" + str(uid1) + "====" + str(zongfensi) + "====" + str(
share) + "====" + str(guanzhu) + "====" + str(userid) + "====" + str(cont))
file.write(text + '\n')
file.close()
elif leixin == 3:
file = open("ax.txt", 'a',encoding='utf8')
text = str(str(emoji.demojize(mingzi)) + "====" + str(uid1) + "====" + str(zongfensi) + "====" + str(
share) + "====" + str(guanzhu) + "====" + str(userid) + "====" + str(cont))
file.write(text + '\n')
file.close()
elif leixin == 4:
file = open("ax.txt", 'a',encoding='utf8')
text = str(str(emoji.demojize(mingzi)) + "====" + str(uid1) + "====" + str(zongfensi) + "====" + str(
share) + "====" + str(guanzhu) + "====" + str(userid) + "====" + str(emoji.demojize(cont)))
file.write(text + '\n')
file.close()
def on_message(data):
cf = configparser.ConfigParser()
cf.read("config.ini")
danmu_resp = test()
danmu_resp.ParseFromString(data)
message = MessageToDict(danmu_resp, preserving_proto_field_name=True)
for message in message['message']:
method = message["method"]
payload = bytes(base64.b64decode(message["payload"].encode()))
if method == "WebcastMemberMessage":
member_message = WebcastMemberMessage()
member_message.ParseFromString(payload)
obj1 = MessageToDict(member_message, preserving_proto_field_name=True)
val = cf.getint("config", "room")
if val == 1:
print("欢迎:" + obj1['user'][0]['nickname'] + "加入直播间"+"---------")
get_html(obj1['user'][0]['secUid'], "加入直播间", 1)
elif val == 0:
print("欢迎:" + obj1['user'][0]['nickname'] + "加入直播间" )
elif method == "WebcastGiftMessage":
member_message3 = WebcastGiftMessage()
member_message3.ParseFromString(payload)
obj3 = MessageToDict(member_message3, preserving_proto_field_name=True)
jiexi2 = obj3
print(jiexi2['common'][0]['describe'])
val = cf.getint("config", "gif")
if val == 1:
get_html(jiexi2['user'][0]['secUid'], "礼物消息", 2)
print(jiexi2['user'][0]['nickname'])
elif val==0:
print(jiexi2['user'][0]['nickname'])
elif method == "WebcastLikeMessage":
member_message4 = WebcastLikeMessage()
member_message4.ParseFromString(payload)
obj4 = MessageToDict(member_message4, preserving_proto_field_name=True)
jiexi = obj4
val = cf.getint("config", "like")
if val == 1:
get_html(jiexi['user'][0]['secUid'], "点赞消息", 3)
print(jiexi['user'][0]['nickname'] + "点赞了主播")
elif val==0:
print(jiexi['user'][0]['nickname'] + "点赞了主播")
elif method == "WebcastChatMessage":
member_message5 = WebcastChatMessage()
member_message5.ParseFromString(payload)
obj5 = MessageToDict(member_message5, preserving_proto_field_name=True)
jiexi1 = obj5
val = cf.getint("config", "chat")
if val == 1:
get_html(jiexi1['user'][0]['secUid'], jiexi1['content'], 4)
print(jiexi1['user'][0]['nickname'] + ":" + jiexi1['content'] )
elif val ==0 :
print(jiexi1['user'][0]['nickname'] + ":" + jiexi1['content'] )
class Counter:
def response(self, flow: mitmproxy.http.HTTPFlow):
if flow.request.host == "live.douyin.com":
data = flow.response.content
on_message(data)
addons = [
Counter()
]
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/weiliang_1_710580513/douyin.git
git@gitee.com:weiliang_1_710580513/douyin.git
weiliang_1_710580513
douyin
抖音弹幕无人直播游戏弹幕获取源码
master

搜索帮助