Skip to content
Permalink
Browse files

[feat] support receive stickers

Added sticker entity and attributes
Updated e2e proto
Allow encrypt/decrypt stickers in yowsup-cli
Updated mediasink demo to support downloading stickers
Fixes #2720 Yowsup Freeze after multiple yowsup.layers.axolotl.layer_receive
Fixes #2617 Echo Stickers error
  • Loading branch information...
tgalal committed May 8, 2019
1 parent 467f758 commit 15e36f4e4c50009ccaa30ed314a1526f26a14373
@@ -405,7 +405,8 @@ class MediaToolsArgParser(YowArgParser):
"video": MediaCipher.INFO_VIDEO,
"gif": MediaCipher.INFO_VIDEO,
"document": MediaCipher.INFO_DOCUM,
"doc": MediaCipher.INFO_DOCUM
"doc": MediaCipher.INFO_DOCUM,
"sticker": MediaCipher.INFO_IMAGE
}

def __init__(self, *args, **kwargs):
@@ -416,7 +417,7 @@ class MediaToolsArgParser(YowArgParser):
gp = self.add_argument_group("Media Tools")
gp.add_argument(
'--media-type',
choices=('image', 'video', 'gif', 'document', 'doc'),
choices=('image', 'video', 'gif', 'document', 'doc', "sticker"),
required=True
)
exgp = gp.add_mutually_exclusive_group()
@@ -2,7 +2,8 @@
from yowsup.layers.protocol_media.protocolentities \
import ImageDownloadableMediaMessageProtocolEntity, AudioDownloadableMediaMessageProtocolEntity,\
VideoDownloadableMediaMessageProtocolEntity, DocumentDownloadableMediaMessageProtocolEntity, \
ContactMediaMessageProtocolEntity, DownloadableMediaMessageProtocolEntity
ContactMediaMessageProtocolEntity, DownloadableMediaMessageProtocolEntity, \
StickerDownloadableMediaMessageProtocolEntity

import threading
from tqdm import tqdm
@@ -130,6 +131,9 @@ def run(self):
filename = media_message_protocolentity.display_name
filedata = media_message_protocolentity.vcard
fileext = "vcard"
elif isinstance(media_message_protocolentity, StickerDownloadableMediaMessageProtocolEntity):
media_info = MediaCipher.INFO_IMAGE
filename = "sticker"
else:
logger.error("Unsupported Media type: %s" % media_message_protocolentity.__class__)
sys.exit(1)
@@ -3,6 +3,7 @@
from .protocolentities import AudioDownloadableMediaMessageProtocolEntity
from .protocolentities import VideoDownloadableMediaMessageProtocolEntity
from .protocolentities import DocumentDownloadableMediaMessageProtocolEntity
from .protocolentities import StickerDownloadableMediaMessageProtocolEntity
from .protocolentities import LocationMediaMessageProtocolEntity
from .protocolentities import ContactMediaMessageProtocolEntity
from .protocolentities import ResultRequestUploadIqProtocolEntity
@@ -35,6 +36,9 @@ def recvMessageStanza(self, node):
if mediaNode.getAttributeValue("mediatype") == "image":
entity = ImageDownloadableMediaMessageProtocolEntity.fromProtocolTreeNode(node)
self.toUpper(entity)
elif mediaNode.getAttributeValue("mediatype") == "sticker":
entity = StickerDownloadableMediaMessageProtocolEntity.fromProtocolTreeNode(node)
self.toUpper(entity)
elif mediaNode.getAttributeValue("mediatype") in ("audio", "ptt"):
entity = AudioDownloadableMediaMessageProtocolEntity.fromProtocolTreeNode(node)
self.toUpper(entity)
@@ -4,6 +4,7 @@
from .message_media_downloadable_audio import AudioDownloadableMediaMessageProtocolEntity
from .message_media_downloadable_video import VideoDownloadableMediaMessageProtocolEntity
from .message_media_downloadable_document import DocumentDownloadableMediaMessageProtocolEntity
from .message_media_downloadable_sticker import StickerDownloadableMediaMessageProtocolEntity
from .message_media_location import LocationMediaMessageProtocolEntity
from .message_media_contact import ContactMediaMessageProtocolEntity
from .message_media_extendedtext import ExtendedTextMediaMessageProtocolEntity
@@ -0,0 +1,17 @@
class StickerAttributes(object):
def __init__(self, width, height, png_thumbnail=None):
self._width = width
self._height = height
self._png_thumbnail = png_thumbnail

@property
def width(self):
return self._width

@property
def height(self):
return self._height

@property
def png_thumbnail(self):
return self._png_thumbnail
@@ -16,11 +16,12 @@ class MediaMessageProtocolEntity(ProtomessageProtocolEntity):
TYPE_MEDIA_GIF = "gif"
TYPE_MEDIA_PTT = "ptt"
TYPE_MEDIA_URL = "url"
TYPE_MEDIA_STICKER = "sticker"

TYPES_MEDIA = (
TYPE_MEDIA_IMAGE, TYPE_MEDIA_AUDIO, TYPE_MEDIA_VIDEO,
TYPE_MEDIA_CONTACT, TYPE_MEDIA_LOCATION, TYPE_MEDIA_DOCUMENT,
TYPE_MEDIA_GIF, TYPE_MEDIA_PTT, TYPE_MEDIA_URL
TYPE_MEDIA_GIF, TYPE_MEDIA_PTT, TYPE_MEDIA_URL, TYPE_MEDIA_STICKER
)

def __init__(self, media_type, media_message_attrs, message_attrs):
@@ -0,0 +1,46 @@
from .message_media_downloadable import DownloadableMediaMessageProtocolEntity
from yowsup.layers.protocol_media.protocolentities.attributes.attributes_downloadablemedia \
import DownloadableMediaMessageAttributes
from yowsup.layers.protocol_media.protocolentities.attributes.attributes_sticker import StickerAttributes
from yowsup.layers.protocol_messages.protocolentities.attributes.attributes_message import MessageAttributes


class StickerDownloadableMediaMessageProtocolEntity(DownloadableMediaMessageProtocolEntity):
def __init__(self, sticker_attrs, downloadablemedia_attrs, message_attrs):
# type: (StickerAttributes, DownloadableMediaMessageAttributes, MessageAttributes) -> None
super(StickerDownloadableMediaMessageProtocolEntity, self).__init__(
"sticker", downloadablemedia_attrs, message_attrs
)
self.width = sticker_attrs.width
self.height = sticker_attrs.height

if sticker_attrs.png_thumbnail is not None:
self.png_thumbnail = sticker_attrs.png_thumbnail

@property
def proto(self):
return self._proto.sticker_message

@property
def width(self):
return self.proto.width

@width.setter
def width(self, value):
self.proto.width = value

@property
def height(self):
return self.proto.height

@height.setter
def height(self, value):
self.proto.height = value

@property
def png_thumbnail(self):
return self.proto.png_thumbnail

@png_thumbnail.setter
def png_thumbnail(self, value):
self.proto.png_thumbnail = value if value is not None else b""
Oops, something went wrong.

0 comments on commit 15e36f4

Please sign in to comment.
You can’t perform that action at this time.