tgalal / yowsup

The WhatsApp lib
GNU General Public License v3.0
7.06k stars 2.23k forks source link

Decrypt Media in Echoclient? #2989

Open JOOKER69 opened 4 years ago

JOOKER69 commented 4 years ago

Hi, I did have read so many posts/threads about decryption/downloading media files but I can't get it download decoded. Could somebody help me and other ppl, and update my following 'layer.py' code to get it done please?

import subprocess
from yowsup.layers.interface                           import YowInterfaceLayer, ProtocolEntityCallback
from yowsup.layers.protocol_messages.protocolentities  import TextMessageProtocolEntity
from yowsup.layers.protocol_media.protocolentities      import *

import time;
from datetime import datetime

import binascii

ts = time.time()
now = datetime.now() # current date and time

class EchoLayer(YowInterfaceLayer):

    @ProtocolEntityCallback("message")
    def onMessage(self, messageProtocolEntity):

        msgType = messageProtocolEntity.getType()

        if msgType == 'text':
            self.onTextMessage(messageProtocolEntity)

        elif msgType == 'media':
            self.onMediaMessage(messageProtocolEntity)

        self.toLower(messageProtocolEntity.ack(True))

    @ProtocolEntityCallback("receipt")
    def onReceipt(self, entity):
        self.toLower(entity.ack())

    def getMediaMessageBody(self, messageProtocolEntity):
        print(messageProtocolEntity)

    def onTextMessage(self,messageProtocolEntity):
        print("*** GOT TEXT MSG ***\n")

    def onMediaMessage(self, messageProtocolEntity):
        print('MEDIA TYPE: '+messageProtocolEntity.media_type);

        if messageProtocolEntity.media_type == "image":
            print("*** GOT IMAGE ***\n")

            # DOWNLOAD / SAVE DECRYPTED IMAGE HERE #

        elif messageProtocolEntity.media_type == "audio":         
            print("*** GOT AUDIO ***\n")

            # DOWNLOAD / SAVE DECRYPTED AUDIO HERE #

        elif messageProtocolEntity.media_type == "video":
            print('*** GOT VIDEO ***\n')

            # DOWNLOAD / SAVE DECRYPTED VIDEO HERE #

        elif messageProtocolEntity.media_type == "ptt":
            print('*** GOT VOICE ***\n')

            # DOWNLOAD / SAVE DECRYPTED VOICE HERE # IF POSSIBLE #

        elif messageProtocolEntity.media_type == "location":
            print('*** GOT LOCATION ***\n')

        else:
            print('*** GOT ALIEN MEDIA ***\n')
mostepunk commented 4 years ago

You should use sink_worker in yowsup/yowsup/demos/common/

def __init__(self):
        ...
        self._sink_worker = None

@ProtocolEntityCallback("message")
def onMessage(self, messageProtocolEntity):
    msgType = messageProtocolEntity.getType()
    if msgType == 'text':
            self.onTextMessage(messageProtocolEntity)
    elif msgType == 'media':
        self.on_media_message(messageProtocolEntity)

def on_media_message(self, media_message_protocolentity):
        self._sink_worker.enqueue(media_message_protocolentity)

Here's good example