neonize.utils package

Submodules

neonize.utils.calc module

neonize.utils.calc.AspectRatioMethod(width, height, res=1280)[source]

Calculate the aspect ratio of a given width and height with respect to a resolution.

Parameters:
  • width (int | float) – The width of the given area.

  • height (int | float) – The height of the given area.

  • res (int, optional) – The resolution to calculate the aspect ratio with, defaults to 1280.

Returns:

A tuple containing the calculated width and height based on the aspect ratio.

Return type:

Tuple[int, int]

neonize.utils.calc.auto_sticker(fn)[source]

This function creates a new sticker image with a specified size (512 x 512). The original image is placed at the center of the new sticker.

Parameters:

fn (str) – The file name of the original image.

Returns:

The new sticker image with the original image at the center.

Return type:

Image object

neonize.utils.calc.crop_image(image)[source]

Crops an image to make it square. If the image is already square, it is returned as is. If the image is not square, the longer dimension is cropped equally from both sides to make it square.

Parameters:

image (Image.Image) – An image that needs to be cropped

Returns:

A square cropped image

Return type:

Image.Image

neonize.utils.calc.sticker_scaler(fn)[source]

This function rescales an image to a maximum dimension of 512 pixels while maintaining the aspect ratio. The function takes the filename of the image as an input and returns the rescaled image.

Parameters:

fn (str) – Filename of the image to be rescaled

Returns:

Rescaled image

Return type:

PIL.Image.Image

neonize.utils.enum module

class neonize.utils.enum.BlocklistAction(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration of blocklist actions.

BLOCK

Block action.

Type:

str

UNBLOCK

Unblock action.

Type:

str

BLOCK = 'block'
UNBLOCK = 'unblock'
class neonize.utils.enum.ChatPresence(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enum representing the presence status in a chat.

CHAT_PRESENCE_COMPOSING

Indicates that the user is currently composing a message.

Type:

int

CHAT_PRESENCE_PAUSED

Indicates that the user has paused composing a message.

Type:

int

CHAT_PRESENCE_COMPOSING = 0
CHAT_PRESENCE_PAUSED = 1
class neonize.utils.enum.ChatPresenceMedia(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enum representing the type of media being used in a chat.

CHAT_PRESENCE_MEDIA_TEXT

Indicates that the chat media type is text.

Type:

int

CHAT_PRESENCE_MEDIA_AUDIO

Indicates that the chat media type is audio.

Type:

int

CHAT_PRESENCE_MEDIA_AUDIO = 1
CHAT_PRESENCE_MEDIA_TEXT = 0
class neonize.utils.enum.ClientName(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration of client names.

LINUX

Linux operating system.

Type:

str

WINDOWS

Windows operating system.

Type:

str

ANDROID

Android operating system.

Type:

str

ANDROID = 'android'
LINUX = 'linux'
WINDOWS = 'windows nt'
property name: str

Returns the title-cased name of the client.

Returns:

The title-cased name.

Return type:

str

class neonize.utils.enum.ClientType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration of client types.

UNKNOWN

Unknown client type.

Type:

int

CHROME

Chrome browser.

Type:

int

EDGE

Microsoft Edge browser.

Type:

int

FIREFOX

Mozilla Firefox browser.

Type:

int

IE

Internet Explorer browser.

Type:

int

OPERA

Opera browser.

Type:

int

SAFARI

Safari browser.

Type:

int

ELECTRON

Electron framework.

Type:

int

UWP

Universal Windows Platform.

Type:

int

OTHER

Other client types.

Type:

int

CHROME = 1
EDGE = 2
ELECTRON = 7
FIREFOX = 3
IE = 4
OPERA = 5
OTHER = 9
SAFARI = 6
UNKNOWN = 0
UWP = 8
property name: str

Returns the title-cased name of the client type.

Returns:

The title-cased name.

Return type:

str

class neonize.utils.enum.LogLevel(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enum representing the different levels of logging.

NOTSET

Logging level not set, represented by -1.

Type:

int

DEBUG

Debug level, represented by 0.

Type:

int

INFO

Information level, represented by 1.

Type:

int

WARN

Warning level, represented by 2.

Type:

int

ERROR

Error level, represented by 3.

Type:

int

DEBUG = 0
ERROR = 3
INFO = 1
NOTSET = -1
WARN = 2
classmethod from_logging(level)[source]

Converts a numeric logging level to a corresponding LogLevel enum member.

Parameters:

level (int) – Numeric value representing the logging level.

Returns:

The corresponding LogLevel enum member.

Return type:

LogLevel

property level: bytes

Returns the logging level name encoded as bytes.

Returns:

The name of the logging level encoded in bytes. If the level is NOTSET, returns an empty byte string.

Return type:

bytes

log_level()[source]

Converts the LogLevel enum member to its corresponding numeric logging level.

Returns:

The numeric value representing the logging level.

Return type:

int

class neonize.utils.enum.MediaType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

MediaAppState = 5
MediaAudio = 2
MediaDocument = 3
MediaHistory = 4
MediaImage = 0
MediaLinkThumbnail = 6
MediaVideo = 1
classmethod from_magic(fn_or_bytes)[source]

Returns the MediaType based on file magic bytes or file extension.

Parameters:

fn_or_bytes (Union[str, bytes]) – Either a file path (str) or binary data (bytes) for determining the MediaType.

Returns:

The determined MediaType.

Return type:

MediaType

class neonize.utils.enum.MediaTypeToMMS(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

MediaAppState = 'md-app-state'
MediaAudio = 'audio'
MediaDocument = 'document'
MediaHistory = 'md-msg-hist'
MediaImage = 'image'
MediaLinkThumbnail = 'thumbnail-link'
MediaVideo = 'video'
classmethod from_message(message)[source]
classmethod from_mime(mime)[source]
class neonize.utils.enum.ParticipantChange(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration of participant change actions.

ADD

Add participant action.

Type:

str

REMOVE

Remove participant action.

Type:

str

PROMOTE

Promote participant action.

Type:

str

DEMOTE

Demote participant action.

Type:

str

ADD = 'add'
DEMOTE = 'demote'
PROMOTE = 'promote'
REMOVE = 'remove'
class neonize.utils.enum.ParticipantRequestChange(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration of participant request change actions.

APPROVE

Approve participant request action.

Type:

str

REJECT

Reject participant request action.

Type:

str

APPROVE = 'approve'
REJECT = 'reject'
class neonize.utils.enum.PrivacySetting(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration of privacy settings.

UNDEFINED

Undefined privacy setting.

Type:

str

ALL

All privacy setting.

Type:

str

CONTACTS

Contacts privacy setting.

Type:

str

CONTACTS_BLACKLIST

Contacts blacklist privacy setting.

Type:

str

MATCH_LAST_SEEN

Match last seen privacy setting.

Type:

str

KNOWN

Known privacy setting.

Type:

str

NONE

None privacy setting.

Type:

str

ALL = 'all'
CONTACTS = 'contacts'
CONTACTS_BLACKLIST = 'contacts_blacklist'
KNOWN = 'known'
MATCH_LAST_SEEN = 'match_last_seen'
NONE = 'none'
UNDEFINED = ''
class neonize.utils.enum.PrivacySettingType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration of privacy setting types.

GROUP_ADD

Group add privacy setting.

Type:

str

LAST_SEEN

Last seen privacy setting.

Type:

str

STATUS

Status privacy setting.

Type:

str

PROFILE

Profile privacy setting.

Type:

str

READ_RECEIPTS

Read receipts privacy setting.

Type:

str

ONLINE

Online privacy setting.

Type:

str

CALL_ADD

Call add privacy setting.

Type:

str

CALL_ADD = 'calladd'
GROUP_ADD = 'groupadd'
LAST_SEEN = 'last'
ONLINE = 'online'
PROFILE = 'profile'
READ_RECEIPTS = 'readreceipts'
STATUS = 'status'
class neonize.utils.enum.ReceiptType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enum representing different types of message receipts.

DELIVERED

Indicates that the message has been delivered.

Type:

bytes

SENDER

Indicates that the message is from the sender.

Type:

bytes

RETRY

Indicates a retry receipt.

Type:

bytes

READ

Indicates that the message has been read.

Type:

bytes

READ_SELF

Indicates that the message has been read by the sender themselves.

Type:

bytes

PLAYED

Indicates that the message has been played (e.g., for audio messages).

Type:

bytes

PLAYED_SELF

Indicates that the message has been played by the sender themselves.

Type:

bytes

SERVER_ERROR

Indicates a server error receipt.

Type:

bytes

INACTIVE

Indicates that the recipient is inactive.

Type:

bytes

PEER_MSG

Indicates a peer message receipt.

Type:

bytes

HISTORY_SYNC

Indicates that the message is part of a history sync.

Type:

str

DELIVERED = b''
HISTORY_SYNC = 'hist_sync'
INACTIVE = b'inactive'
PEER_MSG = b'peer_msg'
PLAYED = b'played'
PLAYED_SELF = b'played-self'
READ = b'read'
READ_SELF = b'read-self'
RETRY = b'RETRY'
SENDER = b'sender'
SERVER_ERROR = b'server-error'

neonize.utils.ffmpeg module

class neonize.utils.ffmpeg.FFProbeInfo(format, streams)[source]

Bases: object

Data class representing FFProbe information for a media file.

format

The format information of the media file.

Type:

Format

streams

List of streams in the media file.

Type:

List[Stream]

format: Format
streams: List[Stream]
class neonize.utils.ffmpeg.FFmpeg(data, prefix=None)[source]

Bases: object

call(cmd)[source]
cv_to_webp(animated=True)[source]

This function converts a given file to webp format using ffmpeg. If the animated flag is set to True, it will only convert the first 6 seconds of the file.

Parameters:

animated (bool, optional) – If True, only the first 6 seconds of the file will be converted, defaults to True

Returns:

The converted file in bytes

Return type:

bytes

extract_info()[source]

Extracts media file information using ffprobe tool.

This method uses ffprobe, a tool from the FFmpeg package, to extract information about a media file. It returns the information in the form of an FFProbeInfo object, which contains the format and streams of the media file.

Returns:

An FFProbeInfo object containing the format and streams of the media file.

Return type:

FFProbeInfo

extract_thumbnail(format=ImageFormat.JPG, size=200)[source]

Extracts a thumbnail from a video file.

Parameters:
  • format (ImageFormat, optional) – The format of the output thumbnail, defaults to ImageFormat.JPG

  • size (Optional[Tuple[int, int] | int], optional) – The size of the output thumbnail. If an integer is provided, the thumbnail will be scaled while maintaining the aspect ratio. If a tuple of two integers is provided, it will be used as the exact dimensions for the thumbnail, defaults to 200

Returns:

The bytes representing the thumbnail image.

Return type:

bytes

property filepath
to_mp3()[source]
Return type:

bytes

class neonize.utils.ffmpeg.Format(filename, nb_streams, nb_programs, format_name, format_long_name, start_time, duration, size, probe_score, tags)[source]

Bases: object

Data class representing the format of multimedia content.

filename

Name of the file.

Type:

str

nb_streams

Number of streams in the file.

Type:

int

nb_programs

Number of programs in the file.

Type:

int

format_name

Name of the format.

Type:

str

format_long_name

Long name of the format.

Type:

str

start_time

Start time of the format.

Type:

float

duration

Duration of the content.

Type:

float

size

Size of the file in bytes.

Type:

int

probe_score

Probe score of the file.

Type:

int

tags

Tags associated with the format.

Type:

dict

duration: float
filename: str
format_long_name: str
format_name: str
nb_programs: int
nb_streams: int
probe_score: int
size: int
start_time: float
tags: dict
class neonize.utils.ffmpeg.ImageFormat(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration for image formats.

JPG

JPEG format identifier.

Type:

str

PNG

PNG format identifier.

Type:

str

JPG = 'mjpeg'
PNG = 'apng'
class neonize.utils.ffmpeg.Stream(index, codec_type, avg_frame_rate, codec_tag_string, start_pts, tags, extradata_size, start_time, disposition, codec_tag, time_base, codec_long_name, codec_name, r_frame_rate, closed_captions=None, color_range=None, display_aspect_ratio=None, color_transfer=None, is_avc=None, color_primaries=None, film_grain=None, color_space=None, refs=None, level=None, nal_length_size=None, chroma_location=None, has_b_frames=None, pix_fmt=None, sample_aspect_ratio=None, bits_per_raw_sample=None, profile=None, field_order=None, width=None, height=None, coded_width=None, coded_height=None, bits_per_sample=None, sample_fmt=None, channel_layout=None, initial_padding=None, channels=None, sample_rate=None)[source]

Bases: object

Data class representing a stream in multimedia.

index

Index of the stream.

Type:

int

codec_type

Type of codec used in the stream.

Type:

str

avg_frame_rate

Average frame rate of the stream.

Type:

str

codec_tag_string

Codec tag string.

Type:

str

start_pts

Starting presentation timestamp.

Type:

int

tags

Tags associated with the stream.

Type:

dict

extradata_size

Size of the extra data.

Type:

int

start_time

Start time of the stream.

Type:

str

disposition

Disposition of the stream.

Type:

dict

codec_tag

Codec tag.

Type:

str

time_base

Time base.

Type:

str

codec_long_name

Long name of the codec.

Type:

str

codec_name

Name of the codec.

Type:

str

r_frame_rate

Real frame rate.

Type:

str

closed_captions

Closed captions (Video field).

Type:

Optional[int]

color_range

Color range.

Type:

Optional[str]

display_aspect_ratio

Display aspect ratio.

Type:

Optional[str]

color_transfer

Color transfer.

Type:

Optional[str]

is_avc

AVC flag.

Type:

Optional[str]

color_primaries

Color primaries.

Type:

Optional[str]

film_grain

Film grain.

Type:

Optional[int]

color_space

Color space.

Type:

Optional[str]

refs

Number of reference frames.

Type:

Optional[int]

level

Codec level.

Type:

Optional[int]

nal_length_size

NAL length size.

Type:

Optional[str]

chroma_location

Chroma location.

Type:

Optional[str]

has_b_frames

B-frames flag.

Type:

Optional[int]

pix_fmt

Pixel format.

Type:

Optional[str]

sample_aspect_ratio

Sample aspect ratio.

Type:

Optional[str]

bits_per_raw_sample

Bits per raw sample.

Type:

Optional[str]

profile

Codec profile.

Type:

Optional[str]

field_order

Field order.

Type:

Optional[str]

width

Width of the video frame.

Type:

Optional[int]

height

Height of the video frame.

Type:

Optional[int]

coded_width

Coded width of the video frame.

Type:

Optional[int]

coded_height

Coded height of the video frame.

Type:

Optional[int]

bits_per_sample

Bits per sample (Audio field).

Type:

Optional[int]

sample_fmt

Sample format.

Type:

Optional[str]

channel_layout

Channel layout.

Type:

Optional[str]

initial_padding

Initial padding.

Type:

Optional[int]

channels

Number of channels.

Type:

Optional[int]

sample_rate

Sample rate.

Type:

Optional[str]

avg_frame_rate: str
bits_per_raw_sample: Optional[str] = None
bits_per_sample: Optional[int] = None
channel_layout: Optional[str] = None
channels: Optional[int] = None
chroma_location: Optional[str] = None
closed_captions: Optional[int] = None
codec_long_name: str
codec_name: str
codec_tag: str
codec_tag_string: str
codec_type: str
coded_height: Optional[int] = None
coded_width: Optional[int] = None
color_primaries: Optional[str] = None
color_range: Optional[str] = None
color_space: Optional[str] = None
color_transfer: Optional[str] = None
display_aspect_ratio: Optional[str] = None
disposition: dict
extradata_size: int
field_order: Optional[str] = None
film_grain: Optional[int] = None
has_b_frames: Optional[int] = None
height: Optional[int] = None
index: int
initial_padding: Optional[int] = None
is_avc: Optional[str] = None
level: Optional[int] = None
nal_length_size: Optional[str] = None
pix_fmt: Optional[str] = None
profile: Optional[str] = None
r_frame_rate: str
refs: Optional[int] = None
sample_aspect_ratio: Optional[str] = None
sample_fmt: Optional[str] = None
sample_rate: Optional[str] = None
start_pts: int
start_time: str
tags: dict
time_base: str
width: Optional[int] = None

neonize.utils.iofile module

class neonize.utils.iofile.TemporaryFile(prefix=None, suffix=None, dir=None, touch=True)[source]

Bases: object

neonize.utils.iofile.get_bytes_from_name_or_url(args)[source]

Gets bytes from either a file name or a URL.

Parameters:

args (Union[str, bytes]) – Either a file name (str) or binary data (bytes).

Returns:

The bytes extracted from the specified file name or URL.

Return type:

bytes

neonize.utils.iofile.write_from_bytesio_or_filename(fn_or_bytesio, data)[source]

Writes bytes to either a BytesIO object or a file specified by its name.

Parameters:
  • fn_or_bytesio (io.BytesIO | str) – Either a BytesIO object or the name of the file to write data to.

  • data (bytes) – The bytes to be written.

neonize.utils.jid module

neonize.utils.jid.JIDToNonAD(jid)[source]

Converts a JID (Jabber ID) to a non-AD (Active Directory) format by setting RawAgent and Device to 0.

Parameters:

jid (JID) – The JID to be converted.

Returns:

A new JID object with RawAgent and Device set to 0.

Return type:

JID

neonize.utils.jid.Jid2String(jid)[source]

Converts a Jabber Identifier (JID) to a string.

Parameters:

jid (JID) – The Jabber Identifier (JID) to be converted.

Returns:

The string representation of the JID.

Return type:

str

neonize.utils.jid.build_jid(phone_number)[source]

Builds a JID (Jabber ID) from a phone number.

Parameters:

phone_number (str) – The phone number to be used for building the JID.

Returns:

A JID object constructed from the given phone number.

Return type:

JID

neonize.utils.log module

neonize.utils.message module

neonize.utils.message.extract_text(message)[source]

Extracts text content from a message.

Parameters:

message (Message) – The message object.

Returns:

The extracted text content.

Return type:

str

neonize.utils.message.get_message_type(message)[source]

Determines the type of message.

Parameters:

message (Message) – The message object.

Raises:

IndexError – If the message type cannot be determined.

Returns:

The type of the message.

Return type:

MediaMessageType | TextMessageType

neonize.utils.platform module

neonize.utils.platform.arch_normalizer(arch_)[source]

Normalizes architecture names to a standardized format.

Parameters:

arch (str) – The architecture name to be normalized.

Returns:

The normalized architecture name.

Return type:

str

neonize.utils.platform.generated_name(os_name='', arch_name='')[source]

Generates a standardized filename based on the operating system and architecture.

Parameters:
  • os_name (str, optional) – The name of the operating system, defaults to an empty string.

  • arch_name (str, optional) – The name of the architecture, defaults to an empty string.

Returns:

The generated filename.

Return type:

str

neonize.utils.thumbnail module

neonize.utils.thumbnail.save_file_to_temp_directory(data)[source]
Return type:

str

Module contents

neonize.utils.AspectRatioMethod(width, height, res=1280)[source]

Calculate the aspect ratio of a given width and height with respect to a resolution.

Parameters:
  • width (int | float) – The width of the given area.

  • height (int | float) – The height of the given area.

  • res (int, optional) – The resolution to calculate the aspect ratio with, defaults to 1280.

Returns:

A tuple containing the calculated width and height based on the aspect ratio.

Return type:

Tuple[int, int]

class neonize.utils.BlocklistAction(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration of blocklist actions.

BLOCK

Block action.

Type:

str

UNBLOCK

Unblock action.

Type:

str

BLOCK = 'block'
UNBLOCK = 'unblock'
class neonize.utils.ChatPresence(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enum representing the presence status in a chat.

CHAT_PRESENCE_COMPOSING

Indicates that the user is currently composing a message.

Type:

int

CHAT_PRESENCE_PAUSED

Indicates that the user has paused composing a message.

Type:

int

CHAT_PRESENCE_COMPOSING = 0
CHAT_PRESENCE_PAUSED = 1
class neonize.utils.ChatPresenceMedia(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enum representing the type of media being used in a chat.

CHAT_PRESENCE_MEDIA_TEXT

Indicates that the chat media type is text.

Type:

int

CHAT_PRESENCE_MEDIA_AUDIO

Indicates that the chat media type is audio.

Type:

int

CHAT_PRESENCE_MEDIA_AUDIO = 1
CHAT_PRESENCE_MEDIA_TEXT = 0
class neonize.utils.ClientName(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration of client names.

LINUX

Linux operating system.

Type:

str

WINDOWS

Windows operating system.

Type:

str

ANDROID

Android operating system.

Type:

str

ANDROID = 'android'
LINUX = 'linux'
WINDOWS = 'windows nt'
property name: str

Returns the title-cased name of the client.

Returns:

The title-cased name.

Return type:

str

class neonize.utils.ClientType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration of client types.

UNKNOWN

Unknown client type.

Type:

int

CHROME

Chrome browser.

Type:

int

EDGE

Microsoft Edge browser.

Type:

int

FIREFOX

Mozilla Firefox browser.

Type:

int

IE

Internet Explorer browser.

Type:

int

OPERA

Opera browser.

Type:

int

SAFARI

Safari browser.

Type:

int

ELECTRON

Electron framework.

Type:

int

UWP

Universal Windows Platform.

Type:

int

OTHER

Other client types.

Type:

int

CHROME = 1
EDGE = 2
ELECTRON = 7
FIREFOX = 3
IE = 4
OPERA = 5
OTHER = 9
SAFARI = 6
UNKNOWN = 0
UWP = 8
property name: str

Returns the title-cased name of the client type.

Returns:

The title-cased name.

Return type:

str

class neonize.utils.FFmpeg(data, prefix=None)[source]

Bases: object

call(cmd)[source]
cv_to_webp(animated=True)[source]

This function converts a given file to webp format using ffmpeg. If the animated flag is set to True, it will only convert the first 6 seconds of the file.

Parameters:

animated (bool, optional) – If True, only the first 6 seconds of the file will be converted, defaults to True

Returns:

The converted file in bytes

Return type:

bytes

extract_info()[source]

Extracts media file information using ffprobe tool.

This method uses ffprobe, a tool from the FFmpeg package, to extract information about a media file. It returns the information in the form of an FFProbeInfo object, which contains the format and streams of the media file.

Returns:

An FFProbeInfo object containing the format and streams of the media file.

Return type:

FFProbeInfo

extract_thumbnail(format=ImageFormat.JPG, size=200)[source]

Extracts a thumbnail from a video file.

Parameters:
  • format (ImageFormat, optional) – The format of the output thumbnail, defaults to ImageFormat.JPG

  • size (Optional[Tuple[int, int] | int], optional) – The size of the output thumbnail. If an integer is provided, the thumbnail will be scaled while maintaining the aspect ratio. If a tuple of two integers is provided, it will be used as the exact dimensions for the thumbnail, defaults to 200

Returns:

The bytes representing the thumbnail image.

Return type:

bytes

property filepath
to_mp3()[source]
Return type:

bytes

neonize.utils.JIDToNonAD(jid)[source]

Converts a JID (Jabber ID) to a non-AD (Active Directory) format by setting RawAgent and Device to 0.

Parameters:

jid (JID) – The JID to be converted.

Returns:

A new JID object with RawAgent and Device set to 0.

Return type:

JID

neonize.utils.Jid2String(jid)[source]

Converts a Jabber Identifier (JID) to a string.

Parameters:

jid (JID) – The Jabber Identifier (JID) to be converted.

Returns:

The string representation of the JID.

Return type:

str

class neonize.utils.MediaType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

MediaAppState = 5
MediaAudio = 2
MediaDocument = 3
MediaHistory = 4
MediaImage = 0
MediaLinkThumbnail = 6
MediaVideo = 1
classmethod from_magic(fn_or_bytes)[source]

Returns the MediaType based on file magic bytes or file extension.

Parameters:

fn_or_bytes (Union[str, bytes]) – Either a file path (str) or binary data (bytes) for determining the MediaType.

Returns:

The determined MediaType.

Return type:

MediaType

class neonize.utils.MediaTypeToMMS(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

MediaAppState = 'md-app-state'
MediaAudio = 'audio'
MediaDocument = 'document'
MediaHistory = 'md-msg-hist'
MediaImage = 'image'
MediaLinkThumbnail = 'thumbnail-link'
MediaVideo = 'video'
classmethod from_message(message)[source]
classmethod from_mime(mime)[source]
class neonize.utils.ParticipantChange(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration of participant change actions.

ADD

Add participant action.

Type:

str

REMOVE

Remove participant action.

Type:

str

PROMOTE

Promote participant action.

Type:

str

DEMOTE

Demote participant action.

Type:

str

ADD = 'add'
DEMOTE = 'demote'
PROMOTE = 'promote'
REMOVE = 'remove'
class neonize.utils.ParticipantRequestChange(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration of participant request change actions.

APPROVE

Approve participant request action.

Type:

str

REJECT

Reject participant request action.

Type:

str

APPROVE = 'approve'
REJECT = 'reject'
class neonize.utils.PrivacySetting(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration of privacy settings.

UNDEFINED

Undefined privacy setting.

Type:

str

ALL

All privacy setting.

Type:

str

CONTACTS

Contacts privacy setting.

Type:

str

CONTACTS_BLACKLIST

Contacts blacklist privacy setting.

Type:

str

MATCH_LAST_SEEN

Match last seen privacy setting.

Type:

str

KNOWN

Known privacy setting.

Type:

str

NONE

None privacy setting.

Type:

str

ALL = 'all'
CONTACTS = 'contacts'
CONTACTS_BLACKLIST = 'contacts_blacklist'
KNOWN = 'known'
MATCH_LAST_SEEN = 'match_last_seen'
NONE = 'none'
UNDEFINED = ''
class neonize.utils.PrivacySettingType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration of privacy setting types.

GROUP_ADD

Group add privacy setting.

Type:

str

LAST_SEEN

Last seen privacy setting.

Type:

str

STATUS

Status privacy setting.

Type:

str

PROFILE

Profile privacy setting.

Type:

str

READ_RECEIPTS

Read receipts privacy setting.

Type:

str

ONLINE

Online privacy setting.

Type:

str

CALL_ADD

Call add privacy setting.

Type:

str

CALL_ADD = 'calladd'
GROUP_ADD = 'groupadd'
LAST_SEEN = 'last'
ONLINE = 'online'
PROFILE = 'profile'
READ_RECEIPTS = 'readreceipts'
STATUS = 'status'
class neonize.utils.ReceiptType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enum representing different types of message receipts.

DELIVERED

Indicates that the message has been delivered.

Type:

bytes

SENDER

Indicates that the message is from the sender.

Type:

bytes

RETRY

Indicates a retry receipt.

Type:

bytes

READ

Indicates that the message has been read.

Type:

bytes

READ_SELF

Indicates that the message has been read by the sender themselves.

Type:

bytes

PLAYED

Indicates that the message has been played (e.g., for audio messages).

Type:

bytes

PLAYED_SELF

Indicates that the message has been played by the sender themselves.

Type:

bytes

SERVER_ERROR

Indicates a server error receipt.

Type:

bytes

INACTIVE

Indicates that the recipient is inactive.

Type:

bytes

PEER_MSG

Indicates a peer message receipt.

Type:

bytes

HISTORY_SYNC

Indicates that the message is part of a history sync.

Type:

str

DELIVERED = b''
HISTORY_SYNC = 'hist_sync'
INACTIVE = b'inactive'
PEER_MSG = b'peer_msg'
PLAYED = b'played'
PLAYED_SELF = b'played-self'
READ = b'read'
READ_SELF = b'read-self'
RETRY = b'RETRY'
SENDER = b'sender'
SERVER_ERROR = b'server-error'
neonize.utils.add_exif(name='', packname='')[source]

Adds EXIF metadata to a sticker pack.

Parameters:
  • name (str, optional) – Name of the sticker pack, defaults to an empty string.

  • packname (str, optional) – Publisher of the sticker pack, defaults to an empty string.

Returns:

Byte array containing the EXIF metadata.

Return type:

bytes

neonize.utils.build_jid(phone_number)[source]

Builds a JID (Jabber ID) from a phone number.

Parameters:

phone_number (str) – The phone number to be used for building the JID.

Returns:

A JID object constructed from the given phone number.

Return type:

JID

neonize.utils.extract_text(message)[source]

Extracts text content from a message.

Parameters:

message (Message) – The message object.

Returns:

The extracted text content.

Return type:

str

neonize.utils.gen_vcard(name, phone_number)[source]

Generates a vCard string for a contact.

Parameters:
  • name (str) – Name of the contact.

  • phone_number (str) – Phone number of the contact.

Returns:

vCard string for the contact.

Return type:

str

neonize.utils.get_bytes_from_name_or_url(args)[source]

Gets bytes from either a file name or a URL.

Parameters:

args (Union[str, bytes]) – Either a file name (str) or binary data (bytes).

Returns:

The bytes extracted from the specified file name or URL.

Return type:

bytes

neonize.utils.get_message_type(message)[source]

Determines the type of message.

Parameters:

message (Message) – The message object.

Raises:

IndexError – If the message type cannot be determined.

Returns:

The type of the message.

Return type:

MediaMessageType | TextMessageType

neonize.utils.save_file_to_temp_directory(data)[source]
Return type:

str

Validates if the provided link is a valid URL.

Parameters:

link (str) – The URL to validate.

Returns:

True if the URL is valid, False otherwise.

Return type:

bool