-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Core] Implemented Receiving for VideoEntity.cs
- Loading branch information
Linwenxuan
authored and
Linwenxuan
committed
Feb 2, 2024
1 parent
47e3a5e
commit e7d50c3
Showing
9 changed files
with
218 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Lagrange.Core/Internal/Event/Message/VideoDownloadEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
namespace Lagrange.Core.Internal.Event.Message; | ||
|
||
#pragma warning disable CS8618 | ||
|
||
internal class VideoDownloadEvent : ProtocolEvent | ||
{ | ||
public string AudioUrl { get; } | ||
|
||
public string Uuid { get; } | ||
|
||
public string SelfUid { get; } | ||
|
||
public string FileName { get; } | ||
|
||
public string FileMd5 { get; } | ||
|
||
public string? FileSha1 { get; } | ||
|
||
public bool IsGroup { get; } | ||
|
||
private VideoDownloadEvent(string uuid, string selfUid, string fileName, string fileMd5, string? fileSha1, bool isGroup) : base(true) | ||
{ | ||
Uuid = uuid; | ||
SelfUid = selfUid; | ||
FileName = fileName; | ||
FileSha1 = fileSha1; | ||
IsGroup = isGroup; | ||
FileMd5 = fileMd5; | ||
} | ||
|
||
private VideoDownloadEvent(int resultCode, string audioUrl) : base(resultCode) | ||
{ | ||
AudioUrl = audioUrl; | ||
} | ||
|
||
public static VideoDownloadEvent Create(string uuid, string selfUid, string fileName, string fileMd5, string? fileSha1 = null, bool isGroup = false) | ||
=> new(uuid, selfUid, fileName, fileMd5, fileSha1, isGroup); | ||
|
||
public static VideoDownloadEvent Result(int resultCode, string url) => new(resultCode, url); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0x11E9_200.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using ProtoBuf; | ||
|
||
namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request; | ||
|
||
// ReSharper disable InconsistentNaming | ||
#pragma warning disable CS8618 | ||
|
||
/// <summary> | ||
/// Video Download | ||
/// </summary> | ||
[ProtoContract] | ||
[OidbSvcTrpcTcp(0x11e9, 200)] | ||
internal class OidbSvcTrpcTcp0x11E9_200 | ||
{ | ||
[ProtoMember(1)] public OidbSvcTrpcTcp0x126D_200Field1 Field1 { get; set; } | ||
|
||
[ProtoMember(3)] public OidbSvcTrpcTcp0x126D_200Field3 Field3 { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
Lagrange.Core/Internal/Service/Message/VideoDownloadService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using Lagrange.Core.Common; | ||
using Lagrange.Core.Internal.Event; | ||
using Lagrange.Core.Internal.Event.Message; | ||
using Lagrange.Core.Internal.Packets.Service.Oidb; | ||
using Lagrange.Core.Internal.Packets.Service.Oidb.Request; | ||
using Lagrange.Core.Internal.Packets.Service.Oidb.Response; | ||
using Lagrange.Core.Utility.Binary; | ||
using Lagrange.Core.Utility.Extension; | ||
using ProtoBuf; | ||
|
||
namespace Lagrange.Core.Internal.Service.Message; | ||
|
||
[EventSubscribe(typeof(VideoDownloadEvent))] | ||
[Service("OidbSvcTrpcTcp.0x11e9_200")] | ||
internal class VideoDownloadService : BaseService<VideoDownloadEvent> | ||
{ | ||
protected override bool Build(VideoDownloadEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, | ||
out BinaryPacket output, out List<BinaryPacket>? extraPackets) | ||
{ | ||
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x11E9_200>(new OidbSvcTrpcTcp0x11E9_200 | ||
{ | ||
Field1 = new OidbSvcTrpcTcp0x126D_200Field1 | ||
{ | ||
Field1 = new OidbSvcTrpcTcp0x126D_200Field1Field1 | ||
{ | ||
Field1 = input.IsGroup ? 3u : 34u, | ||
Field2 = 200 | ||
}, | ||
Field2 = new OidbSvcTrpcTcp0x126D_200Field1Field2 | ||
{ | ||
Field1 = 2, | ||
Field2 = 2, | ||
Field3 = 1, | ||
Field201 = new OidbSvcTrpcTcp0x126D_200Field1Field2Field201 | ||
{ | ||
Field1 = 2, | ||
SelfUid = input.SelfUid | ||
} | ||
}, | ||
Field3 = new OidbSvcTrpcTcp0x126D_200Field1Field3 | ||
{ | ||
Field1 = 2 | ||
} | ||
}, | ||
Field3 = new OidbSvcTrpcTcp0x126D_200Field3 | ||
{ | ||
Field1 = new OidbSvcTrpcTcp0x126D_200Field3Field1 | ||
{ | ||
Field1 = new OidbSvcTrpcTcp0x126D_200Field3Field1Field1 | ||
{ | ||
Field1 = 0, | ||
FileHash = input.FileMd5, | ||
FileSha1 = input.FileSha1 ?? "", | ||
FileName = input.FileName, | ||
Field5 = new OidbSvcTrpcTcp0x126D_200Field3Field1Field1Field5 | ||
{ | ||
Field1 = 2, | ||
Field2 = 0, | ||
Field3 = 0, | ||
Field4 = 0 | ||
}, | ||
Field6 = 0, | ||
Field7 = 0, | ||
Field8 = 0, | ||
Field9 = 0 | ||
}, | ||
FileUuid = input.Uuid, | ||
Field3 = 0, | ||
Field4 = 0, | ||
Field5 = 0, | ||
Field6 = 0 | ||
}, | ||
Field2 = new OidbSvcTrpcTcp0x126D_200Field3Field2 | ||
{ | ||
Field2 = new OidbSvcTrpcTcp0x126D_200Field3Field2Field2 | ||
{ | ||
Field1 = 0, | ||
Field2 = 0 | ||
} | ||
} | ||
} | ||
}, false, true); | ||
output = packet.Serialize(); | ||
extraPackets = null; | ||
|
||
return true; | ||
} | ||
|
||
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, out VideoDownloadEvent output, | ||
out List<ProtocolEvent>? extraEvents) | ||
{ | ||
var payload = Serializer.Deserialize<OidbSvcTrpcTcpResponse<OidbSvcTrpcTcp0x1026_200Response>>(input.AsSpan()); | ||
var body = payload.Body.Body; | ||
string url = $"https://{body.Field3.Domain}{body.Field3.Suffix}{body.DownloadParams}"; | ||
|
||
output = VideoDownloadEvent.Result((int)payload.ErrorCode, url); | ||
extraEvents = null; | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters