gramjs
gramjs copied to clipboard
Failed to save video thumbnail to local
I want to save only the thumbnail of the video to the local, but the local pictures failed to browse, and the picture content is blank.What is wrong with the following code?
let id = 0;
for await (const message of client.iterMessages(
"me",
{
limit: 20,
reverse: false,
addOffset: 0,
filter: Api.InputMessagesFilterVideo,
})
) {
//console.log(message);
if (message) {
if (message.media) {
const thumbs = message.media.document.thumbs
//console.log(thumbs);
for (const thumb of thumbs) {
const buffer = await client.downloadMedia(thumb, {
workers: 1,
});
//console.log(buffer);
id += 1;
fs.writeFile(id + ".jpg", buffer, "binary", function (err) {
if (err) {
console.log("保存失败");
}
console.log("保存成功");
});
}
}
}
}
you have to use downloadFile with thumbs not download media.
Sometimes the thumb has all the info (when it's of type (Api.PhotoCachedSize and Api.PhotoStrippedSize) in which case you have to use _downloadCachedPhotoSize
instead (imported from client/downloads.ts)