当前位置:网站首页>Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
2022-07-06 15:59:00 【Attrapez le voleur, attrapez le roi en premier.】
RÉFÉRENCES:
- https://zhuanlan.zhihu.com/p/392931611
- https://gitee.com/nbody1996/bilibili-API-collect/blob/master/danmaku/danmaku_proto.md
- Bilibili Rideau d'histoire:https://www.cnblogs.com/mollnn/p/14964905.html
bLe format de transmission du rideau de station est transmis par xml A la place protobuf,Ce format est une transmission codée binaire,Les ventes de transport sont beaucoup plus élevées xml,Par conséquent, il est avantageux de réduire la pression du réseau sur l'extrémité mobile..Mais l'un des problèmes est,Ce format est très difficile à analyser,Généralement à partir de api Les données obtenues sont directement codées.,Il faut des moyens spécifiques pour voir le vrai contenu,Ça fait mal à la tête.
B Station non utilisée protobuf Interface pop - up avant le Protocole
1、Qu'est - ce que Protobuf
Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages.
Ce passage vient de Google Protobuf Introduction au site officiel,C'est simplement un Protocole de transmission,Que xml Plus petit、Plus vite.、Plus simple.,Pour plus d'informations, voir:https://developers.google.com/protocol-buffers/
2、Comment analyser Protobuf Le rideau
2.1 Télécharger Protoc Compilateur
Protoc Est utilisé pour .proto Les fichiers sont compilés dans différents langages de programmation(Par exemple: Python、Golang Attendez.)Compilateur pour,Oui. Protobuf Conditions nécessaires à l'analyse,Disponible en téléchargement sur le lien ci - dessous:https://github.com/protocolbuffers/protobuf


Une fois le téléchargement terminé, décompresser est exe Documentation,Aucune installation requise,Mais doit être ajouté manuellement à Path Moyenne.

Déterminer si l'installation a été réussie en exécutant le code suivant dans le terminal:protoc --version

2.2 Télécharger Protobuf-Python Afin de Python Résolution moyenne Protobuf
Télécharger l'adresse:https://github.com/protocolbuffers/protobuf
Décompresser une fois le téléchargement terminé,Puis entrez python Entrée dans le Répertoire,

Exécutez le Code de ligne de commande suivant:
python setup.py clean
python setup.py build
python setup.py install
python setup.py test2.3 Le rideau proto Définir et compiler
Format du rideau,protobuf Structure:
dm.proto
syntax = "proto3";
package dm;
message DmSegMobileReply{
repeated DanmakuElem elems = 1;
}
message DanmakuElem{
int64 id = 1;
int32 progress = 2;
int32 mode = 3;
int32 fontsize = 4;
uint32 color = 5;
string midHash = 6;
string content = 7;
int64 ctime = 8;
int32 weight = 9;
string action = 10;
int32 pool = 11;
string idStr = 12;
}| Nom | Sens | Type | Remarques |
|---|---|---|---|
| id | Rideau d'obusdmID | int64 | Unique Disponible pour les paramètres de fonctionnement |
| progress | Heure d'apparition de l'écran dans la vidéo | int32 | MS |
| mode | Type de rideau | int32 | 1 2 3:Un écran ordinaire 4:Le rideau inférieur 5:Haut du rideau 6:Écran inversé 7:Haut de gamme 8:Écran de code 9:BASRideau d'obus |
| fontsize | Taille du rideau | int32 | 18:Petit 25:Critères 36:Grand |
| color | Couleur du rideau | uint32 | DécimalRGB888Valeur |
| midHash | ExpéditeurUIDDeHASH | string | Pour masquer l'utilisateur et voir tous les écrans envoyés par l'utilisateur Vous pouvez également inverser la recherche de l'utilisateurID |
| content | Contenu du rideau | string | utf-8Codage |
| ctime | Temps d'envoi du rideau | int64 | Horodatage |
| weight | Poids | int32 | Pour le niveau de blindage intelligent |
| action | Action | string | Inconnu |
| pool | La piscine du rideau | int32 | 0:Piscine ordinaire 1:Sous - titres Pool 2:Piscine spéciale(Code/BASRideau d'obus) |
| idStr | Rideau d'obusdmIDType de chaîne pour | string | Unique Disponible pour les paramètres de fonctionnement |
2.4 Analyse seg.so Format des données d'écran
Exemple de vidéo:https://www.bilibili.com/video/av98919207
Vous devez installer python De probuf Sac: pip install protobuf

Compiler proto Fichier de structure,
protoc --python_out=. dm.protoUne fois l'exécution terminée dm_pb2.py,Introduire ceci dans le Code python Documentation,

dm_pj.py Les codes sont les suivants::
Attention!:
- Écran en temps réel Pas besoin. cookie,Demande directe pour obtenir seg.so
- Rideau d'histoire Besoin cookie Pour obtenir seg.so
# -*- coding: utf-8 -*-
# @Author :
# @Date :
# @File : dm_pj.py
# @description : XXX
import json
import requests
from dm_pb2 import DmSegMobileReply
from google.protobuf.json_format import MessageToJson, Parse
b_web_cookie = 'SESSDATA=fd25e2e6%2C1660373048%2C287c9%2A21;'
def get_date_list():
url = "https://api.bilibili.com/x/v2/dm/history/index?type=1&oid=168855206&month=2022-02"
headers = {
'cookie': b_web_cookie
}
response = requests.get(url, headers=headers)
print(json.dumps(response.json(), ensure_ascii=False, indent=4))
def dm_real_time():
url_real_time = 'https://api.bilibili.com/x/v2/dm/web/seg.so?type=1&oid=168855206&pid=98919207&segment_index=1'
resp = requests.get(url_real_time)
DM = DmSegMobileReply()
DM.ParseFromString(resp.content)
data_dict = json.loads(MessageToJson(DM))
# print(data_dict)
list(map(lambda x=None: print(x['content']), data_dict.get('elems', [])))
def dm_history():
url_history = 'https://api.bilibili.com/x/v2/dm/web/history/seg.so?type=1&oid=168855206&date=2022-02-23'
headers = {
'cookie': b_web_cookie
}
resp = requests.get(url_history, headers=headers)
DM = DmSegMobileReply()
DM.ParseFromString(resp.content)
data_dict = json.loads(MessageToJson(DM))
# print(data_dict)
list(map(lambda x=None: print(x['content']), data_dict.get('elems', [])))
if __name__ == '__main__':
# dm_real_time()
get_date_list()
# dm_history()
pass
Capture d'écran des résultats de l'exécution:

Comparaison des écrans:

边栏推荐
- Determine the Photo Position
- Cost accounting [13]
- 信息安全-安全专业名称|CVE|RCE|POC|VUL|0DAY
- Perinatal Software Industry Research Report - market status analysis and development prospect forecast
- Alice and Bob (2021牛客暑期多校训练营1)
- [exercise-7] crossover answers
- Shell脚本编程
- 毕业才知道IT专业大学生毕业前必做的1010件事
- Optimization method of path problem before dynamic planning
- China potato slicer market trend report, technical dynamic innovation and market forecast
猜你喜欢

Nodejs+vue online fresh flower shop sales information system express+mysql

Information security - Analysis of security orchestration automation and response (soar) technology

Penetration test (2) -- penetration test system, target, GoogleHacking, Kali tool

Borg Maze (BFS+最小生成树)(解题报告)

Gartner: five suggestions on best practices for zero trust network access

Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools

Information security - threat detection engine - common rule engine base performance comparison
![[analysis of teacher Gao's software needs] collection of exercises and answers for level 20 cloud class](/img/3b/dc43564a36f82e73826b08f39c935e.png)
[analysis of teacher Gao's software needs] collection of exercises and answers for level 20 cloud class

渗透测试 2 --- XSS、CSRF、文件上传、文件包含、反序列化漏洞

信息安全-威胁检测-NAT日志接入威胁检测平台详细设计
随机推荐
【练习-11】4 Values whose Sum is 0(和为0的4个值)
Cost accounting [16]
通俗地理解什么是编程语言
渗透测试 2 --- XSS、CSRF、文件上传、文件包含、反序列化漏洞
初入Redis
Penetration test (3) -- Metasploit framework (MSF)
CEP used by Flink
【练习-8】(Uva 246)10-20-30==模拟
Shell脚本编程
用C语言写网页游戏
【练习-7】(Uva 10976)Fractions Again?!(分数拆分)
【练习-5】(Uva 839)Not so Mobile(天平)
Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
Perform general operations on iptables
Cost accounting [13]
D - Function(HDU - 6546)女生赛
China earth moving machinery market trend report, technical dynamic innovation and market forecast
b站 实时弹幕和历史弹幕 Protobuf 格式解析
Penetration test (7) -- vulnerability scanning tool Nessus
Information security - threat detection - Flink broadcast stream broadcaststate dual stream merging application in filtering security logs