From fac6b739990da881f6028f7a74c42f5b9305fde3 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 28 Jul 2022 17:11:51 +0300 Subject: [PATCH] Add audio.album_cover. --- td/generate/scheme/td_api.tl | 5 +++-- td/telegram/AudiosManager.cpp | 10 +++++++++- td/telegram/InlineQueriesManager.cpp | 2 +- td/telegram/files/FileGenerateManager.cpp | 5 +++-- td/telegram/files/FileManager.cpp | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index ff97a5d22..32d33c5a5 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -292,8 +292,9 @@ animation duration:int32 width:int32 height:int32 file_name:string mime_type:str //@description Describes an audio file. Audio is usually in MP3 or M4A format @duration Duration of the audio, in seconds; as defined by the sender @title Title of the audio; as defined by the sender @performer Performer of the audio; as defined by the sender //@file_name Original name of the file; as defined by the sender @mime_type The MIME type of the file; as defined by the sender @album_cover_minithumbnail The minithumbnail of the album cover; may be null -//@album_cover_thumbnail The thumbnail of the album cover in JPEG format; as defined by the sender. The full size thumbnail is supposed to be extracted from the downloaded file; may be null @audio File containing the audio -audio duration:int32 title:string performer:string file_name:string mime_type:string album_cover_minithumbnail:minithumbnail album_cover_thumbnail:thumbnail audio:file = Audio; +//@album_cover_thumbnail The thumbnail of the album cover in JPEG format; as defined by the sender. The full size thumbnail is supposed to be extracted from the downloaded audio file; may be null +//@album_cover Album cover to use if the downloaded audio file have no album cover; may be null. Downloading of this file is expected to fail if album cover is unknown @audio File containing the audio +audio duration:int32 title:string performer:string file_name:string mime_type:string album_cover_minithumbnail:minithumbnail album_cover_thumbnail:thumbnail album_cover:file audio:file = Audio; //@description Describes a document of any type @file_name Original name of the file; as defined by the sender @mime_type MIME type of the file; as defined by the sender //@minithumbnail Document minithumbnail; may be null @thumbnail Document thumbnail in JPEG or PNG format (PNG will be used only for background patterns); as defined by the sender; may be null @document File containing the document diff --git a/td/telegram/AudiosManager.cpp b/td/telegram/AudiosManager.cpp index 9e097d46b..f4fc31313 100644 --- a/td/telegram/AudiosManager.cpp +++ b/td/telegram/AudiosManager.cpp @@ -45,10 +45,18 @@ tl_object_ptr AudiosManager::get_audio_object(FileId file_id) con CHECK(it != audios_.end()); auto audio = it->second.get(); CHECK(audio != nullptr); + + td_api::object_ptr album_cover_file; + if (!td_->auth_manager_->is_bot()) { + auto r_file_id = td_->file_manager_->get_audio_thumbnail_file_id(audio->title, audio->performer, DialogId()); + if (r_file_id.is_ok()) { + album_cover_file = td_->file_manager_->get_file_object(r_file_id.move_as_ok()); + } + } return make_tl_object( audio->duration, audio->title, audio->performer, audio->file_name, audio->mime_type, get_minithumbnail_object(audio->minithumbnail), - get_thumbnail_object(td_->file_manager_.get(), audio->thumbnail, PhotoFormat::Jpeg), + get_thumbnail_object(td_->file_manager_.get(), audio->thumbnail, PhotoFormat::Jpeg), std::move(album_cover_file), td_->file_manager_->get_file_object(file_id)); } diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index b069c7c92..4c12dca60 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -1245,7 +1245,7 @@ template <> tl_object_ptr copy(const td_api::audio &obj) { return td_api::make_object(obj.duration_, obj.title_, obj.performer_, obj.file_name_, obj.mime_type_, copy(obj.album_cover_minithumbnail_), copy(obj.album_cover_thumbnail_), - copy(obj.audio_)); + copy(obj.album_cover_), copy(obj.audio_)); } template <> diff --git a/td/telegram/files/FileGenerateManager.cpp b/td/telegram/files/FileGenerateManager.cpp index 5a1e29d5e..6b8edba10 100644 --- a/td/telegram/files/FileGenerateManager.cpp +++ b/td/telegram/files/FileGenerateManager.cpp @@ -160,10 +160,11 @@ class WebFileDownloadGenerateActor final : public FileGenerateActor { return Status::Error("Title or performer must be non-empty"); } - file_name_ = PSTRING() << "music_thumbnail_" << parts[3] << " - " << parts[2] << ".jpg"; + file_name_ = PSTRING() << "Album cover for " << parts[3] << " - " << parts[2] << ".jpg"; auto flags = telegram_api::inputWebFileAudioAlbumThumbLocation::TITLE_MASK; - return make_tl_object(flags, nullptr, parts[2].str(), parts[3].str()); + return make_tl_object(flags, nullptr, parts[2].str(), + parts[3].str()); } if (parts.size() != 9 || parts[1] != "map") { diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index bac403435..29adb0de4 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -988,7 +988,7 @@ Status FileManager::check_local_location(FullLocalFileLocation &location, int64 }; if ((location.file_type_ == FileType::Thumbnail || location.file_type_ == FileType::EncryptedThumbnail) && size > MAX_THUMBNAIL_SIZE && !begins_with(PathView(location.path_).file_name(), "map") && - !begins_with(PathView(location.path_).file_name(), "music_thumbnail")) { + !begins_with(PathView(location.path_).file_name(), "Album cover for ")) { return get_file_size_error(" for a thumbnail"); } if (size > MAX_FILE_SIZE) {