Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media data #3436

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Media data #3436

wants to merge 2 commits into from

Conversation

EllaxElla118
Copy link

@EllaxElla118 EllaxElla118 commented Jan 9, 2025

PR Details

This PR allows you to get MessageMedia's data (like Size, Duration, Name, preview, pageCount... e.t.c.) without downloading the media itself

Description

Added a new function that can be invoked with WAWebJS.Message.getMediaData()

Example

let metaData = {};
let id = 'Message_Id_Here';
let message = await client.getMessageById(id);
if(message.hasMedia) {
     metaData = message.getMediaData(); // returns JSON Object
}
console.log(metaData); /* returns an object like this {
                mimetype: 'image/jpg',
                filename: 'example.jpg',
                filesize: 232443,
                preview64: 'base64dataofthe preview',
                pageCount: 'if_its_a_document_return_its_page_count',
                duration: 'return_video/audio_duration_in_seconds'
            };
  */

Related Issue(s)

closes #3435

Motivation and Context

How Has This Been Tested

Tested with the following media types: document, video, audio, sticker, image

Environment

  • Machine OS: Linux Mint
  • Phone OS: Andriod
  • Library Version: whatsapp-web.js 1.26.1-alpha.3
  • WhatsApp Web Version:
  • Puppeteer Version: 18.2.1
  • Browser Type and Version: Chromium
  • Node Version: 22

Types of changes

  • Dependency change
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • I have updated the documentation accordingly (index.d.ts).
  • I have updated the usage example accordingly (example.js)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to get media metadata, like media preview, size, filename before download
1 participant