Update DataResult.cs
- adding DownloadAudio - adding an optional method for all available ones to save attachments directly to a file
This commit is contained in:
parent
f914920919
commit
7a3e4721bd
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -108,14 +109,49 @@ namespace TelegramBotBase.Base
|
|||||||
return new InputOnlineFile(encryptedContent, this.Document.FileName);
|
return new InputOnlineFile(encryptedContent, this.Document.FileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task DownloadDocument(String path)
|
||||||
|
{
|
||||||
|
var file = await this.Client.TelegramClient.GetFileAsync(this.Document.FileId);
|
||||||
|
FileStream fs = new FileStream(path, FileMode.Create);
|
||||||
|
await this.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||||
|
fs.Close();
|
||||||
|
fs.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<InputOnlineFile> DownloadVideo()
|
public async Task<InputOnlineFile> DownloadVideo()
|
||||||
{
|
{
|
||||||
var encryptedContent = new System.IO.MemoryStream(this.Video.FileSize);
|
var encryptedContent = new System.IO.MemoryStream(this.Video.FileSize);
|
||||||
var file = await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Video.FileId, encryptedContent);
|
var file = await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Video.FileId, encryptedContent);
|
||||||
|
|
||||||
|
return new InputOnlineFile(encryptedContent, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DownloadVideo(String path)
|
||||||
|
{
|
||||||
|
var file = await this.Client.TelegramClient.GetFileAsync(this.Video.FileId);
|
||||||
|
FileStream fs = new FileStream(path, FileMode.Create);
|
||||||
|
await this.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||||
|
fs.Close();
|
||||||
|
fs.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<InputOnlineFile> DownloadAudio()
|
||||||
|
{
|
||||||
|
var encryptedContent = new System.IO.MemoryStream(this.Audio.FileSize);
|
||||||
|
var file = await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Audio.FileId, encryptedContent);
|
||||||
|
|
||||||
return new InputOnlineFile(encryptedContent, "");
|
return new InputOnlineFile(encryptedContent, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task DownloadAudio(String path)
|
||||||
|
{
|
||||||
|
var file = await this.Client.TelegramClient.GetFileAsync(this.Audio.FileId);
|
||||||
|
FileStream fs = new FileStream(path, FileMode.Create);
|
||||||
|
await this.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||||
|
fs.Close();
|
||||||
|
fs.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<InputOnlineFile> DownloadPhoto(int index)
|
public async Task<InputOnlineFile> DownloadPhoto(int index)
|
||||||
{
|
{
|
||||||
var photo = this.Photos[index];
|
var photo = this.Photos[index];
|
||||||
@ -125,5 +161,15 @@ namespace TelegramBotBase.Base
|
|||||||
return new InputOnlineFile(encryptedContent, "");
|
return new InputOnlineFile(encryptedContent, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task DownloadPhoto(int index, String path)
|
||||||
|
{
|
||||||
|
var photo = this.Photos[index];
|
||||||
|
var file = await this.Client.TelegramClient.GetFileAsync(photo.FileId);
|
||||||
|
FileStream fs = new FileStream(path, FileMode.Create);
|
||||||
|
await this.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||||
|
fs.Close();
|
||||||
|
fs.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user