示例#1
0
        private async Task ProcessConvertAsync(Message message)
        {
            try
            {
                var tempFile = Path.GetTempFileName();
                var fileName = Path.ChangeExtension(tempFile, ".mp4");
                using var file = File.Create(fileName);

                try
                {
                    Notificator.VideoHandled(message);

                    var video = await _client.GetFileAsync(message.Video.FileId);

                    await _client.DownloadFileAsync(video.FilePath, file);

                    file.Flush();
                    file.Close();

                    using var videoStream = await _videoСonverter.ConvertAsync(fileName);

                    Notificator.VideoConverted(message, videoStream.Length);

                    var caption = message.GetFromFirstName() + _settings.Messages.CaptionPhrases.GetRandom();

                    var inputFile = new InputOnlineFile(videoStream, _settings.ResultFileName);
                    await _client.SendVideoAsync(message.Chat.Id, inputFile,
                                                 caption : caption,
                                                 replyToMessageId : message.MessageId);

                    Notificator.VideoSendSuccess(message, caption);
                }
                catch (Exception exc)
                {
                    Notificator.Error("Exception: " + exc.Message);
                    await _client.SendTextMessageAsync(message.Chat.Id,
                                                       $"{message.GetFromFirstName()},\n" +
                                                       $"{exc.Message}\n" +
                                                       $"{exc.StackTrace}",
                                                       replyToMessageId : message.MessageId);
                }
                finally
                {
                    File.Delete(file.Name);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }