From fa90e236e704eec061f2942fb613413417d5d506 Mon Sep 17 00:00:00 2001
From: Wizou <11647984+wiz0u@users.noreply.github.com>
Date: Sun, 29 Jun 2025 16:42:27 +0200
Subject: [PATCH] Helpers to download animated photos (DownloadFileAsync +
photo.LargestVideoSize)
---
src/Client.Helpers.cs | 12 ++++++++++++
src/TL.Xtended.cs | 3 ++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/Client.Helpers.cs b/src/Client.Helpers.cs
index eefcd36..a26210d 100644
--- a/src/Client.Helpers.cs
+++ b/src/Client.Helpers.cs
@@ -334,6 +334,18 @@ namespace WTelegram
return await DownloadFileAsync(fileLocation, outputStream, photo.dc_id, photoSize.FileSize, progress);
}
+ /// Download an animated photo from Telegram into the outputStream
+ /// The photo to download
+ /// Stream to write the file content to. This method does not close/dispose the stream
+ /// A specific size/version of the animated photo. Use photo.LargestVideoSize to download the largest version of the animated photo
+ /// (optional) Callback for tracking the progression of the transfer
+ /// The file type of the photo
+ public async Task DownloadFileAsync(Photo photo, Stream outputStream, VideoSize videoSize, ProgressCallback progress = null)
+ {
+ var fileLocation = photo.ToFileLocation(videoSize);
+ return await DownloadFileAsync(fileLocation, outputStream, photo.dc_id, videoSize.size, progress);
+ }
+
/// Download a document from Telegram into the outputStream
/// The document to download
/// Stream to write the file content to. This method does not close/dispose the stream
diff --git a/src/TL.Xtended.cs b/src/TL.Xtended.cs
index 30a2c39..630a370 100644
--- a/src/TL.Xtended.cs
+++ b/src/TL.Xtended.cs
@@ -348,8 +348,9 @@ namespace TL
protected override InputPhoto ToInputPhoto() => new() { id = id, access_hash = access_hash, file_reference = file_reference };
public InputPhotoFileLocation ToFileLocation() => ToFileLocation(LargestPhotoSize);
public InputPhotoFileLocation ToFileLocation(PhotoSizeBase photoSize) => new() { id = id, access_hash = access_hash, file_reference = file_reference, thumb_size = photoSize.Type };
- public InputDocumentFileLocation ToFileLocation(VideoSize videoSize) => new() { id = id, access_hash = access_hash, file_reference = file_reference, thumb_size = videoSize.type };
+ public InputPhotoFileLocation ToFileLocation(VideoSize videoSize) => new() { id = id, access_hash = access_hash, file_reference = file_reference, thumb_size = videoSize.type };
public PhotoSizeBase LargestPhotoSize => sizes.Aggregate((agg, next) => (long)next.Width * next.Height > (long)agg.Width * agg.Height ? next : agg);
+ public VideoSize LargestVideoSize => video_sizes?.OfType().DefaultIfEmpty().Aggregate((agg, next) => (long)next.w * next.h > (long)agg.w * agg.h ? next : agg);
}
partial class PhotoSizeBase