Я хочу получить музыкальную обложку от музыки, отправленную в канал, < /p>
У меня есть этот метод, написанный для этого действия, но наиболее высокое изображение Res, которое я могу получить, - это 320 * 180, который является заполнителем, в то время как телеграмма загружает основное фотопользовательское фото (в официальном приложении Telegram)
Как я могу получить более высокий качественный изображение для Media File? документ. < /p>
async Task DownloadSongWithAllThumbsAsync(Client client, Document doc, string saveDir, string baseName)
{
string extension;
if (!string.IsNullOrEmpty(doc.Filename) && Path.HasExtension(doc.Filename))
extension = Path.GetExtension(doc.Filename).TrimStart('.');
else
extension = doc.mime_type?.Split('/').Last() switch
{
"mpeg" => "mp3",
"mp4" => "m4a",
_ => "bin"
};
string audioPath = Path.Combine(saveDir, $"{baseName}.{extension}");
await using (var fs = File.OpenWrite(audioPath))
await client.DownloadFileAsync(doc, fs);
try
{
var file = TagLib.File.Create(audioPath, ReadStyle.Average);
if (file.Tag.Pictures != null && file.Tag.Pictures.Length > 0)
{
var pic = file.Tag.Pictures[0];
string ext = pic.MimeType switch
{
"image/jpeg" => "jpg",
"image/png" => "png",
_ => "bin"
};
string coverPath = Path.Combine(saveDir, $"{baseName}_cover.{ext}");
File.WriteAllBytes(coverPath, pic.Data.Data);
}
else if (doc.thumbs != null && doc.thumbs.Length > 0)
{
var x = doc.LargestThumbSize;
PhotoSize? largestThumb = null;
int maxSize = 0;
foreach (var thumbObj in doc.thumbs.OfType())
{
int size = thumbObj.w * thumbObj.h;
if (size > maxSize)
{
maxSize = size;
largestThumb = thumbObj;
}
string thumbPath = Path.Combine(saveDir, $"{baseName}_thumb_{thumbObj.type}.jpg");
var inputLocation = new InputDocumentFileLocation
{
id = doc.id,
access_hash = doc.access_hash,
file_reference = doc.file_reference,
thumb_size = thumbObj.type
};
await using (var tfs = File.OpenWrite(thumbPath))
await client.DownloadFileAsync(inputLocation, tfs);
}
if (largestThumb != null)
{
string coverPath = Path.Combine(saveDir, $"{baseName}_cover.jpg");
var inputLocation = new InputDocumentFileLocation
{
id = doc.id,
access_hash = doc.access_hash,
file_reference = doc.file_reference,
thumb_size = largestThumb.type
};
await using (var tfs = File.OpenWrite(coverPath))
await client.DownloadFileAsync(inputLocation, tfs);
var picture = new TagLib.Picture(coverPath)
{
Type = PictureType.FrontCover,
Description = "Cover"
};
file.Tag.Pictures = new TagLib.IPicture[] { picture };
file.Save();
}
}
}
catch (TagLib.UnsupportedFormatException ex)
{
Console.WriteLine($"Warning: TagLib could not read tags for '{audioPath}': {ex.Message}");
}
return audioPath;
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... gramclient
Получить музыкальную обложку от Telegram от WtelegramClient ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Telegram не отправляет OTP на мобильный телефон в библиотеке WTelegramClient [закрыто]
Anonymous » » в форуме C# - 0 Ответы
- 8 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Как я могу воспроизвести музыкальную ноту с помощью NAudio (или иначе) на C#?
Anonymous » » в форуме C# - 0 Ответы
- 25 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Как я могу воспроизвести музыкальную ноту с помощью NAudio (или иначе) на C#?
Anonymous » » в форуме C# - 0 Ответы
- 23 Просмотры
-
Последнее сообщение Anonymous
-