mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2026-04-05 06:25:30 +00:00
Added SecretChats.DownloadFile and media.MimeType to simplify download & decryption
This commit is contained in:
parent
82d852e071
commit
b9587e3997
8 changed files with 74 additions and 30 deletions
|
|
@ -91,10 +91,11 @@ Type a command, or a message to send to the active secret chat:");
|
|||
{
|
||||
if (msg.Media != null && unem.message is EncryptedMessage { file: EncryptedFile ef })
|
||||
{
|
||||
Console.WriteLine($"{unem.message.ChatId}> {msg.Message} [file being downloaded to media.jpg]");
|
||||
using var output = File.Create("media.jpg"); // not necessarily a JPG, check the msg.Media mime_type
|
||||
using var decryptStream = new WTelegram.AES_IGE_Stream(output, msg.Media);
|
||||
await Client.DownloadFileAsync(ef, decryptStream, ef.dc_id, ef.size);
|
||||
int slash = msg.Media.MimeType?.IndexOf('/') ?? 0; // quick & dirty conversion from MIME type to file extension
|
||||
var filename = slash > 0 ? $"media.{msg.Media.MimeType[(slash + 1)..]}" : "media.bin";
|
||||
Console.WriteLine($"{unem.message.ChatId}> {msg.Message} [attached file downloaded to {filename}]");
|
||||
using var output = File.Create(filename);
|
||||
await Secrets.DownloadFile(ef, msg.Media, output);
|
||||
}
|
||||
else if (msg.Action == null) Console.WriteLine($"{unem.message.ChatId}> {msg.Message}");
|
||||
else Console.WriteLine($"{unem.message.ChatId}> Service Message {msg.Action.GetType().Name[22..]}");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue