mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
Helpers to download animated photos (DownloadFileAsync + photo.LargestVideoSize)
This commit is contained in:
parent
25990a8477
commit
fa90e236e7
|
|
@ -334,6 +334,18 @@ namespace WTelegram
|
||||||
return await DownloadFileAsync(fileLocation, outputStream, photo.dc_id, photoSize.FileSize, progress);
|
return await DownloadFileAsync(fileLocation, outputStream, photo.dc_id, photoSize.FileSize, progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Download an animated photo from Telegram into the outputStream</summary>
|
||||||
|
/// <param name="photo">The photo to download</param>
|
||||||
|
/// <param name="outputStream">Stream to write the file content to. This method does not close/dispose the stream</param>
|
||||||
|
/// <param name="videoSize">A specific size/version of the animated photo. Use <c>photo.LargestVideoSize</c> to download the largest version of the animated photo</param>
|
||||||
|
/// <param name="progress">(optional) Callback for tracking the progression of the transfer</param>
|
||||||
|
/// <returns>The file type of the photo</returns>
|
||||||
|
public async Task<Storage_FileType> 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);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Download a document from Telegram into the outputStream</summary>
|
/// <summary>Download a document from Telegram into the outputStream</summary>
|
||||||
/// <param name="document">The document to download</param>
|
/// <param name="document">The document to download</param>
|
||||||
/// <param name="outputStream">Stream to write the file content to. This method does not close/dispose the stream</param>
|
/// <param name="outputStream">Stream to write the file content to. This method does not close/dispose the stream</param>
|
||||||
|
|
|
||||||
|
|
@ -348,8 +348,9 @@ namespace TL
|
||||||
protected override InputPhoto ToInputPhoto() => new() { id = id, access_hash = access_hash, file_reference = file_reference };
|
protected override InputPhoto ToInputPhoto() => new() { id = id, access_hash = access_hash, file_reference = file_reference };
|
||||||
public InputPhotoFileLocation ToFileLocation() => ToFileLocation(LargestPhotoSize);
|
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 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 PhotoSizeBase LargestPhotoSize => sizes.Aggregate((agg, next) => (long)next.Width * next.Height > (long)agg.Width * agg.Height ? next : agg);
|
||||||
|
public VideoSize LargestVideoSize => video_sizes?.OfType<VideoSize>().DefaultIfEmpty().Aggregate((agg, next) => (long)next.w * next.h > (long)agg.w * agg.h ? next : agg);
|
||||||
}
|
}
|
||||||
|
|
||||||
partial class PhotoSizeBase
|
partial class PhotoSizeBase
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue