Skip to content

Commit

Permalink
chore: remove bloated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
krypton-byte committed Feb 1, 2024
1 parent 57f4eda commit 78824ac
Show file tree
Hide file tree
Showing 18 changed files with 436 additions and 428 deletions.
53 changes: 0 additions & 53 deletions docs/requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion examples/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def handler(client: NewClient, message: MessageEv):
case "_video":
client.send_video(
chat,
"https://download.samplelib.com/mp4/sample-5s.mp4",
"/home/krypton-byte/Videos/Screenrecorder/Capture_2024-01-28-00-18-32.mp4",
caption="Test",
quoted=message,
)
Expand Down
2 changes: 1 addition & 1 deletion neonize/_binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
from platform import system
import importlib.metadata
from typing import Any, Dict
from typing import Any
from pathlib import Path

func_string = ctypes.CFUNCTYPE(None, ctypes.c_void_p)
Expand Down
78 changes: 48 additions & 30 deletions neonize/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
from google.protobuf.internal.containers import RepeatedCompositeFieldContainer
from linkpreview import link_preview

from .utils.calc import AspectRatioMethod


from ._binder import gocode, func_string, func_callback_bytes, func
from .builder import build_edit, build_revoke
from .events import Event
Expand Down Expand Up @@ -123,7 +126,7 @@
ContactMessage,
)
from .types import MessageServerID, MessageWithContextInfo
from .utils import get_duration, gen_vcard, log, cv_to_webp, validate_link
from .utils import add_exif, gen_vcard, log, validate_link
from .utils.enum import (
BlocklistAction,
MediaType,
Expand All @@ -137,9 +140,9 @@
PrivacySetting,
PrivacySettingType,
)
from .utils.ffmpeg import FFmpeg, ImageFormat
from .utils.iofile import get_bytes_from_name_or_url
from .utils.jid import Jid2String, JIDToNonAD
from .utils.thumbnail import generate_thumbnail


class ContactStore:
Expand Down Expand Up @@ -584,32 +587,39 @@ def send_sticker(
self,
to: JID,
file: typing.Union[str, bytes],
animated: bool = True,
quoted: Optional[neonize_proto.Message] = None,
name: str = "",
packname: str = "",
) -> SendResponse:
"""Sends a sticker to the specified recipient.
:param to: The JID (Jabber Identifier) of the recipient.
"""
Send a sticker to a specific JID.
:param to: The JID to send the sticker to.
:type to: JID
:param file: Either a file path (str) or URL (str) or binary data (bytes) Image/Video/Gif.
:type file: typing.Union[str | bytes]
:param quoted: Optional. The message to which the sticker is a reply. Defaults to None.
:type quoted: Optional[Message], optional
:param name: Optional. The name of the sticker pack. Defaults to "".
:param file: The file path of the sticker or the sticker data in bytes.
:type file: typing.Union[str, bytes]
:param animated: Whether the sticker is animated or not, defaults to True.
:type animated: bool, optional
:param quoted: The quoted message, if any, defaults to None.
:type quoted: Optional[neonize_proto.Message], optional
:param name: The name of the sticker, defaults to "".
:type name: str, optional
:param packname: Optional. The pack name of the sticker pack. Defaults to "".
:param packname: The name of the sticker pack, defaults to "".
:type packname: str, optional
:return: A function for handling the result of the sticker sending process.
:return: The response from the send message function.
:rtype: SendResponse
"""
image_buf = get_bytes_from_name_or_url(file)
mimetype = magic.from_buffer(image_buf, mime=True)
is_video = "video" in mimetype or "gif" in mimetype
io_save = cv_to_webp(image_buf, is_video, name, packname)
io_save.seek(0)
save = io_save.read()
upload = self.upload(save)
with FFmpeg(file) as ffmpeg:
sticker = ffmpeg.cv_to_webp(animated)
thumbnail = ffmpeg.extract_thumbnail(ImageFormat.PNG)
io_save = BytesIO(sticker)
img = Image.open(io_save)
io_save.seek(0)
img.save(
io_save, format="webp", exif=add_exif(name, packname), save_all=True
)
upload = self.upload(io_save.getvalue())
message = Message(
stickerMessage=StickerMessage(
url=upload.url,
Expand All @@ -618,8 +628,9 @@ def send_sticker(
fileLength=upload.FileLength,
fileSha256=upload.FileSHA256,
mediaKey=upload.MediaKey,
mimetype=magic.from_buffer(save, mime=True),
isAnimated=is_video,
mimetype=magic.from_buffer(io_save.getvalue(), mime=True),
isAnimated=animated,
pngThumbnail=thumbnail,
)
)
if quoted:
Expand Down Expand Up @@ -657,19 +668,22 @@ def send_video(
io = BytesIO(get_bytes_from_name_or_url(file))
io.seek(0)
buff = io.read()
with FFmpeg(file) as ffmpeg:
duration = int(ffmpeg.extract_info().format.duration)
thumbnail = ffmpeg.extract_thumbnail()
upload = self.upload(buff)
message = Message(
videoMessage=VideoMessage(
url=upload.url,
caption=caption,
seconds=int(get_duration(buff)),
seconds=duration,
directPath=upload.DirectPath,
fileEncSha256=upload.FileEncSHA256,
fileLength=upload.FileLength,
fileSha256=upload.FileSHA256,
mediaKey=upload.MediaKey,
mimetype=magic.from_buffer(buff, mime=True),
jpegThumbnail=generate_thumbnail(buff),
jpegThumbnail=thumbnail,
thumbnailDirectPath=upload.DirectPath,
thumbnailEncSha256=upload.FileEncSHA256,
thumbnailSha256=upload.FileSHA256,
Expand Down Expand Up @@ -708,10 +722,12 @@ def send_image(
:return: A function for handling the result of the image sending process.
:rtype: SendResponse
"""
io = BytesIO(get_bytes_from_name_or_url(file))
io.seek(0)
buff = io.read()
upload = self.upload(buff)
n_file = get_bytes_from_name_or_url(file)
img = Image.open(BytesIO(n_file))
img.thumbnail(AspectRatioMethod(*img.size, res=200))
thumbnail = BytesIO()
img.save(thumbnail, format="jpeg")
upload = self.upload(n_file)
message = Message(
imageMessage=ImageMessage(
url=upload.url,
Expand All @@ -721,8 +737,8 @@ def send_image(
fileLength=upload.FileLength,
fileSha256=upload.FileSHA256,
mediaKey=upload.MediaKey,
mimetype=magic.from_buffer(buff, mime=True),
jpegThumbnail=generate_thumbnail(buff),
mimetype=magic.from_buffer(n_file, mime=True),
jpegThumbnail=thumbnail.getvalue(),
thumbnailDirectPath=upload.DirectPath,
thumbnailEncSha256=upload.FileEncSHA256,
thumbnailSha256=upload.FileSHA256,
Expand Down Expand Up @@ -762,10 +778,12 @@ def send_audio(
io.seek(0)
buff = io.read()
upload = self.upload(buff)
with FFmpeg(io.getvalue()) as ffmpeg:
duration = int(ffmpeg.extract_info().format.duration)
message = Message(
audioMessage=AudioMessage(
url=upload.url,
seconds=int(get_duration(buff)),
seconds=duration,
directPath=upload.DirectPath,
fileEncSha256=upload.FileEncSHA256,
fileLength=upload.FileLength,
Expand Down
4 changes: 4 additions & 0 deletions neonize/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,7 @@ class UnsupportedEvent(Exception):

class ContactStoreError(Exception):
pass


class FFProbeError(Exception):
pass
2 changes: 1 addition & 1 deletion neonize/goneonize/defproto/def.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 0 additions & 16 deletions neonize/goneonize/go.sum
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek=
filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI=
github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mattn/go-sqlite3 v1.14.20 h1:BAZ50Ns0OFBNxdAqFhbZqdPcht1Xlb16pDCqkq1spr0=
github.com/mattn/go-sqlite3 v1.14.20/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -21,25 +14,16 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go.mau.fi/libsignal v0.1.0 h1:vAKI/nJ5tMhdzke4cTK1fb0idJzz1JuEIpmjprueC+c=
go.mau.fi/libsignal v0.1.0/go.mod h1:R8ovrTezxtUNzCQE5PH30StOQWWeBskBsWE55vMfY9I=
go.mau.fi/util v0.2.0 h1:AMGBEdg9Ya/smb/09dljo9wBwKr432EpfjDWF7aFQg0=
go.mau.fi/util v0.2.0/go.mod h1:AxuJUMCxpzgJ5eV9JbPWKRH8aAJJidxetNdUj7qcb84=
go.mau.fi/util v0.3.0 h1:Lt3lbRXP6ZBqTINK0EieRWor3zEwwwrDT14Z5N8RUCs=
go.mau.fi/util v0.3.0/go.mod h1:9dGsBCCbZJstx16YgnVMVi3O2bOizELoKpugLD4FoGs=
go.mau.fi/whatsmeow v0.0.0-20231216213200-9d803dd92735 h1:+teJYCOK6M4Kn2TYCj29levhHVwnJTmgCtEXLtgwQtM=
go.mau.fi/whatsmeow v0.0.0-20231216213200-9d803dd92735/go.mod h1:5xTtHNaZpGni6z6aE1iEopjW7wNgsKcolZxZrOujK9M=
go.mau.fi/whatsmeow v0.0.0-20240129221825-0bb41340eb03 h1:EWoQvfZydwqrRK6bYPlqQaLYAOJ8MW//ut6a/x2xlyw=
go.mau.fi/whatsmeow v0.0.0-20240129221825-0bb41340eb03/go.mod h1:5xTtHNaZpGni6z6aE1iEopjW7wNgsKcolZxZrOujK9M=
golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
2 changes: 1 addition & 1 deletion neonize/goneonize/neonize/Neonize.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion neonize/proto/Neonize_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion neonize/proto/def_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 78824ac

Please sign in to comment.