Skip to content

Commit 91848d4

Browse files
committed
feat(msg): parse Video elem
1 parent d1306c3 commit 91848d4

File tree

5 files changed

+49
-21
lines changed

5 files changed

+49
-21
lines changed

lagrange/client/message/decoder.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,21 @@ async def parse_msg_new(client: "Client", pkg: MsgPushBody) -> Sequence[Element]
144144
index = extra.body[0].index
145145
uid = client.uid
146146
gid = pkg.response_head.rsp_grp.gid if common.bus_type == 20 else None
147-
url = await client.fetch_image_url(bus_type=cast(Literal[10, 20], common.bus_type),
148-
node=index, uid=uid, gid=gid)
147+
url = await client.fetch_image_url(
148+
bus_type=cast(Literal[10, 20], common.bus_type),
149+
node=index,
150+
uid=uid,
151+
gid=gid,
152+
)
149153
msg_chain.append(
150154
elems.Image(
151155
name=index.info.name,
152156
size=index.info.size,
153157
id=0,
154158
md5=bytes.fromhex(index.info.hash),
155-
text=extra.biz_info.pic.summary if extra.biz_info.pic.summary else "[图片]",
159+
text=extra.biz_info.pic.summary
160+
if extra.biz_info.pic.summary
161+
else "[图片]",
156162
width=index.info.width,
157163
height=index.info.height,
158164
url=url,
@@ -173,23 +179,6 @@ async def parse_msg_new(client: "Client", pkg: MsgPushBody) -> Sequence[Element]
173179
elems.Service(id=sid, raw=content, text=f"[service:{sid}]")
174180
)
175181
ignore_next = True
176-
# elif 16 in raw: # extra
177-
# # nickname = unpack_dict(raw, "16.2", "")
178-
# pass
179-
# elif 19 in raw: # video
180-
# video = raw[19]
181-
# msg_chain.append({
182-
# "type": "video",
183-
# "text": "[视频]",
184-
# "name": unpack_dict(video, "3", "undefined"),
185-
# "id": unpack_dict(video, "1"), # tlv struct? contain md5, filetype
186-
# "md5": unpack_dict(video, "2"),
187-
# "width": unpack_dict(video, "7"),
188-
# "height": unpack_dict(video, "8"),
189-
# "size": unpack_dict(video, "6")
190-
# })
191-
# elif 37 in raw: # unknown
192-
# pass
193182
elif raw.open_data:
194183
msg_chain.append(
195184
elems.Raw(
@@ -247,6 +236,23 @@ async def parse_msg_new(client: "Client", pkg: MsgPushBody) -> Sequence[Element]
247236
# "show_type": typ,
248237
# "id": eid
249238
# })
239+
elif raw.video_file:
240+
video = raw.video_file
241+
242+
msg_chain.append(
243+
elems.Video(
244+
id=0,
245+
time=video.length,
246+
text="[视频]",
247+
name=video.name,
248+
size=video.size,
249+
file_key=video.id,
250+
md5=video.video_md5,
251+
width=video.width,
252+
height=video.height,
253+
qmsg=None,
254+
)
255+
)
250256
else:
251257
pass
252258
# print("unknown msg", raw)

lagrange/client/message/elems.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class Image(Text, MediaInfo):
9494
class Video(Text, MediaInfo):
9595
width: int
9696
height: int
97+
time: int
98+
file_key: str = field(repr=True)
9799

98100

99101
@dataclass

lagrange/client/server_push/msg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
167167
type=body.detail.send_type,
168168
total_operations=body.msg.total_operations,
169169
)
170+
elif pb.flag == 23: # 群幸运字符?
171+
pass
170172
else:
171173
raise ValueError(
172174
f"Unknown subtype_12 flag: {pb.flag}: {pb.body.hex() if pb.body else pb}"

lagrange/pb/message/rich_text/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
SrcMsg,
1818
Text,
1919
TransElem,
20+
VideoFile,
2021
)
2122

2223
__all__ = ["Elems", "RichText"]
@@ -33,7 +34,7 @@ class Elems(ProtoStruct, debug=True):
3334
elem_flags2: Optional[bytes] = proto_field(9, default=None)
3435
rich_msg: Optional[RichMsg] = proto_field(12, default=None)
3536
extra_info: Optional[ExtraInfo] = proto_field(16, default=None)
36-
# video_file: VideoFile = proto_field(19, default=None)
37+
video_file: Optional[VideoFile] = proto_field(19, default=None)
3738
general_flags: Optional[bytes] = proto_field(37, default=None)
3839
open_data: Optional[OpenData] = proto_field(41, default=None)
3940
src_msg: Optional[SrcMsg] = proto_field(45, default=None)

lagrange/pb/message/rich_text/elems.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,20 @@ class CommonElem(ProtoStruct):
131131
service_type: int = proto_field(1)
132132
pb_elem: dict = proto_field(2)
133133
bus_type: int = proto_field(3)
134+
135+
136+
class VideoFile(ProtoStruct):
137+
id: str = proto_field(1)
138+
video_md5: bytes = proto_field(2)
139+
name: str = proto_field(3)
140+
f4: int = proto_field(4) # 2
141+
length: int = proto_field(5) # 100: mp4
142+
size: int = proto_field(6)
143+
width: int = proto_field(7)
144+
height: int = proto_field(8)
145+
thumb_md5: bytes = proto_field(9)
146+
# thumb_name on field 10?
147+
thumb_size: int = proto_field(11)
148+
thumb_width: int = proto_field(16)
149+
thumb_height: int = proto_field(17)
150+
# reserve on field 24?

0 commit comments

Comments
 (0)