Support multiple sizes for audio album covers.
This commit is contained in:
parent
643cecbc16
commit
2be350b8fe
@ -293,8 +293,8 @@ 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 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;
|
||||
//@external_album_covers Album cover variants to use if the downloaded audio file contains no album cover. Provided thumbnail dimensions are approximate @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 external_album_covers:vector<thumbnail> 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
|
||||
|
@ -841,7 +841,7 @@ inputWebDocument#9bed434d url:string size:int mime_type:string attributes:Vector
|
||||
|
||||
inputWebFileLocation#c239d686 url:string access_hash:long = InputWebFileLocation;
|
||||
inputWebFileGeoPointLocation#9f2221c9 geo_point:InputGeoPoint access_hash:long w:int h:int zoom:int scale:int = InputWebFileLocation;
|
||||
inputWebFileAudioAlbumThumbLocation#f46fe924 flags:# document:flags.0?InputDocument title:flags.1?string performer:flags.1?string = InputWebFileLocation;
|
||||
inputWebFileAudioAlbumThumbLocation#f46fe924 flags:# small:flags.2?true document:flags.0?InputDocument title:flags.1?string performer:flags.1?string = InputWebFileLocation;
|
||||
|
||||
upload.webFile#21e753bc size:int mime_type:string file_type:storage.FileType mtime:int bytes:bytes = upload.WebFile;
|
||||
|
||||
|
@ -44,17 +44,25 @@ tl_object_ptr<td_api::audio> AudiosManager::get_audio_object(FileId file_id) con
|
||||
auto audio = get_audio(file_id);
|
||||
CHECK(audio != nullptr);
|
||||
|
||||
td_api::object_ptr<td_api::file> album_cover_file;
|
||||
vector<td_api::object_ptr<td_api::thumbnail>> album_covers;
|
||||
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());
|
||||
}
|
||||
auto add_album_cover = [&](bool is_small, int32 width, int32 height) {
|
||||
auto r_file_id =
|
||||
td_->file_manager_->get_audio_thumbnail_file_id(audio->title, audio->performer, is_small, DialogId());
|
||||
if (r_file_id.is_ok()) {
|
||||
album_covers.emplace_back(
|
||||
td_api::make_object<td_api::thumbnail>(td_api::make_object<td_api::thumbnailFormatJpeg>(), width, height,
|
||||
td_->file_manager_->get_file_object(r_file_id.move_as_ok())));
|
||||
}
|
||||
};
|
||||
|
||||
add_album_cover(true, 100, 100);
|
||||
add_album_cover(false, 600, 600);
|
||||
}
|
||||
return make_tl_object<td_api::audio>(
|
||||
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), std::move(album_cover_file),
|
||||
get_thumbnail_object(td_->file_manager_.get(), audio->thumbnail, PhotoFormat::Jpeg), std::move(album_covers),
|
||||
td_->file_manager_->get_file_object(file_id));
|
||||
}
|
||||
|
||||
|
@ -1124,6 +1124,10 @@ tl_object_ptr<td_api::thumbnail> copy(const td_api::thumbnail &obj) {
|
||||
return td_api::make_object<td_api::thumbnail>(std::move(format), obj.width_, obj.height_, copy(obj.file_));
|
||||
}
|
||||
|
||||
static tl_object_ptr<td_api::thumbnail> copy_thumbnail(const tl_object_ptr<td_api::thumbnail> &obj) {
|
||||
return copy(obj);
|
||||
}
|
||||
|
||||
template <>
|
||||
tl_object_ptr<td_api::StickerFormat> copy(const td_api::StickerFormat &obj) {
|
||||
switch (obj.get_id()) {
|
||||
@ -1245,7 +1249,7 @@ template <>
|
||||
tl_object_ptr<td_api::audio> copy(const td_api::audio &obj) {
|
||||
return td_api::make_object<td_api::audio>(obj.duration_, obj.title_, obj.performer_, obj.file_name_, obj.mime_type_,
|
||||
copy(obj.album_cover_minithumbnail_), copy(obj.album_cover_thumbnail_),
|
||||
copy(obj.album_cover_), copy(obj.audio_));
|
||||
transform(obj.external_album_covers_, copy_thumbnail), copy(obj.audio_));
|
||||
}
|
||||
|
||||
template <>
|
||||
|
@ -154,17 +154,25 @@ class WebFileDownloadGenerateActor final : public FileGenerateActor {
|
||||
return Status::Error("Wrong conversion");
|
||||
}
|
||||
|
||||
if (parts.size() == 5 && parts[1] == "audio_t") {
|
||||
if (parts.size() == 6 && parts[1] == "audio_t") {
|
||||
// music thumbnail
|
||||
if (parts[2].empty() && parts[3].empty()) {
|
||||
return Status::Error("Title or performer must be non-empty");
|
||||
}
|
||||
if (parts[4] != "0" && parts[4] != "1") {
|
||||
return Status::Error("Invalid conversion");
|
||||
}
|
||||
|
||||
file_name_ = PSTRING() << "Album cover for " << parts[3] << " - " << parts[2] << ".jpg";
|
||||
bool is_small = parts[4][0] == '1';
|
||||
file_name_ = PSTRING() << "Album cover " << (is_small ? "thumbnail " : "") << "for " << parts[3] << " - "
|
||||
<< parts[2] << ".jpg";
|
||||
|
||||
auto flags = telegram_api::inputWebFileAudioAlbumThumbLocation::TITLE_MASK;
|
||||
return make_tl_object<telegram_api::inputWebFileAudioAlbumThumbLocation>(flags, nullptr, parts[2].str(),
|
||||
parts[3].str());
|
||||
int32 flags = telegram_api::inputWebFileAudioAlbumThumbLocation::TITLE_MASK;
|
||||
if (is_small) {
|
||||
flags |= telegram_api::inputWebFileAudioAlbumThumbLocation::SMALL_MASK;
|
||||
}
|
||||
return make_tl_object<telegram_api::inputWebFileAudioAlbumThumbLocation>(flags, false /*ignored*/, nullptr,
|
||||
parts[2].str(), parts[3].str());
|
||||
}
|
||||
|
||||
if (parts.size() != 9 || parts[1] != "map") {
|
||||
|
@ -3251,7 +3251,8 @@ Result<FileId> FileManager::get_map_thumbnail_file_id(Location location, int32 z
|
||||
FileLocationSource::FromUser, string(), std::move(conversion), owner_dialog_id, 0);
|
||||
}
|
||||
|
||||
Result<FileId> FileManager::get_audio_thumbnail_file_id(string title, string performer, DialogId owner_dialog_id) {
|
||||
Result<FileId> FileManager::get_audio_thumbnail_file_id(string title, string performer, bool is_small,
|
||||
DialogId owner_dialog_id) {
|
||||
if (!clean_input_string(title)) {
|
||||
return Status::Error(400, "Title must be encoded in UTF-8");
|
||||
}
|
||||
@ -3274,7 +3275,7 @@ Result<FileId> FileManager::get_audio_thumbnail_file_id(string title, string per
|
||||
return Status::Error(400, "Title or performer must be non-empty");
|
||||
}
|
||||
|
||||
string conversion = PSTRING() << "#audio_t#" << title << '#' << performer << '#';
|
||||
string conversion = PSTRING() << "#audio_t#" << title << '#' << performer << '#' << (is_small ? '1' : '0') << '#';
|
||||
return register_generate(
|
||||
owner_dialog_id.get_type() == DialogType::SecretChat ? FileType::EncryptedThumbnail : FileType::Thumbnail,
|
||||
FileLocationSource::FromUser, string(), std::move(conversion), owner_dialog_id, 0);
|
||||
|
@ -491,7 +491,7 @@ class FileManager final : public FileLoadManager::Callback {
|
||||
Result<FileId> get_map_thumbnail_file_id(Location location, int32 zoom, int32 width, int32 height, int32 scale,
|
||||
DialogId owner_dialog_id) TD_WARN_UNUSED_RESULT;
|
||||
|
||||
Result<FileId> get_audio_thumbnail_file_id(string title, string performer,
|
||||
Result<FileId> get_audio_thumbnail_file_id(string title, string performer, bool is_small,
|
||||
DialogId owner_dialog_id) TD_WARN_UNUSED_RESULT;
|
||||
|
||||
FileType guess_file_type(const tl_object_ptr<td_api::InputFile> &file);
|
||||
|
Loading…
Reference in New Issue
Block a user