# Path: modules/utils/data.py
# def download_file(url, max_length=20 * 1024 * 1024, headers={}):
#     try:
#         length = requests.head(url).headers.get('content-length', 0)
#         if int(length) > max_length:
#             return
#         r = requests.get(url, timeout=(1, 3), stream=True, headers=headers)
#         ext = url.rsplit('.', 1)[1]
#         file_name = '{}.{}'.format(uuid.uuid4(), ext)
#         with open(file_name, 'wb') as f:
#             shutil.copyfileobj(r.raw, f)
#         return file_name
#     except RequestException:
#         return


import os
import re
from moviepy.editor import *
from modules.utils.data import download_file




def main(bot, message, update, *args, **kwargs):
    chat_id = kwargs.get('chat_id')
    message = message.strip()
    message_id = update.get('message', {}).get('message_id')
    for url in re.findall(r'http.*\.webm', message):
        file_id = bot.store.get(url)

        data = {
            'chat_id': chat_id,
            'reply_to_message_id': message_id,
            'disable_notification': True
        }

        if file_id:
            data.update(video=file_id)

# Path: modules/utils/data.py
# def download_file(url, max_length=20 * 1024 * 1024, headers={}):
#     try:
#         length = requests.head(url).headers.get('content-length', 0)
#         if int(length) > max_length:
#             return
#         r = requests.get(url, timeout=(1, 3), stream=True, headers=headers)
#         ext = url.rsplit('.', 1)[1]
#         file_name = '{}.{}'.format(uuid.uuid4(), ext)
#         with open(file_name, 'wb') as f:
#             shutil.copyfileobj(r.raw, f)
#         return file_name
#     except RequestException:
#         return


# Path: modules/text_webm_preview.py
import os
import re
from moviepy.editor import *
from modules.utils.data import download_file





def main(bot, message, update, *args, **kwargs):
    chat_id = kwargs.get('chat_id')
    message = message.strip()
    message_id = update.get('message', {}).get('message_id')
    for url in re.findall(r'http.*\.webm', message):
        file_id = bot.store.get(url)

        data = {
            'chat_id': chat_id,
            'reply_to_message_id': message_id,
            'disable_notification': True
        }

        if file_id:
            data.update(video=file_id)

            files = None