painor / telethon-secret-chat

Secret chat plugin for telethon
MIT License
45 stars 10 forks source link

Video Bytes are corrupted! #5

Open mojtabaasg opened 3 years ago

mojtabaasg commented 3 years ago

When someone sends me a video in secret chat, any video, the video is corrupted. This is my code:

async def downloader(event):
    if event.decrypted_event and not isinstance(event.decrypted_event.file, InputEncryptedFileEmpty):
        cache = manager.download_secret_media(event.decrypted_event)
        file_name = event.decrypted_event.media.mime_type.split("/")[0] + '.' + event.decrypted_event.media.mime_type.split("/")[1]  # video.mp4
        with open(f"./{file_name}", "wb") as f:
            f.write(cache)
            f.close()

This code works with all file types except videos after saving videos with this way, video can not be opened by any app. am I wrong or there is a problem?

mojtabaasg commented 3 years ago

I requested from my friend to send me random video. this is the video he sent: https://user-images.githubusercontent.com/83122377/122592580-b3bc1480-d079-11eb-8c6e-c58fa7bcf9ce.mp4

and this is the video I saved using code above: https://user-images.githubusercontent.com/83122377/122592644-ce8e8900-d079-11eb-8b3c-1e5078ea562f.mp4

painor commented 3 years ago

can you also provide the telegram version that was used? (android or macOS).

mojtabaasg commented 3 years ago

Its an unofficial app in android

mojtabaasg commented 3 years ago

I tried with official Telegram app 1 min ago and this problem again

Touexe commented 3 years ago

same as @mojtabaasg i tried sending video file from the official Telegram client on android and the video file can't be opened. And yes! it works fine for other file like photo

Touexe commented 2 years ago

any solution for this?

Touexe commented 2 years ago

well just found out the problem is telethon itself. any downloading message with key and iv provided will be messed up and corrupted. not just video file, I have tried sending a pdf file and rar file. both are corrupted after sending. I once tried sending a video file without compression (sending as document), the video file is not really corrupted, its playable only in the first chunk.

Edited : Found solution that worked for me! I decided not to make the file being decrypted in chunk during downloading in telethon _download_file function. Instead, I let the encrypted file fully written on disk and later decrypted the file later. And it worked! @painor maybe you could provide a fix for that using this solution?

0tanvi00 commented 3 months ago

@Touexe can u share code how u downloaded in enc. format and then decry. it on disk