mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
Examples for download abort, and uploading streamable video (fix #325, thx @patelriki13)
Some checks failed
Dev build / build (push) Has been cancelled
Some checks failed
Dev build / build (push) Has been cancelled
This commit is contained in:
parent
a8fa32dfd5
commit
e9543a690b
3
.github/workflows/telegram-api.yml
vendored
3
.github/workflows/telegram-api.yml
vendored
|
|
@ -12,7 +12,7 @@ jobs:
|
||||||
if: contains(github.event.issue.labels.*.name, 'telegram api')
|
if: contains(github.event.issue.labels.*.name, 'telegram api')
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: dessant/support-requests@v3.0.0
|
- uses: dessant/support-requests@v4
|
||||||
with:
|
with:
|
||||||
support-label: 'telegram api'
|
support-label: 'telegram api'
|
||||||
issue-comment: >
|
issue-comment: >
|
||||||
|
|
@ -26,3 +26,4 @@ jobs:
|
||||||
|
|
||||||
If the above links didn't answer your problem, [click here to ask your question on **StackOverflow**](https://stackoverflow.com/questions/ask?tags=c%23+wtelegramclient+telegram-api) so the whole community can help and benefit.
|
If the above links didn't answer your problem, [click here to ask your question on **StackOverflow**](https://stackoverflow.com/questions/ask?tags=c%23+wtelegramclient+telegram-api) so the whole community can help and benefit.
|
||||||
close-issue: true
|
close-issue: true
|
||||||
|
issue-close-reason: 'not planned'
|
||||||
|
|
|
||||||
37
EXAMPLES.md
37
EXAMPLES.md
|
|
@ -210,7 +210,7 @@ that simplifies the download of a photo/document/file once you get a reference t
|
||||||
|
|
||||||
See [Examples/Program_DownloadSavedMedia.cs](https://github.com/wiz0u/WTelegramClient/blob/master/Examples/Program_DownloadSavedMedia.cs?ts=4#L28) that download all media files you forward to yourself (Saved Messages)
|
See [Examples/Program_DownloadSavedMedia.cs](https://github.com/wiz0u/WTelegramClient/blob/master/Examples/Program_DownloadSavedMedia.cs?ts=4#L28) that download all media files you forward to yourself (Saved Messages)
|
||||||
|
|
||||||
_Note: To abort an ongoing download, you can throw an exception via the `progress` callback argument._
|
_Note: To abort an ongoing download, you can throw an exception via the `progress` callback argument. Example: `(t,s) => ct.ThrowIfCancellationRequested()`_
|
||||||
|
|
||||||
<a name="upload"></a>
|
<a name="upload"></a>
|
||||||
## Upload a media file and post it with caption to a chat
|
## Upload a media file and post it with caption to a chat
|
||||||
|
|
@ -224,6 +224,41 @@ var inputFile = await client.UploadFileAsync(Filepath);
|
||||||
await client.SendMediaAsync(peer, "Here is the photo", inputFile);
|
await client.SendMediaAsync(peer, "Here is the photo", inputFile);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
<a name="upload-video"></a>
|
||||||
|
## Upload a streamable video with optional custom thumbnail
|
||||||
|
```csharp
|
||||||
|
var chats = await client.Messages_GetAllChats();
|
||||||
|
InputPeer peer = chats.chats[1234567890]; // the chat we want
|
||||||
|
const string videoPath = @"C:\...\video.mp4";
|
||||||
|
const string thumbnailPath = @"C:\...\thumbnail.jpg";
|
||||||
|
|
||||||
|
// Extract video information using FFMpegCore or similar library
|
||||||
|
var mediaInfo = await FFmpeg.GetMediaInfo(videoPath);
|
||||||
|
var videoStream = mediaInfo.VideoStreams.FirstOrDefault();
|
||||||
|
int width = videoStream?.Width ?? 0;
|
||||||
|
int height = videoStream?.Height ?? 0;
|
||||||
|
int duration = (int)mediaInfo.Duration.TotalSeconds;
|
||||||
|
|
||||||
|
// Upload video file
|
||||||
|
var inputFile = await Client.UploadFileAsync(videoPath);
|
||||||
|
|
||||||
|
// Prepare InputMedia structure with video attributes
|
||||||
|
var media = new InputMediaUploadedDocument(inputFile, "video/mp4",
|
||||||
|
new DocumentAttributeVideo { w = width, h = height, duration = duration,
|
||||||
|
flags = DocumentAttributeVideo.Flags.supports_streaming });
|
||||||
|
if (thumbnailPath != null)
|
||||||
|
{
|
||||||
|
// upload custom thumbnail and complete InputMedia structure
|
||||||
|
var inputThumb = await client.UploadFileAsync(thumbnailPath);
|
||||||
|
media.thumb = inputThumb;
|
||||||
|
media.flags |= InputMediaUploadedDocument.Flags.has_thumb;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send the media message
|
||||||
|
await client.SendMessageAsync(peer, "caption", media);
|
||||||
|
```
|
||||||
|
*Note: This example requires FFMpegCore NuGet package for video metadata extraction. You can also manually set width, height, and duration if you know the video properties.*
|
||||||
|
|
||||||
<a name="album"></a>
|
<a name="album"></a>
|
||||||
## Send a grouped media album using photos from various sources
|
## Send a grouped media album using photos from various sources
|
||||||
```csharp
|
```csharp
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue